Skip to content

Commit

Permalink
Update getSingleItem function (#148)
Browse files Browse the repository at this point in the history
Update `getSingleItem` to accept object as parameter.
  • Loading branch information
EarthlingDavey authored Oct 30, 2021
1 parent cfc2bc3 commit bd9ffe8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/shopping.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,21 @@ const getMultipleItems = function (options) {
* @param {String} itemId (required)
*/
const getSingleItem = function (itemId) {
if (!itemId) throw new Error('invalid_request_error -> Item ID is null or invalid');
const requestUrl = `${urlObject.buildShoppingUrl(this.options, 'GetSingleItem')}&${stringifyUrl({ 'ItemID': itemId })} `;
return getRequest(requestUrl).then((data) => {
return JSON.parse(data);
}, console.error // eslint-disable-line no-console
if (!input || (typeof input !== 'object' && typeof input !== 'string'))
throw new Error('invalid_request_error -> Invalid input');
// To preserve backwards compatibility
if (typeof input === 'string') {
input = { ItemID: input };
}
const requestUrl = `${urlObject.buildShoppingUrl(
this.options,
'GetSingleItem'
)}&${stringifyUrl(input)} `;
return getRequest(requestUrl).then(
(data) => {
return JSON.parse(data);
},
console.error // eslint-disable-line no-console
);
};

Expand Down

0 comments on commit bd9ffe8

Please sign in to comment.