Skip to content

Commit

Permalink
Add genres endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbinf committed Jun 15, 2023
1 parent bbb2cb7 commit 7eec984
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
15 changes: 15 additions & 0 deletions edge-src/api-definitions/BaseDef.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ export const OPENAPI_RESPONSE_TMPL = {
listen_score_global_rank: {...OPENAPI_PROPERTIES.podcastSpec.listen_score_global_rank},
},
},

GENRE: {
"id": {
"type": "integer",
"description": "The id of this genre, which can be used in the `genre_ids` parameter in other endpoints.",
},
"name": {
"type": "string",
"description": "Human-readable genre name.",
},
"parent_id": {
"type": "integer",
"description": "Parent genre's id.",
},
},
}

export default class BaseDef {
Expand Down
37 changes: 37 additions & 0 deletions edge-src/api-definitions/GetGenresDef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import BaseDef, {OPENAPI_PARAMETERS, OPENAPI_RESPONSE_TMPL} from "./BaseDef";

export default class BestPodcastsDef extends BaseDef {
apiFunctionName() {
return 'fetchPodcastGenres'
}

transformResultFunc(result) {
return result.genres
}

openApiPathSpec() {
const params = {
operationId: 'getGenres',
description: 'Fetch a list of podcast genres. ' +
'The `id` field can be used in other endpoints as `genre_id` parameter.',
parameters: [],
response200: {
description: 'Returns a list of podcast genres in json format',
schema: {
type: 'array',
items: {
type: 'object',
properties: OPENAPI_RESPONSE_TMPL.GENRE,
},
},
},
}
return {
'/genres': this._makeOpenApiPathSpec(params),
}
}

extraParams() {
return {}
}
}
7 changes: 7 additions & 0 deletions functions/api/v2/genres.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ListenApiManager from '../../../edge-src/common/ListenApiManager.js'
import GetGenresDef from "../../../edge-src/api-definitions/GetGenresDef";

export async function onRequestGet(context) {
const mgr = new ListenApiManager(context, GetGenresDef)
return await mgr.getResponse()
}
2 changes: 2 additions & 0 deletions functions/chatgpt-plugin/openapi.json/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ResponseBuilder from "../../../edge-src/common/ResponseBuilder";
import JustListenDef from "../../../edge-src/api-definitions/JustListenDef";
import SearchEpisodesDef from "../../../edge-src/api-definitions/SearchEpisodesDef";
import SearchPodcastsDef from "../../../edge-src/api-definitions/SearchPodcastsDef";
import GetGenresDef from '../../../edge-src/api-definitions/GetGenresDef';

// Example spec: https://platform.openai.com/docs/plugins/getting-started/openapi-definition
// - 200 characters max for each API endpoint description/summary field in API specification
Expand Down Expand Up @@ -32,6 +33,7 @@ export async function onRequestGet(context) {
...new SearchPodcastsDef().openApiPathSpec(),
...new SearchEpisodesDef().openApiPathSpec(),
...new JustListenDef().openApiPathSpec(),
...new GetGenresDef().openApiPathSpec(),
},
}
return responseBuilder.getJsonResponse(openapiSpec(params))
Expand Down

0 comments on commit 7eec984

Please sign in to comment.