-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add Raycast extension installs Badge * fix: capitalize the first letter * fix: change to use the offical public API * fix: change category to downloads
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) |