Files
shields/services/codetally/codetally.service.js
T
Paul MelnikowandGitHub 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

58 lines
1.5 KiB
JavaScript

'use strict'
const LegacyService = require('../legacy-service')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
module.exports = class Codetally extends LegacyService {
static get category() {
return 'funding'
}
static get route() {
return {
base: 'codetally',
}
}
static get examples() {
return [
{
title: 'Codetally',
previewUrl: 'triggerman722/colorstrap',
},
]
}
static registerLegacyRouteHandler({ camp, cache }) {
camp.route(
/^\/codetally\/(.*)\/(.*)\.(svg|png|gif|jpg|json)$/,
cache((data, match, sendBadge, request) => {
const owner = match[1] // eg, triggerman722.
const repo = match[2] // eg, colorstrap
const format = match[3]
const apiUrl = `http://www.codetally.com/formattedshield/${owner}/${repo}`
const badgeData = getBadgeData('codetally', data)
request(apiUrl, (err, res, buffer) => {
if (err != null) {
badgeData.text[1] = 'inaccessible'
sendBadge(format, badgeData)
return
}
try {
const data = JSON.parse(buffer)
badgeData.text[1] = ` ${data.currency_sign}${data.amount} ${
data.multiplier
}`
badgeData.colorscheme = null
badgeData.colorB = '#2E8B57'
sendBadge(format, badgeData)
} catch (e) {
badgeData.text[1] = 'invalid'
sendBadge(format, badgeData)
}
})
})
)
}
}