Files
shields/services/codetally/codetally.service.js
Paul Melnikow 226fa67a02 Create shortcut for BaseService-related imports (#2809)
Continue to implement #2698:

- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
2019-01-21 15:41:24 -05:00

75 lines
1.5 KiB
JavaScript

'use strict'
const Joi = require('joi')
const { BaseJsonService } = require('..')
const schema = Joi.object({
currency_sign: Joi.string().required(),
amount: Joi.number().required(),
multiplier: Joi.string()
.allow('')
.required(),
currency_abbreviation: Joi.string().required(),
}).required()
module.exports = class Codetally extends BaseJsonService {
static render({ currency, amount, multiplier }) {
return {
message: `${currency}${amount.toFixed(2)} ${multiplier}`,
}
}
static get category() {
return 'funding'
}
static get defaultBadgeData() {
return {
label: 'codetally',
color: '#2E8B57',
}
}
static get route() {
return {
base: 'codetally',
pattern: ':owner/:repo',
}
}
static get examples() {
return [
{
title: 'Codetally',
namedParams: {
owner: 'triggerman722',
repo: 'colorstrap',
},
staticPreview: this.render({
currency: '$',
amount: 4.68,
multiplier: 'K',
}),
},
]
}
async handle({ owner, repo }) {
const url = `http://www.codetally.com/formattedshield/${owner}/${repo}`
const json = await this._requestJson({
url,
schema,
errorMessages: {
404: 'repo not found',
503: 'repo not found',
},
})
return this.constructor.render({
currency: json.currency_sign,
amount: json.amount,
multiplier: json.multiplier,
})
}
}