-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
beerpay.service.js
59 lines (51 loc) · 1.31 KB
/
beerpay.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
const Joi = require('@hapi/joi')
const { BaseJsonService } = require('..')
const schema = Joi.object({
total_amount: Joi.number()
.min(0)
.required(),
}).required()
module.exports = class Beerpay extends BaseJsonService {
static get category() {
return 'funding'
}
static get route() {
return {
base: 'beerpay',
pattern: ':user/:project',
}
}
static get examples() {
return [
{
title: 'Beerpay',
namedParams: { user: 'hashdog', project: 'scrapfy-chrome-extension' },
staticPreview: this.render({ totalAmount: 10 }),
},
]
}
static get defaultBadgeData() {
return {
label: 'beerpay',
}
}
static render({ totalAmount }) {
return {
message: `$${totalAmount}`,
color: totalAmount > 0 ? 'blue' : 'red',
}
}
async handle({ user, project }) {
// e.g. JSON response: https://beerpay.io/api/v1/beerpay/projects/beerpay.io
// e.g. SVG badge: https://beerpay.io/beerpay/beerpay.io/badge.svg?style=flat-square
const { total_amount: totalAmount } = await this._requestJson({
schema,
url: `https://beerpay.io/api/v1/${user}/projects/${project}`,
errorMessages: {
404: 'project not found',
},
})
return this.constructor.render({ totalAmount })
}
}