-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d4ce24b
commit 90831e6
Showing
2 changed files
with
20 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,13 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const { BaseJsonService } = require('..') | ||
|
||
const schema = Joi.object({ | ||
total_amount: Joi.number().min(0).required(), | ||
}).required() | ||
|
||
module.exports = class Beerpay extends BaseJsonService { | ||
static category = 'funding' | ||
static route = { base: 'beerpay', pattern: ':user/:project' } | ||
|
||
static examples = [ | ||
{ | ||
title: 'Beerpay', | ||
namedParams: { user: 'hashdog', project: 'scrapfy-chrome-extension' }, | ||
staticPreview: this.render({ totalAmount: 10 }), | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { 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 }) | ||
} | ||
} | ||
const { deprecatedService } = require('..') | ||
|
||
module.exports = deprecatedService({ | ||
category: 'build', | ||
route: { | ||
base: 'beerpay', | ||
pattern: ':various+', | ||
}, | ||
label: 'beerpay', | ||
dateAdded: new Date('2021-07-03'), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
'use strict' | ||
|
||
const { withRegex } = require('../test-validators') | ||
const t = (module.exports = require('../tester').createServiceTester()) | ||
|
||
const amountOfMoney = withRegex(/^\$[0-9]+(\.[0-9]+)?/) | ||
|
||
t.create('funding').get('/hashdog/scrapfy-chrome-extension.json').expectBadge({ | ||
label: 'beerpay', | ||
message: amountOfMoney, | ||
}) | ||
|
||
t.create('funding (unknown project)') | ||
.get('/hashdog/not-a-real-project.json') | ||
const { ServiceTester } = require('../tester') | ||
const t = (module.exports = new ServiceTester({ | ||
id: 'beerpay', | ||
title: 'Beerpay', | ||
})) | ||
|
||
t.create('no longer available (previously beerpay)') | ||
.get('/hashdog/scrapfy-chrome-extension.json') | ||
.expectBadge({ | ||
label: 'beerpay', | ||
message: 'project not found', | ||
message: 'no longer available', | ||
}) |