Skip to content

Commit

Permalink
migrate examples to openApi part 4; affects [ecologi elm flathub …
Browse files Browse the repository at this point in the history
…gem gitter GithubTotalDiscussions greasyfork hackage hackernews homebrew] (#9430)

* migrate some services from examples to openApi

* improve and de-dupe service titles

* revert changes to homebrew
  • Loading branch information
chris48s authored Aug 21, 2023
1 parent ad359a2 commit 6823d38
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 118 deletions.
18 changes: 11 additions & 7 deletions services/ecologi/ecologi-carbon.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { floorCount } from '../color-formatters.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const apiSchema = Joi.object({
total: Joi.number().positive().required(),
Expand All @@ -10,13 +10,17 @@ const apiSchema = Joi.object({
export default class EcologiCarbonOffset extends BaseJsonService {
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 openApi = {
'/ecologi/carbon/{username}': {
get: {
summary: 'Ecologi (Carbon Offset)',
parameters: pathParams({
name: 'username',
example: 'ecologi',
}),
},
},
]
}

static defaultBadgeData = { label: 'carbon offset' }

Expand Down
18 changes: 11 additions & 7 deletions services/ecologi/ecologi-trees.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { floorCount } from '../color-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const apiSchema = Joi.object({
total: nonNegativeInteger,
Expand All @@ -11,13 +11,17 @@ const apiSchema = Joi.object({
export default class EcologiTrees extends BaseJsonService {
static category = 'other'
static route = { base: 'ecologi/trees', pattern: ':username' }
static examples = [
{
title: 'Ecologi (Trees)',
namedParams: { username: 'ecologi' },
staticPreview: this.render({ count: 250 }),
static openApi = {
'/ecologi/trees/{username}': {
get: {
summary: 'Ecologi (Trees)',
parameters: pathParams({
name: 'username',
example: 'ecologi',
}),
},
},
]
}

static defaultBadgeData = { label: 'trees' }

Expand Down
24 changes: 17 additions & 7 deletions services/elm-package/elm-package.service.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import Joi from 'joi'
import { renderVersionBadge } from '../version.js'
import { semver } from '../validators.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const schema = Joi.object({ version: semver }).required()

export default class ElmPackage extends BaseJsonService {
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 openApi = {
'/elm-package/v/{user}/{packageName}': {
get: {
summary: 'Elm package',
parameters: pathParams(
{
name: 'user',
example: 'elm',
},
{
name: 'packageName',
example: 'core',
},
),
},
},
]
}

static defaultBadgeData = { label: 'elm package' }

Expand Down
18 changes: 10 additions & 8 deletions services/flathub/flathub-downloads.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'

const schema = Joi.object({
Expand All @@ -9,15 +9,17 @@ const schema = Joi.object({
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',
static openApi = {
'/flathub/downloads/{packageName}': {
get: {
summary: 'Flathub Downloads',
parameters: pathParams({
name: 'packageName',
example: 'org.mozilla.firefox',
}),
},
staticPreview: renderDownloadsBadge({ downloads: '277136' }),
},
]
}

static defaultBadgeData = { label: 'installs' }

Expand Down
18 changes: 10 additions & 8 deletions services/flathub/flathub.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi'
import { renderVersionBadge } from '../version.js'
import { BaseJsonService, NotFound } from '../index.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'

const schema = Joi.alternatives()
.try(
Expand All @@ -14,15 +14,17 @@ const schema = Joi.alternatives()
export default class Flathub extends BaseJsonService {
static category = 'version'
static route = { base: 'flathub/v', pattern: ':packageName' }
static examples = [
{
title: 'Flathub',
namedParams: {
packageName: 'org.mozilla.firefox',
static openApi = {
'/flathub/v/{packageName}': {
get: {
summary: 'Flathub Version',
parameters: pathParams({
name: 'packageName',
example: 'org.mozilla.firefox',
}),
},
staticPreview: renderVersionBadge({ version: '78.0.2' }),
},
]
}

static defaultBadgeData = { label: 'flathub' }

Expand Down
19 changes: 11 additions & 8 deletions services/gem/gem-owner.service.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import Joi from 'joi'
import { floorCount as floorCountColor } from '../color-formatters.js'
import { metric } from '../text-formatters.js'
import { BaseJsonService } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const ownerSchema = Joi.array().required()

export default class GemOwner extends BaseJsonService {
static category = 'other'
static route = { base: 'gem/u', pattern: ':user' }
static examples = [
{
title: 'Gems',
namedParams: { user: 'raphink' },
staticPreview: this.render({ count: 34 }),
keywords: ['ruby'],
static openApi = {
'/gem/u/{user}': {
get: {
summary: 'Gem Owner',
parameters: pathParams({
name: 'user',
example: 'raphink',
}),
},
},
]
}

static defaultBadgeData = { label: 'gems' }

Expand Down
26 changes: 16 additions & 10 deletions services/github/github-discussions-total.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gql from 'graphql-tag'
import Joi from 'joi'
import { pathParams } from '../index.js'
import { nonNegativeInteger } from '../validators.js'
import { GithubAuthV4Service } from './github-auth-service.js'
import { transformErrors } from './github-helpers.js'
Expand All @@ -21,18 +22,23 @@ export default class GithubTotalDiscussions extends GithubAuthV4Service {
pattern: ':user/:repo',
}

static examples = [
{
title: 'GitHub Discussions',
namedParams: {
user: 'vercel',
repo: 'next.js',
static openApi = {
'/github/discussions/{user}/{repo}': {
get: {
summary: 'GitHub Discussions',
parameters: pathParams(
{
name: 'user',
example: 'vercel',
},
{
name: 'repo',
example: 'next.js',
},
),
},
staticPreview: this.render({
discussions: '6000 total',
}),
},
]
}

static defaultBadgeData = { label: 'discussions', color: 'blue' }

Expand Down
25 changes: 16 additions & 9 deletions services/gitter/gitter.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseStaticService } from '../index.js'
import { BaseStaticService, pathParams } from '../index.js'

export default class Gitter extends BaseStaticService {
static category = 'chat'
Expand All @@ -8,16 +8,23 @@ export default class Gitter extends BaseStaticService {
pattern: ':user/:repo',
}

static examples = [
{
title: 'Gitter',
namedParams: {
user: 'nwjs',
repo: 'nw.js',
static openApi = {
'/gitter/room/{user}/{repo}': {
get: {
summary: 'Gitter',
parameters: pathParams(
{
name: 'user',
example: 'nwjs',
},
{
name: 'repo',
example: 'nw.js',
},
),
},
staticPreview: this.render(),
},
]
}

static defaultBadgeData = { label: 'chat' }

Expand Down
18 changes: 11 additions & 7 deletions services/greasyfork/greasyfork-license.service.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { renderLicenseBadge } from '../licenses.js'
import { InvalidResponse } from '../index.js'
import { InvalidResponse, pathParams } from '../index.js'
import BaseGreasyForkService from './greasyfork-base.js'

export default class GreasyForkLicense extends BaseGreasyForkService {
static category = 'license'
static route = { base: 'greasyfork', pattern: 'l/:scriptId' }

static examples = [
{
title: 'Greasy Fork',
namedParams: { scriptId: '407466' },
staticPreview: renderLicenseBadge({ licenses: ['MIT'] }),
static openApi = {
'/greasyfork/l/{scriptId}': {
get: {
summary: 'Greasy Fork License',
parameters: pathParams({
name: 'scriptId',
example: '407466',
}),
},
},
]
}

static defaultBadgeData = { label: 'license' }

Expand Down
17 changes: 11 additions & 6 deletions services/greasyfork/greasyfork-rating.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pathParams } from '../index.js'
import { floorCount as floorCountColor } from '../color-formatters.js'
import { metric } from '../text-formatters.js'
import BaseGreasyForkService from './greasyfork-base.js'
Expand All @@ -6,13 +7,17 @@ export default class GreasyForkRatingCount extends BaseGreasyForkService {
static category = 'rating'
static route = { base: 'greasyfork', pattern: 'rating-count/:scriptId' }

static examples = [
{
title: 'Greasy Fork',
namedParams: { scriptId: '407466' },
staticPreview: this.render({ good: 17, ok: 2, bad: 3 }),
static openApi = {
'/greasyfork/rating-count/{scriptId}': {
get: {
summary: 'Greasy Fork Rating',
parameters: pathParams({
name: 'scriptId',
example: '407466',
}),
},
},
]
}

static defaultBadgeData = { label: 'rating' }

Expand Down
17 changes: 11 additions & 6 deletions services/greasyfork/greasyfork-version.service.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import BaseGreasyForkService from './greasyfork-base.js'

export default class GreasyForkVersion extends BaseGreasyForkService {
static category = 'version'
static route = { base: 'greasyfork', pattern: 'v/:scriptId' }

static examples = [
{
title: 'Greasy Fork',
namedParams: { scriptId: '407466' },
staticPreview: renderVersionBadge({ version: '3.9.3' }),
static openApi = {
'/greasyfork/v/{scriptId}': {
get: {
summary: 'Greasy Fork Version',
parameters: pathParams({
name: 'scriptId',
example: '407466',
}),
},
},
]
}

async handle({ scriptId }) {
const data = await this.fetch({ scriptId })
Expand Down
18 changes: 11 additions & 7 deletions services/hackage/hackage-deps.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseService } from '../index.js'
import { BaseService, pathParams } from '../index.js'

export default class HackageDeps extends BaseService {
static category = 'dependencies'
Expand All @@ -8,13 +8,17 @@ export default class HackageDeps extends BaseService {
pattern: ':packageName',
}

static examples = [
{
title: 'Hackage-Deps',
namedParams: { packageName: 'lens' },
staticPreview: this.render({ isOutdated: false }),
static openApi = {
'/hackage-deps/v/{packageName}': {
get: {
summary: 'Hackage Dependencies',
parameters: pathParams({
name: 'packageName',
example: 'lens',
}),
},
},
]
}

static defaultBadgeData = { label: 'dependencies' }

Expand Down
Loading

0 comments on commit 6823d38

Please sign in to comment.