Files
shields/services/pub/pub-publisher.service.js
chris48s 3eb4959163 migrate examples to openApi part 14; affects [azuredevops discord netlify opencollective pub ros visualstudio] (#9560)
* migrate some services from examples to openApi

* migrate pub version

* improve pub descriptions
2023-12-04 13:09:37 +00:00

55 lines
1.2 KiB
JavaScript

import Joi from 'joi'
import { BaseJsonService, pathParams } from '../index.js'
import { baseDescription } from './pub-common.js'
const schema = Joi.object({
publisherId: Joi.string().allow(null).required(),
}).required()
export class PubPublisher extends BaseJsonService {
static category = 'other'
static route = {
base: 'pub/publisher',
pattern: ':packageName',
}
static openApi = {
'/pub/publisher/{packageName}': {
get: {
summary: 'Pub Publisher',
description: baseDescription,
parameters: pathParams({
name: 'packageName',
example: 'path',
}),
},
},
}
static _cacheLength = 3600
static defaultBadgeData = { label: 'publisher' }
static render({ publisher }) {
return {
label: 'publisher',
message: publisher == null ? 'unverified' : publisher,
color: publisher == null ? 'lightgrey' : 'blue',
}
}
async fetch({ packageName }) {
return this._requestJson({
schema,
url: `https://pub.dev/api/packages/${packageName}/publisher`,
})
}
async handle({ packageName }) {
const data = await this.fetch({ packageName })
const publisher = data.publisherId
return this.constructor.render({ publisher })
}
}