Skip to content

Commit

Permalink
added findItemsByProduct support
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaydev committed Sep 21, 2019
1 parent dd84153 commit 83b88be
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
11 changes: 11 additions & 0 deletions demo/findingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ ebay.findCompletedItems({
console.log(error);
});

// This call searches for items on eBay using specific eBay product values.
// https://developer.ebay.com/DevZone/finding/CallRef/findItemsByProduct.html#findItemsByProduct
ebay.findItemsByProduct({
productId: 53039031,
entriesPerPage: 2
}).then((data) => {
console.log(data);
}, (error) => {
console.log(error);
});

ebay.getVersion().then((data) => {
console.log(data.version);
}, (error) => {
Expand Down
32 changes: 28 additions & 4 deletions src/findingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ const urlObject = require('./buildURL');
const { getRequest } = require('./request');

const findItemsByKeywords = function (options) {
if (!options || !options.keywords) {
if (!options) {
throw new Error('Keyword is missing, Keyword is required');
}

this.options.operationName = 'findItemsByKeywords';
this.options.param = 'keywords';

// support only keyword string.
if (!options.keywords) {
this.options.name = options;
}
Expand Down Expand Up @@ -42,6 +41,11 @@ const findItemsByCategory = function (categoryID) {
);
};

/**
* searches for items whose listings are completed and are no longer available for
* sale by category (using categoryId), by keywords (using keywords), or a combination of the two.
* @param {Object} options
*/
const findCompletedItems = function (options) {
if (!options) throw new Error('Keyword or category ID are required.');
if (!options.keywords && !options.categoryId) throw new Error('Keyword or category ID are required.');
Expand All @@ -58,6 +62,7 @@ const findCompletedItems = function (options) {
);
};


const getVersion = function () {
this.options.operationName = 'getVersion';
const url = urlObject.buildSearchUrl(this.options);
Expand All @@ -67,6 +72,24 @@ const getVersion = function () {
);
};

/**
* Searches for items on eBay using specific eBay product values.
* @param {Object} options
*/
const findItemsByProduct = function (options) {
if (!options) throw new Error('Please enter the Valid input.');
if (!options.productId) throw new Error('Product ID is required.');
this.options.operationName = 'findItemsByProduct';
this.options.additionalParam = constructAdditionalParams(options);
let url = urlObject.buildSearchUrl(this.options);
url = `${url}&productId.@type=ReferenceID`;
return getRequest(url).then((data) => {
return JSON.parse(data).findItemsByProductResponse;

}, console.error
);
};

const constructAdditionalParams = (options) => {
let params = '';
let count = 0;
Expand All @@ -75,7 +98,7 @@ const constructAdditionalParams = (options) => {
if (key === 'entriesPerPage' || key === 'pageNumber') {
params = `${params}paginationInput.${key}=${options[key]}&`;
}
else if (key === 'keywords' || key === 'categoryId' || key === 'sortOrder') {
else if (key === 'keywords' || key === 'categoryId' || key === 'productId' || key === 'sortOrder') {
params = `${params}${key}=${options[key]}&`;
}
else {
Expand All @@ -95,5 +118,6 @@ module.exports = {
findItemsByCategory,
findCompletedItems,
constructAdditionalParams,
findItemsByProduct,
getVersion
};
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { getDefaultCategoryTreeId,
const { findItemsByKeywords,
findItemsByCategory,
findCompletedItems,
findItemsByProduct,
getVersion } = require('./findingApi');
const { setAccessToken,
getAccessToken,
Expand Down Expand Up @@ -63,6 +64,7 @@ Ebay.prototype = {
findItemsByKeywords,
findItemsByCategory,
findCompletedItems,
findItemsByProduct,
getVersion,
getItem,
getItemByLegacyId,
Expand Down

0 comments on commit 83b88be

Please sign in to comment.