Files
shields/services/liberapay/liberapay-receives.service.js
2019-01-28 20:57:11 +00:00

38 lines
913 B
JavaScript

'use strict'
const { InvalidResponse } = require('..')
const { renderCurrencyBadge, LiberapayBase } = require('./liberapay-base')
module.exports = class LiberapayReceives extends LiberapayBase {
static get route() {
return this.buildRoute('receives')
}
static get examples() {
return [
{
title: 'Liberapay receiving',
namedParams: { entity: 'Changaco' },
staticPreview: renderCurrencyBadge({
label: 'receives',
amount: '98.32',
currency: 'EUR',
}),
},
]
}
async handle({ entity }) {
const data = await this.fetch({ entity })
if (data.receiving) {
return renderCurrencyBadge({
label: 'receives',
amount: data.receiving.amount,
currency: data.receiving.currency,
})
} else {
throw new InvalidResponse({ prettyMessage: 'no public receiving stats' })
}
}
}