Skip to content
Open
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
25 changes: 22 additions & 3 deletions lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,36 @@ function search (opts) {
const url = BASE_URL + encodeURIComponent(opts.term);
const storeId = common.storeId(opts.country);
const lang = opts.lang || 'en-us';

// The platformId is not well documented but this is what
// I have gathered so far and will be digging in more as I have time
/*
{
K7: 20, // iPad
P7: 21, // iPhone
K71: 23, // iPad
P71: 24, // iPhone
K8: 25, // iPad
P8: 26, // iPhone
P84: 29, // iPhone
K84: 30, // iPad
Android: 31,
Watch: 35,
MacPodcasts1: 38
}
*/
const platformId = opts.platform === 'ipad' ? 25 : 24;
common.request(
url,
{
'X-Apple-Store-Front': `${storeId},24 t:native`,
'X-Apple-Store-Front': `${storeId},${platformId} t:native`,
'Accept-Language': lang
},
opts.requestOptions
)
.then(JSON.parse)
.then((response) => (response.bubbles[0] && response.bubbles[0].results) || [])
.then((response) => {
return (response.bubbles && response.bubbles.length > 0 && response.bubbles[0].results) || (response.pageData && response.pageData.bubbles.length > 0 && response.pageData.bubbles[0].results) || []
})
.then(paginate(opts.num, opts.page))
.then(R.pluck('id'))
.then((ids) => {
Expand Down