Skip to content

Commit

Permalink
migrate some services from examples to openApi
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Jul 31, 2023
1 parent 57c2ba0 commit f33d104
Show file tree
Hide file tree
Showing 18 changed files with 231 additions and 156 deletions.
18 changes: 11 additions & 7 deletions services/itunes/itunes.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { renderVersionBadge } from '../version.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService, NotFound } from '../index.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'

const schema = Joi.object({
resultCount: nonNegativeInteger,
Expand All @@ -18,13 +18,17 @@ export default class Itunes extends BaseJsonService {
pattern: ':bundleId',
}

static examples = [
{
title: 'iTunes App Store',
namedParams: { bundleId: '803453959' },
staticPreview: renderVersionBadge({ version: 'v3.3.3' }),
static openApi = {
'/itunes/v/{bundleId}': {
get: {
summary: 'iTunes App Store',
parameters: pathParams({
name: 'bundleId',
example: '803453959',
}),
},
},
]
}

static defaultBadgeData = { label: 'itunes app store' }

Expand Down
17 changes: 10 additions & 7 deletions services/jetbrains/jetbrains-downloads.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { renderDownloadsBadge } from '../downloads.js'
import { nonNegativeInteger } from '../validators.js'
import JetbrainsBase from './jetbrains-base.js'
Expand Down Expand Up @@ -29,15 +30,17 @@ export default class JetbrainsDownloads extends JetbrainsBase {
pattern: ':pluginId',
}

static examples = [
{
title: 'JetBrains plugins',
namedParams: {
pluginId: '1347',
static openApi = {
'/jetbrains/plugin/d/{pluginId}': {
get: {
summary: 'JetBrains plugins',
parameters: pathParams({
name: 'pluginId',
example: '1347',
}),
},
staticPreview: renderDownloadsBadge({ downloads: 10200000 }),
},
]
}

async handle({ pluginId }) {
let downloads
Expand Down
17 changes: 10 additions & 7 deletions services/jetbrains/jetbrains-version.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import JetbrainsBase from './jetbrains-base.js'

Expand Down Expand Up @@ -35,15 +36,17 @@ export default class JetbrainsVersion extends JetbrainsBase {
pattern: ':pluginId',
}

static examples = [
{
title: 'JetBrains Plugins',
namedParams: {
pluginId: '9630',
static openApi = {
'/jetbrains/plugin/v/{pluginId}': {
get: {
summary: 'JetBrains Plugins',
parameters: pathParams({
name: 'pluginId',
example: '9630',
}),
},
staticPreview: this.render({ version: 'v1.7' }),
},
]
}

static defaultBadgeData = { label: 'jetbrains plugin' }

Expand Down
26 changes: 16 additions & 10 deletions services/jitpack/jitpack-version.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 } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const schema = Joi.object({
version: Joi.string().required(),
Expand All @@ -17,17 +17,23 @@ export default class JitPackVersion extends BaseJsonService {
pattern: ':groupId/:artifactId',
}

static examples = [
{
title: 'JitPack',
namedParams: {
groupId: 'com.github.jitpack',
artifactId: 'maven-simple',
static openApi = {
'/jitpack/version/{groupId}/{artifactId}': {
get: {
summary: 'JitPack',
parameters: pathParams(
{
name: 'groupId',
example: 'com.github.jitpack',
},
{
name: 'artifactId',
example: 'maven-simple',
},
),
},
staticPreview: renderVersionBadge({ version: 'v1.1' }),
keywords: ['java', 'maven'],
},
]
}

static defaultBadgeData = { label: 'jitpack' }

Expand Down
29 changes: 20 additions & 9 deletions services/jsdelivr/jsdelivr-hits-github.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pathParams } from '../index.js'
import { schema, periodMap, BaseJsDelivrService } from './jsdelivr-base.js'

export default class JsDelivrHitsGitHub extends BaseJsDelivrService {
Expand All @@ -6,17 +7,27 @@ export default class JsDelivrHitsGitHub extends BaseJsDelivrService {
pattern: ':period(hd|hw|hm|hy)/:user/:repo',
}

static examples = [
{
title: 'jsDelivr hits (GitHub)',
namedParams: {
period: 'hm',
user: 'jquery',
repo: 'jquery',
static openApi = {
'/jsdelivr/gh/{period}/{user}/{repo}': {
get: {
summary: 'jsDelivr hits (GitHub)',
parameters: pathParams(
{
name: 'period',
example: 'hm',
},
{
name: 'user',
example: 'jquery',
},
{
name: 'repo',
example: 'jquery',
},
),
},
staticPreview: this.render({ period: 'hm', hits: 9809876 }),
},
]
}

async fetch({ period, user, repo }) {
return this._requestJson({
Expand Down
20 changes: 11 additions & 9 deletions services/keybase/keybase-btc.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { nonNegativeInteger } from '../validators.js'
import KeybaseProfile from './keybase-profile.js'

Expand Down Expand Up @@ -32,16 +33,17 @@ export default class KeybaseBTC extends KeybaseProfile {
pattern: ':username',
}

static examples = [
{
title: 'Keybase BTC',
namedParams: { username: 'skyplabs' },
staticPreview: this.render({
address: '12ufRLmbEmgjsdGzhUUFY4pcfiQZyRPV9J',
}),
keywords: ['bitcoin'],
static openApi = {
'/keybase/btc/{username}': {
get: {
summary: 'Keybase BTC',
parameters: pathParams({
name: 'username',
example: 'skyplabs',
}),
},
},
]
}

static defaultBadgeData = {
label: 'btc',
Expand Down
17 changes: 11 additions & 6 deletions services/keybase/keybase-pgp.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { nonNegativeInteger } from '../validators.js'
import KeybaseProfile from './keybase-profile.js'

Expand Down Expand Up @@ -28,13 +29,17 @@ export default class KeybasePGP extends KeybaseProfile {
pattern: ':username',
}

static examples = [
{
title: 'Keybase PGP',
namedParams: { username: 'skyplabs' },
staticPreview: this.render({ fingerprint: '1863145FD39EE07E' }),
static openApi = {
'/keybase/pgp/{username}': {
get: {
summary: 'Keybase PGP',
parameters: pathParams({
name: 'username',
example: 'skyplabs',
}),
},
},
]
}

static defaultBadgeData = {
label: 'pgp',
Expand Down
20 changes: 11 additions & 9 deletions services/keybase/keybase-xlm.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { nonNegativeInteger } from '../validators.js'
import KeybaseProfile from './keybase-profile.js'

Expand Down Expand Up @@ -30,16 +31,17 @@ export default class KeybaseXLM extends KeybaseProfile {
pattern: ':username',
}

static examples = [
{
title: 'Keybase XLM',
namedParams: { username: 'skyplabs' },
staticPreview: this.render({
address: 'GCGH37DYONEBPGAZGCHJEZZF3J2Q3EFYZBQBE6UJL5QKTULCMEA6MXLA',
}),
keywords: ['stellar'],
static openApi = {
'/keybase/xlm/{username}': {
get: {
summary: 'Keybase XLM',
parameters: pathParams({
name: 'username',
example: 'skyplabs',
}),
},
},
]
}

static defaultBadgeData = {
label: 'xlm',
Expand Down
20 changes: 11 additions & 9 deletions services/keybase/keybase-zec.service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { pathParams } from '../index.js'
import { nonNegativeInteger } from '../validators.js'
import KeybaseProfile from './keybase-profile.js'

Expand Down Expand Up @@ -32,16 +33,17 @@ export default class KeybaseZEC extends KeybaseProfile {
pattern: ':username',
}

static examples = [
{
title: 'Keybase ZEC',
namedParams: { username: 'skyplabs' },
staticPreview: this.render({
address: 't1RJDxpBcsgqAotqhepkhLFMv2XpMfvnf1y',
}),
keywords: ['zcash'],
static openApi = {
'/keybase/zec/{username}': {
get: {
summary: 'Keybase ZEC',
parameters: pathParams({
name: 'username',
example: 'skyplabs',
}),
},
},
]
}

static defaultBadgeData = {
label: 'zec',
Expand Down
21 changes: 11 additions & 10 deletions services/lemmy/lemmy.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { BaseJsonService, InvalidParameter } from '../index.js'
import { BaseJsonService, InvalidParameter, pathParams } from '../index.js'

const lemmyCommunitySchema = Joi.object({
community_view: Joi.object({
Expand All @@ -18,16 +18,17 @@ export default class Lemmy extends BaseJsonService {
pattern: ':community',
}

static examples = [
{
title: 'Lemmy',
namedParams: { community: 'asklemmy@lemmy.ml' },
staticPreview: this.render({
community: 'asklemmy@lemmy.ml',
members: 42,
}),
static openApi = {
'/lemmy/{community}': {
get: {
summary: 'Lemmy',
parameters: pathParams({
name: 'community',
example: 'asklemmy@lemmy.ml',
}),
},
},
]
}

static defaultBadgeData = { label: 'community' }

Expand Down
22 changes: 11 additions & 11 deletions services/liberapay/liberapay-gives.service.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { InvalidResponse } from '../index.js'
import { InvalidResponse, pathParams } from '../index.js'
import { renderCurrencyBadge, LiberapayBase } from './liberapay-base.js'

export default class LiberapayGives extends LiberapayBase {
static route = this.buildRoute('gives')

static examples = [
{
title: 'Liberapay giving',
namedParams: { entity: 'Changaco' },
staticPreview: renderCurrencyBadge({
label: 'gives',
amount: '2.58',
currency: 'EUR',
}),
static openApi = {
'/liberapay/gives/{entity}': {
get: {
summary: 'Liberapay giving',
parameters: pathParams({
name: 'entity',
example: 'Changaco',
}),
},
},
]
}

async handle({ entity }) {
const data = await this.fetch({ entity })
Expand Down
Loading

0 comments on commit f33d104

Please sign in to comment.