Files
shields/services/librariesio/librariesio-dependent-repos.service.js
Paul Melnikow 02ec19fd22 BaseService terminology: Rename url to route (#2278)
The term “url” is overloaded in services, to refer to the Shields route and also the API URL. Calling the Shields URL a “route” is on the whole more descriptive, and makes it clearer and more obvious which one of these we’re talking about. It’s a small thing, though seems like an improvement.

We have a few functions called `buildUrl`. I’ve renamed them to `buildRoute` when they refer to routes, and left them as `buildUrl` when they refer to API URLs.

I included a minor style tweak and some formatting cleanup in `TUTORIAL.md`.
2018-11-09 15:11:03 -05:00

53 lines
1.2 KiB
JavaScript

'use strict'
const { metric } = require('../../lib/text-formatters')
const LibrariesIoBase = require('./librariesio-base')
// https://libraries.io/api#project-dependent-repositories
class LibrariesIoDependentRepos extends LibrariesIoBase {
static get category() {
return 'other'
}
static get defaultBadgeData() {
return {
label: 'dependent repos',
}
}
static get route() {
return this.buildRoute('librariesio/dependent-repos')
}
static get examples() {
return [
{
title: 'Dependent repos (via libraries.io)',
exampleUrl: 'npm/got',
urlPattern: ':platform/:library',
staticExample: this.render({ dependentReposCount: 84000 }),
},
]
}
static render({ dependentReposCount }) {
return {
message: metric(dependentReposCount),
color: dependentReposCount === 0 ? 'orange' : 'brightgreen',
}
}
async handle({ platform, packageName }) {
const { dependent_repos_count: dependentReposCount } = await this.fetch(
{
platform,
packageName,
},
{ allowPackages: true }
)
return this.constructor.render({ dependentReposCount })
}
}
module.exports = LibrariesIoDependentRepos