Skip to content

Commit bd9ffe8

Browse files
Update getSingleItem function (#148)
Update `getSingleItem` to accept object as parameter.
1 parent cfc2bc3 commit bd9ffe8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/shopping.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,21 @@ const getMultipleItems = function (options) {
6666
* @param {String} itemId (required)
6767
*/
6868
const getSingleItem = function (itemId) {
69-
if (!itemId) throw new Error('invalid_request_error -> Item ID is null or invalid');
70-
const requestUrl = `${urlObject.buildShoppingUrl(this.options, 'GetSingleItem')}&${stringifyUrl({ 'ItemID': itemId })} `;
71-
return getRequest(requestUrl).then((data) => {
72-
return JSON.parse(data);
73-
}, console.error // eslint-disable-line no-console
69+
if (!input || (typeof input !== 'object' && typeof input !== 'string'))
70+
throw new Error('invalid_request_error -> Invalid input');
71+
// To preserve backwards compatibility
72+
if (typeof input === 'string') {
73+
input = { ItemID: input };
74+
}
75+
const requestUrl = `${urlObject.buildShoppingUrl(
76+
this.options,
77+
'GetSingleItem'
78+
)}&${stringifyUrl(input)} `;
79+
return getRequest(requestUrl).then(
80+
(data) => {
81+
return JSON.parse(data);
82+
},
83+
console.error // eslint-disable-line no-console
7484
);
7585
};
7686

0 commit comments

Comments
 (0)