Skip to content

Commit

Permalink
feat(helper): ✨ add function getParamString to make param construct…
Browse files Browse the repository at this point in the history
…ion easier to read and add to
  • Loading branch information
djdembeck committed Aug 9, 2022
1 parent 596fedb commit 302de43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/helpers/books/audible/ApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ class ApiHelper {
const helper = new SharedHelper()
const baseDomain = 'https://api.audible.com'
const baseUrl = '1.0/catalog/products'
const params =
'?response_groups=contributors,product_desc,product_extended_attrs,product_attrs,media,rating,series&image_sizes=500,1024'
const paramArr = [
'contributors',
'product_desc',
'product_extended_attrs',
'product_attrs',
'media',
'rating',
'series',
'image_sizes=500,1024'
]
const paramStr = helper.getParamString(paramArr)
const params = `?response_groups=${paramStr}`
this.reqUrl = helper.buildUrl(asin, baseDomain, baseUrl, params)
}

Expand Down
9 changes: 9 additions & 0 deletions src/helpers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ class SharedHelper {
getGenreAsinFromUrl(url: string): string | undefined {
return url.match(this.asin11Regex)?.[0]
}

/**
* Combine the given array of string parameters into a single string.
* @param {string[]} params the array of string parameters to combine
* @returns {string} the combined string
*/
getParamString(params: string[]): string {
return params.slice(0, -1).join(',') + '&' + params.slice(-1)
}
}

export default SharedHelper

0 comments on commit 302de43

Please sign in to comment.