Files
shields/services/gem/gem-owner.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

58 lines
1.1 KiB
JavaScript

'use strict'
const Joi = require('joi')
const { BaseJsonService } = require('..')
const { floorCount: floorCountColor } = require('../../lib/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'],
},
]
}
}