* convert an example that doesn't matter * migrate some services from examples to openApi * improve and de-dupe service titles * revert changes to codefactor
42 lines
944 B
JavaScript
42 lines
944 B
JavaScript
import Joi from 'joi'
|
|
import { pathParams } from '../index.js'
|
|
import BaseCoincapService from './coincap-base.js'
|
|
|
|
const schema = Joi.object({
|
|
data: Joi.object({
|
|
rank: Joi.string()
|
|
.pattern(/^[0-9]+$/)
|
|
.required(),
|
|
name: Joi.string().required(),
|
|
}).required(),
|
|
}).required()
|
|
|
|
export default class CoincapRank extends BaseCoincapService {
|
|
static route = { base: 'coincap/rank', pattern: ':assetId' }
|
|
|
|
static openApi = {
|
|
'/coincap/rank/{assetId}': {
|
|
get: {
|
|
summary: 'Coincap (Rank)',
|
|
parameters: pathParams({
|
|
name: 'assetId',
|
|
example: 'bitcoin',
|
|
}),
|
|
},
|
|
},
|
|
}
|
|
|
|
static render({ asset }) {
|
|
return {
|
|
label: `${asset.name}`.toLowerCase(),
|
|
message: asset.rank,
|
|
color: 'blue',
|
|
}
|
|
}
|
|
|
|
async handle({ assetId }) {
|
|
const { data: asset } = await this.fetch({ assetId, schema })
|
|
return this.constructor.render({ asset })
|
|
}
|
|
}
|