From 721fb02777eb02394e1fa5cb032fb67bc90f0427 Mon Sep 17 00:00:00 2001 From: Gianni Ferullo Date: Tue, 17 Oct 2023 14:35:49 -0400 Subject: [PATCH] fetch-api: add optional qsParams argument to GiphyFetch --- packages/fetch-api/public/index.tsx | 14 ++++++++++++++ packages/fetch-api/src/api.ts | 11 +++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/fetch-api/public/index.tsx b/packages/fetch-api/public/index.tsx index 801df209..f8c7f270 100644 --- a/packages/fetch-api/public/index.tsx +++ b/packages/fetch-api/public/index.tsx @@ -138,6 +138,19 @@ const textTrending = async () => { console.error('textTrending', error) } } + +const extraQS = async () => { + try { + const gf = new GiphyFetch('sXpGFDGZs0Dv1mmNFvYaGUvYwKX0PWIh', { countryCode: 'us' }) + const result = await gf.trending({ + limit: 2, + type: 'text', + }) + console.log('extra qs', result) + } catch (error) { + console.error('extra qs', error) + } +} categories() search() searchChannel() @@ -154,4 +167,5 @@ text() textTrending() animate() searchVideos() +extraQS() relatedClips() diff --git a/packages/fetch-api/src/api.ts b/packages/fetch-api/src/api.ts index 6a2064e9..5f047b4c 100644 --- a/packages/fetch-api/src/api.ts +++ b/packages/fetch-api/src/api.ts @@ -21,21 +21,28 @@ const getType = (options?: TypeOption): MediaType => (options && options.type ? /** * @class GiphyFetch * @param {string} apiKey + * @param {object} qsParams */ export class GiphyFetch { - constructor(apiKey: string) { + constructor(apiKey: string, qsParams: Record = {}) { this.apiKey = apiKey + this.qsParams = qsParams } /** * @hidden */ private apiKey: string + + /** + * @hidden + */ + private qsParams: Record /** * @hidden */ private getQS = (options: any = {}) => { - return qs.stringify({ ...options, api_key: this.apiKey, pingback_id: getPingbackId() }) + return qs.stringify({ ...options, api_key: this.apiKey, pingback_id: getPingbackId(), ...this.qsParams }) } /**