1
0
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:
Fatpandac 2023-12-21 00:28:41 +08:00 committed by GitHub
parent c44e8c4cce
commit 6e581b7acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View 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 })
}
}

View 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,
})