convert some service classes to static props, run [EclipseMarketplace Ecologi ElmPackage Endpoint] (#5544)

* refactor(eclipsemarketplace): convert to static props

* refactor(ecologi): convert to static props

* refactor(elmpackage): convert to static props

* refactor(endpoint): convert to static props
This commit is contained in:
Caleb Cartwright
2020-09-15 06:46:27 -05:00
committed by GitHub
parent ac54dd3ced
commit 614daef08f
9 changed files with 87 additions and 191 deletions

View File

@@ -38,27 +38,16 @@ function DownloadsForInterval(interval) {
}[interval]
return class EclipseMarketplaceDownloads extends EclipseMarketplaceBase {
static get name() {
return name
}
static get category() {
return 'downloads'
}
static get route() {
return this.buildRoute(base)
}
static get examples() {
return [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ downloads: 30000 }),
},
]
}
static name = name
static category = 'downloads'
static route = this.buildRoute(base)
static examples = [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ downloads: 30000 }),
},
]
static render({ downloads }) {
return {

View File

@@ -13,27 +13,17 @@ const favoritesResponseSchema = Joi.object({
}).required()
module.exports = class EclipseMarketplaceFavorites extends EclipseMarketplaceBase {
static get category() {
return 'other'
}
static category = 'other'
static route = this.buildRoute('eclipse-marketplace/favorites')
static examples = [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ favorited: 55 }),
},
]
static get route() {
return this.buildRoute('eclipse-marketplace/favorites')
}
static get examples() {
return [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ favorited: 55 }),
},
]
}
static get defaultBadgeData() {
return { label: 'favorites' }
}
static defaultBadgeData = { label: 'favorites' }
static render({ favorited }) {
return {

View File

@@ -12,27 +12,17 @@ const licenseResponseSchema = Joi.object({
}).required()
module.exports = class EclipseMarketplaceLicense extends EclipseMarketplaceBase {
static get category() {
return 'license'
}
static category = 'license'
static route = this.buildRoute('eclipse-marketplace/l')
static examples = [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ license: 'GPL' }),
},
]
static get route() {
return this.buildRoute('eclipse-marketplace/l')
}
static get examples() {
return [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ license: 'GPL' }),
},
]
}
static get defaultBadgeData() {
return { label: 'license' }
}
static defaultBadgeData = { label: 'license' }
static render({ license }) {
if (license === '') {

View File

@@ -15,27 +15,17 @@ const updateResponseSchema = Joi.object({
}).required()
module.exports = class EclipseMarketplaceUpdate extends EclipseMarketplaceBase {
static get category() {
return 'activity'
}
static category = 'activity'
static route = this.buildRoute('eclipse-marketplace/last-update')
static examples = [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ date: new Date().getTime() }),
},
]
static get route() {
return this.buildRoute('eclipse-marketplace/last-update')
}
static get examples() {
return [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ date: new Date().getTime() }),
},
]
}
static get defaultBadgeData() {
return { label: 'updated' }
}
static defaultBadgeData = { label: 'updated' }
static render({ date }) {
return {

View File

@@ -13,27 +13,17 @@ const versionResponseSchema = Joi.object({
}).required()
module.exports = class EclipseMarketplaceVersion extends EclipseMarketplaceBase {
static get category() {
return 'version'
}
static category = 'version'
static route = this.buildRoute('eclipse-marketplace/v')
static examples = [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ version: '1.0.1' }),
},
]
static get route() {
return this.buildRoute('eclipse-marketplace/v')
}
static get examples() {
return [
{
title: 'Eclipse Marketplace',
namedParams: { name: 'notepad4e' },
staticPreview: this.render({ version: '1.0.1' }),
},
]
}
static get defaultBadgeData() {
return { label: 'eclipse marketplace' }
}
static defaultBadgeData = { label: 'eclipse marketplace' }
static render({ version }) {
return renderVersionBadge({ version })

View File

@@ -10,30 +10,17 @@ const apiSchema = Joi.object({
}).required()
module.exports = class EcologiCarbonOffset extends BaseJsonService {
static get category() {
return 'other'
}
static category = 'other'
static route = { base: 'ecologi/carbon', pattern: ':username' }
static examples = [
{
title: 'Ecologi (Carbon Offset)',
namedParams: { username: 'ecologi' },
staticPreview: this.render({ count: 15.05 }),
},
]
static get route() {
return {
base: 'ecologi/carbon',
pattern: ':username',
}
}
static get examples() {
return [
{
title: 'Ecologi (Carbon Offset)',
namedParams: { username: 'ecologi' },
staticPreview: this.render({ count: 15.05 }),
},
]
}
static get defaultBadgeData() {
return { label: 'carbon offset' }
}
static defaultBadgeData = { label: 'carbon offset' }
static render({ count }) {
const tonnes = metric(count)

View File

@@ -11,30 +11,17 @@ const apiSchema = Joi.object({
}).required()
module.exports = class EcologiTrees extends BaseJsonService {
static get category() {
return 'other'
}
static category = 'other'
static route = { base: 'ecologi/trees', pattern: ':username' }
static examples = [
{
title: 'Ecologi (Trees)',
namedParams: { username: 'ecologi' },
staticPreview: this.render({ count: 250 }),
},
]
static get route() {
return {
base: 'ecologi/trees',
pattern: ':username',
}
}
static get examples() {
return [
{
title: 'Ecologi (Trees)',
namedParams: { username: 'ecologi' },
staticPreview: this.render({ count: 250 }),
},
]
}
static get defaultBadgeData() {
return { label: 'trees' }
}
static defaultBadgeData = { label: 'trees' }
static render({ count }) {
return { message: metric(count), color: floorCount(count, 10, 50, 100) }

View File

@@ -8,32 +8,17 @@ const { BaseJsonService } = require('..')
const schema = Joi.object({ version: semver }).required()
module.exports = class ElmPackage extends BaseJsonService {
static get category() {
return 'version'
}
static category = 'version'
static route = { base: 'elm-package/v', pattern: ':user/:packageName' }
static examples = [
{
title: 'Elm package',
namedParams: { user: 'elm', packageName: 'core' },
staticPreview: this.render({ version: '1.0.2' }),
},
]
static get route() {
return {
base: 'elm-package/v',
pattern: ':user/:packageName',
}
}
static get examples() {
return [
{
title: 'Elm package',
namedParams: { user: 'elm', packageName: 'core' },
staticPreview: this.render({ version: '1.0.2' }),
},
]
}
static get defaultBadgeData() {
return {
label: 'elm package',
}
}
static defaultBadgeData = { label: 'elm package' }
static render(props) {
return renderVersionBadge(props)

View File

@@ -14,27 +14,15 @@ const queryParamSchema = Joi.object({
}).required()
module.exports = class Endpoint extends BaseJsonService {
static get category() {
return 'dynamic'
static category = 'dynamic'
static route = {
base: 'endpoint',
pattern: '',
queryParamSchema,
}
static get route() {
return {
base: 'endpoint',
pattern: '',
queryParamSchema,
}
}
static get _cacheLength() {
return 300
}
static get defaultBadgeData() {
return {
label: 'custom badge',
}
}
static _cacheLength = 300
static defaultBadgeData = { label: 'custom badge' }
static render({
isError,