Add [modrinth] followers (#8601)
* Add Modrinth followers * Update class names
This commit is contained in:
@@ -7,7 +7,7 @@ const schema = Joi.object({
|
||||
downloads: nonNegativeInteger,
|
||||
}).required()
|
||||
|
||||
export default class Modrinth extends BaseJsonService {
|
||||
export default class ModrinthDownloads extends BaseJsonService {
|
||||
static category = 'downloads'
|
||||
|
||||
static route = {
|
||||
@@ -17,7 +17,7 @@ export default class Modrinth extends BaseJsonService {
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'Modrinth',
|
||||
title: 'Modrinth Downloads',
|
||||
namedParams: { projectId: 'AANobbMI' },
|
||||
staticPreview: renderDownloadsBadge({ downloads: 120000 }),
|
||||
},
|
||||
49
services/modrinth/modrinth-followers.service.js
Normal file
49
services/modrinth/modrinth-followers.service.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import Joi from 'joi'
|
||||
import { metric } from '../text-formatters.js'
|
||||
import { BaseJsonService } from '../index.js'
|
||||
import { nonNegativeInteger } from '../validators.js'
|
||||
|
||||
const schema = Joi.object({
|
||||
followers: nonNegativeInteger,
|
||||
}).required()
|
||||
|
||||
export default class ModrinthFollowers extends BaseJsonService {
|
||||
static category = 'social'
|
||||
|
||||
static route = {
|
||||
base: 'modrinth/followers',
|
||||
pattern: ':projectId',
|
||||
}
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'Modrinth Followers',
|
||||
namedParams: { projectId: 'AANobbMI' },
|
||||
staticPreview: Object.assign(this.render({ followers: 176 }), {
|
||||
label: 'Followers',
|
||||
style: 'social',
|
||||
}),
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'followers' }
|
||||
|
||||
static render({ followers }) {
|
||||
return {
|
||||
message: metric(followers),
|
||||
color: 'blue',
|
||||
}
|
||||
}
|
||||
|
||||
async fetch({ projectId }) {
|
||||
return this._requestJson({
|
||||
schema,
|
||||
url: `https://api.modrinth.com/v2/project/${projectId}`,
|
||||
})
|
||||
}
|
||||
|
||||
async handle({ projectId }) {
|
||||
const { followers } = await this.fetch({ projectId })
|
||||
return this.constructor.render({ followers })
|
||||
}
|
||||
}
|
||||
12
services/modrinth/modrinth-followers.tester.js
Normal file
12
services/modrinth/modrinth-followers.tester.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { createServiceTester } from '../tester.js'
|
||||
import { isMetric } from '../test-validators.js'
|
||||
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('Followers')
|
||||
.get('/AANobbMI.json')
|
||||
.expectBadge({ label: 'followers', message: isMetric })
|
||||
|
||||
t.create('Followers (not found)')
|
||||
.get('/not-existing.json')
|
||||
.expectBadge({ label: 'followers', message: 'not found', color: 'red' })
|
||||
Reference in New Issue
Block a user