Files
shields/services/gem/gem-owner.service.js
T
Paul MelnikowandGitHub 3ad742e79a Example: Canonicalize urlPattern to pattern (#2341)
Close #2334 

To avoid merge conflicts, I've deferred removing the aliasing logic in `prepareExamples`. That whole function will be refactored momentarily, and there's also #2339 open.
2018-11-18 09:03:33 -05:00

60 lines
1.2 KiB
JavaScript

'use strict'
const Joi = require('joi')
const BaseJsonService = require('../base-json')
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',
format: '(.+)',
capture: ['user'],
}
}
static get examples() {
return [
{
title: 'Gems',
exampleUrl: 'raphink',
pattern: ':user',
staticExample: this.render({ count: 34 }),
keywords: ['ruby'],
},
]
}
}