From bd9ffe83fb15e737088bfc9992c65aa98d914a72 Mon Sep 17 00:00:00 2001 From: EarthlingDavey <15802017+EarthlingDavey@users.noreply.github.com> Date: Sat, 30 Oct 2021 06:13:45 +0100 Subject: [PATCH] Update getSingleItem function (#148) Update `getSingleItem` to accept object as parameter. --- src/shopping.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/shopping.js b/src/shopping.js index 8b788c7..6ae7eea 100644 --- a/src/shopping.js +++ b/src/shopping.js @@ -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 ); };