Skip to content

Commit

Permalink
Merge pull request #432 from Giphy/fetch-api-internal
Browse files Browse the repository at this point in the history
fetch api internal option for gif request
  • Loading branch information
giannif authored Jan 4, 2024
2 parents 0fc034f + 357c1b9 commit c9789cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-tips-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@giphy/js-fetch-api': minor
---

fetch-api: internal option for extra gif metadata
11 changes: 11 additions & 0 deletions packages/fetch-api/public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ const gif = async () => {
console.error('gif', error)
}
}

const internalGif = async () => {
try {
const result = await gf.gif('3oEjHGr1Fhz0kyv8Ig', { internal: true })
console.log('gif', result)
} catch (error) {
// console.error('expected error here with a public api key', error)
}
}

const gifs = async () => {
try {
const result = await gf.gifs(['3oEjHGr1Fhz0kyv8Ig'])
Expand Down Expand Up @@ -155,6 +165,7 @@ categories()
search()
searchChannel()
gif()
internalGif()
gifs()
gifByCategory()
categories()
Expand Down
6 changes: 4 additions & 2 deletions packages/fetch-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export class GiphyFetch {
* @param {string} id
* @returns {Promise<GifsResult>}
**/
gif(id: string): Promise<GifResult> {
return request(`gifs/${id}?${this.getQS()}`, { normalizer: normalizeGif }) as Promise<GifResult>
gif(id: string, options?: { internal?: boolean }): Promise<GifResult> {
// there is an internal endpoint that has more metadata available only specific api keys
const prefix = options?.internal ? 'internal/' : ''
return request(`${prefix}gifs/${id}?${this.getQS()}`, { normalizer: normalizeGif }) as Promise<GifResult>
}

/**
Expand Down

0 comments on commit c9789cd

Please sign in to comment.