Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch api extra qs params #418

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fluffy-months-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@giphy/js-fetch-api': minor
---

add optional qs params argument to GiphyFetch constructor

Any params passed here will be apppened to all requests
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
node-version: 16.x
cache: 'yarn'
- run: yarn install --immutable --immutable-cache
- run: yarn install --immutable
- name: Build
run: yarn run build
- name: Lint and Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version: 16.x
cache: 'yarn'

- run: yarn install --immutable --immutable-cache
- run: yarn install --immutable
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
Expand Down
4 changes: 2 additions & 2 deletions packages/fetch-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@types/qs": "^6.9.4",
"jest-fetch-mock": "^3.0.3",
"parcel-bundler": "latest",
"typedoc": "^0.20.36",
"typedoc-thunder-theme": "^0.0.2",
"typedoc": "^0.20.37",
"typedoc-thunder-theme": "^0.0.3",
"typescript": "^5.0.4"
}
}
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
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2533,8 +2533,8 @@ __metadata:
jest-fetch-mock: ^3.0.3
parcel-bundler: latest
qs: ^6.9.4
typedoc: ^0.20.36
typedoc-thunder-theme: ^0.0.2
typedoc: ^0.20.37
typedoc-thunder-theme: ^0.0.3
typescript: ^5.0.4
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -21879,14 +21879,14 @@ __metadata:
languageName: node
linkType: hard

"typedoc-thunder-theme@npm:^0.0.2":
version: 0.0.2
resolution: "typedoc-thunder-theme@npm:0.0.2"
checksum: 0d41937b831aff3cd653a436f05d0eba0757315ac712171aab497cd108f3e0fbc8ee82eaa28e3db0af41ad7eb790ea8c2dffd6e97a7aae39f3bcb4af43c112ec
"typedoc-thunder-theme@npm:^0.0.3":
version: 0.0.3
resolution: "typedoc-thunder-theme@npm:0.0.3"
checksum: f19ce94290fe2c145170dfb7d52e90dfe16da1c8c6e7b38b6e997ccf3cb943c6e85f9bcff2efeac0dfbfbac747dedb558b59f5dbfe9594d5d9bc5cfcde938e28
languageName: node
linkType: hard

"typedoc@npm:^0.20.36":
"typedoc@npm:^0.20.37":
version: 0.20.37
resolution: "typedoc@npm:0.20.37"
dependencies:
Expand Down