Files
shields/services/wheelmap/wheelmap.service.js
Paul Melnikow 02ec19fd22 BaseService terminology: Rename url to route (#2278)
The term “url” is overloaded in services, to refer to the Shields route and also the API URL. Calling the Shields URL a “route” is on the whole more descriptive, and makes it clearer and more obvious which one of these we’re talking about. It’s a small thing, though seems like an improvement.

We have a few functions called `buildUrl`. I’ve renamed them to `buildRoute` when they refer to routes, and left them as `buildUrl` when they refer to API URLs.

I included a minor style tweak and some formatting cleanup in `TUTORIAL.md`.
2018-11-09 15:11:03 -05:00

60 lines
1.6 KiB
JavaScript

'use strict'
const LegacyService = require('../legacy-service')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
module.exports = class Wheelmap extends LegacyService {
static get category() {
return 'other'
}
static get route() {
return {
base: 'wheelmap/a',
}
}
static get examples() {
return [
{
title: 'Wheelmap',
previewUrl: '2323004600',
},
]
}
static registerLegacyRouteHandler({ camp, cache }) {
camp.route(
/^\/wheelmap\/a\/(.*)\.(svg|png|gif|jpg|json)$/,
cache((data, match, sendBadge, request) => {
const nodeId = match[1] // eg, `2323004600`.
const format = match[2]
const options = {
method: 'GET',
json: true,
uri: `http://wheelmap.org/nodes/${nodeId}.json`,
}
const badgeData = getBadgeData('wheelmap', data)
// eslint-disable-next-line handle-callback-err
request(options, (err, res, json) => {
try {
const accessibility = json.node.wheelchair
badgeData.text[1] = accessibility
if (accessibility === 'yes') {
badgeData.colorscheme = 'brightgreen'
} else if (accessibility === 'limited') {
badgeData.colorscheme = 'yellow'
} else if (accessibility === 'no') {
badgeData.colorscheme = 'red'
}
sendBadge(format, badgeData)
} catch (e) {
badgeData.text[1] = 'void'
sendBadge(format, badgeData)
}
})
})
)
}
}