Skip to content

Commit

Permalink
fetch-api: add optional qsParams argument to GiphyFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
giannif committed Oct 17, 2023
1 parent f89f1eb commit 721fb02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/fetch-api/public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -154,4 +167,5 @@ text()
textTrending()
animate()
searchVideos()
extraQS()
relatedClips()
11 changes: 9 additions & 2 deletions packages/fetch-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {}) {
this.apiKey = apiKey
this.qsParams = qsParams
}

/**
* @hidden
*/
private apiKey: string

/**
* @hidden
*/
private qsParams: Record<string, string>
/**
* @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 })
}

/**
Expand Down

0 comments on commit 721fb02

Please sign in to comment.