Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flathub]Add downloads badge #7724

Merged
merged 5 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions services/flathub/flathub-downloads.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'

const schema = Joi.object({
installs_total: Joi.number().integer().required(),
}).required()

export default class FlathubDownloads extends BaseJsonService {
static category = 'downloads'
static route = { base: 'flathub/downloads', pattern: ':packageName' }
static examples = [
{
title: 'Flathub',
namedParams: {
packageName: 'org.mozilla.firefox',
},
staticPreview: renderDownloadsBadge({ downloads: '277136' }),
},
]

static defaultBadgeData = { label: 'downloads' }

async handle({ packageName }) {
const data = await this._requestJson({
schema,
url: `https://flathub.org/api/v2/stats/${encodeURIComponent(
packageName
)}`,
})
return renderDownloadsBadge({ downloads: data.installs_total })
}
}
14 changes: 14 additions & 0 deletions services/flathub/flathub-downloads.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('Flathub Downloads (valid)')
.get('/org.mozilla.firefox.json')
.expectBadge({
label: 'downloads',
message: isMetric,
})

t.create('Flathub Downloads (not found)')
.get('/not.a.package.json')
.expectBadge({ label: 'downloads', message: 'not found' })