mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
Add [Raycast] Badge (#9801)
* feat: add Raycast extension installs Badge * fix: capitalize the first letter * fix: change to use the offical public API * fix: change category to downloads
This commit is contained in:
parent
c44e8c4cce
commit
6e581b7acf
55
services/raycast/installs.service.js
Normal file
55
services/raycast/installs.service.js
Normal file
@ -0,0 +1,55 @@
|
||||
import Joi from 'joi'
|
||||
import { nonNegativeInteger } from '../validators.js'
|
||||
import { BaseJsonService, pathParams } from '../index.js'
|
||||
import { renderDownloadsBadge } from '../downloads.js'
|
||||
|
||||
const schema = Joi.object({
|
||||
download_count: nonNegativeInteger,
|
||||
}).required()
|
||||
|
||||
export default class RaycastInstalls extends BaseJsonService {
|
||||
static category = 'downloads'
|
||||
|
||||
static route = {
|
||||
base: 'raycast/dt',
|
||||
pattern: ':user/:extension',
|
||||
}
|
||||
|
||||
static openApi = {
|
||||
'/raycast/dt/{user}/{extension}': {
|
||||
get: {
|
||||
summary: 'Raycast extension downloads count',
|
||||
parameters: pathParams(
|
||||
{ name: 'user', example: 'Fatpandac' },
|
||||
{ name: 'extension', example: 'bilibili' },
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
static render({ downloads }) {
|
||||
return renderDownloadsBadge({ downloads })
|
||||
}
|
||||
|
||||
async fetch({ user, extension }) {
|
||||
return this._requestJson({
|
||||
schema,
|
||||
url: `https://www.raycast.com/api/v1/extensions/${user}/${extension}`,
|
||||
httpErrors: {
|
||||
404: 'user/extension not found',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
transform(json) {
|
||||
const downloads = json.download_count
|
||||
|
||||
return { downloads }
|
||||
}
|
||||
|
||||
async handle({ user, extension }) {
|
||||
const json = await this.fetch({ user, extension })
|
||||
const { downloads } = this.transform(json)
|
||||
return this.constructor.render({ downloads })
|
||||
}
|
||||
}
|
30
services/raycast/installs.tester.js
Normal file
30
services/raycast/installs.tester.js
Normal file
@ -0,0 +1,30 @@
|
||||
import { createServiceTester } from '../tester.js'
|
||||
import { isMetric } from '../test-validators.js'
|
||||
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('installs (invalid user)')
|
||||
.get('/fatpandac/bilibili.json')
|
||||
.expectBadge({
|
||||
label: 'downloads',
|
||||
message: 'user/extension not found',
|
||||
})
|
||||
|
||||
t.create('installs (not existing extension)')
|
||||
.get('/Fatpandac/safdsaklfhe.json')
|
||||
.expectBadge({
|
||||
label: 'downloads',
|
||||
message: 'user/extension not found',
|
||||
})
|
||||
|
||||
t.create('installs (not existing user and extension)')
|
||||
.get('/fatpandac/safdsaklfhe.json')
|
||||
.expectBadge({
|
||||
label: 'downloads',
|
||||
message: 'user/extension not found',
|
||||
})
|
||||
|
||||
t.create('installs (valid)').get('/Fatpandac/bilibili.json').expectBadge({
|
||||
label: 'downloads',
|
||||
message: isMetric,
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user