1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00
shields/services/cocoapods/cocoapods-docs.service.js
chris48s b2f47a3303
migrate examples to openApi part 2; affects [archlinux bitcomponents bountysource cdnjs chrome clearlydefined clojars cocoapods coincap] (#9428)
* convert an example that doesn't matter

* migrate some services from examples to openApi

* improve and de-dupe service titles

* revert changes to codefactor
2023-08-08 23:57:47 +00:00

49 lines
1.2 KiB
JavaScript

import Joi from 'joi'
import { coveragePercentage as coveragePercentageColor } from '../color-formatters.js'
import { BaseJsonService, pathParams } from '../index.js'
const schema = Joi.object({
cocoadocs: Joi.object({
doc_percent: Joi.number().allow(null).required(),
}).required(),
}).required()
export default class CocoapodsDocs extends BaseJsonService {
static category = 'analysis'
static route = { base: 'cocoapods/metrics/doc-percent', pattern: ':spec' }
static openApi = {
'/cocoapods/metrics/doc-percent/{spec}': {
get: {
summary: 'Cocoapods doc percentage',
parameters: pathParams({
name: 'spec',
example: 'AFNetworking',
}),
},
},
}
static defaultBadgeData = { label: 'docs' }
static render({ percentage }) {
return {
message: `${percentage}%`,
color: coveragePercentageColor(percentage),
}
}
async fetch({ spec }) {
return this._requestJson({
schema,
url: `https://metrics.cocoapods.org/api/v1/pods/${spec}`,
})
}
async handle({ spec }) {
const data = await this.fetch({ spec })
const percentage = data.cocoadocs.doc_percent || 0
return this.constructor.render({ percentage })
}
}