Files
shields/services/gem/gem-owner.service.js
Paul Melnikow fafb22efee Move "good" badge helpers from lib/ to services/ (#3101)
This moves a few helpers from `lib/` to `services/`:

build-status.js
build-status.spec.js
color-formatters.js
color-formatters.spec.js
contributor-count.js
licenses.js
licenses.spec.js
php-version.js
php-version.spec.js
text-formatters.js
text-formatters.spec.js
version.js
version.spec.js

And one from `lib/` to `core/`:

unhandled-rejection.spec.js

The diff is long, but the changes are straightforward.

Ref #2832
2019-02-27 20:47:46 -05:00

57 lines
1.1 KiB
JavaScript

'use strict'
const Joi = require('joi')
const { BaseJsonService } = require('..')
const { floorCount: floorCountColor } = require('../color-formatters')
const ownerSchema = Joi.array().required()
module.exports = class GemOwner extends BaseJsonService {
async fetch({ user }) {
const url = `https://rubygems.org/api/v1/owners/${user}/gems.json`
return this._requestJson({
url,
schema: ownerSchema,
})
}
static render({ count }) {
return {
message: count,
color: floorCountColor(count, 10, 50, 100),
}
}
async handle({ user }) {
const json = await this.fetch({ user })
return this.constructor.render({ count: json.length })
}
// Metadata
static get defaultBadgeData() {
return { label: 'gems' }
}
static get category() {
return 'other'
}
static get route() {
return {
base: 'gem/u',
pattern: ':user',
}
}
static get examples() {
return [
{
title: 'Gems',
namedParams: { user: 'raphink' },
staticPreview: this.render({ count: 34 }),
keywords: ['ruby'],
},
]
}
}