Skip to content

Commit

Permalink
Added findItemsAdvanced support (#69)
Browse files Browse the repository at this point in the history
* added findItemsAdvanced support

* handle error

* updated readmre
  • Loading branch information
pajaydev authored Dec 26, 2019
1 parent 8b75799 commit f3bee06
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 18 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The intent is to simplify the request process by handling the tedious logic. It'
* [Usage](#usage)
* [Examples](#examples)
* [Getting Access Token](#getaccesstoken)
* [Finding Api(findItemsByKeywords, findItemsByCategory, findCompletedItems, findItemsByProduct, getVersion)](#finding-api)
* [Finding Api(findItemsByKeywords, findItemsByCategory, findCompletedItems, findItemsByProduct, findItemsAdvanced, getVersion)](#finding-api)
* [Fetch Items By Keyword](#fetchitemsbykeyword)
* [Get Items By Category](#getitemsbycategory)
* [Get Single Item](#getitem)
Expand Down Expand Up @@ -148,6 +148,17 @@ ebay.findItemsByProduct({
console.log(error);
});

// https://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html
ebay.findItemsAdvanced({
entriesPerPage: 2,
keywords: 'ipad',
ExpeditedShippingType: 'OneDayShipping'
}).then((data) => {
console.log(data);
}, (error) => {
console.log(error);
});

ebay.getVersion().then((data) => {
console.log(data.version);
}, (error) => {
Expand Down
13 changes: 12 additions & 1 deletion demo/findingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ebay.findCompletedItems({
console.log(error);
});

// This call searches for items on eBay using specific eBay product values.
// // 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,
Expand All @@ -58,6 +58,17 @@ ebay.findItemsByProduct({
console.log(error);
});

// Searches items on eBay by category or keyword or both.
ebay.findItemsAdvanced({
entriesPerPage: 2,
keywords: 'ipad',
ExpeditedShippingType: 'OneDayShipping'
}).then((data) => {
console.log(data);
}, (error) => {
console.log(error);
});

ebay.getVersion().then((data) => {
console.log(data.version);
}, (error) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ebay-node-api",
"version": "2.7.5",
"version": "2.7.6",
"description": "Ebay node api client",
"main": "./src/index.js",
"homepage": "https://github.com/pajaydev/ebay-node-api",
Expand Down
31 changes: 28 additions & 3 deletions src/findingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

const urlObject = require('./buildURL');
const { getRequest } = require('./request');
const FIND_ITEMS_BY_KEYWORD = 'findItemsByKeywords';
const FIND_ITEMS_BY_CATEGORY = 'findItemsByCategory';
const FIND_COMPLETED_ITEMS = 'findCompletedItems';
const FIND_ITEMS_ADV = 'findItemsAdvanced';

const findItemsByKeywords = function (options) {
if (!options) {
throw new Error('INVALID_REQUEST_PARMS --> Keyword is missing, Keyword is required');
}
this.options.operationName = 'findItemsByKeywords';
this.options.operationName = FIND_ITEMS_BY_KEYWORD;
this.options.param = 'keywords';
// support only keyword string.
if (!options.keywords) {
Expand All @@ -25,7 +29,7 @@ const findItemsByKeywords = function (options) {
const findItemsByCategory = function (categoryID) {
if (!categoryID) throw new Error('INVALID_REQUEST_PARMS --> Category ID is null or invalid');
this.options.name = categoryID;
this.options.operationName = 'findItemsByCategory';
this.options.operationName = FIND_ITEMS_BY_CATEGORY;
this.options.param = 'categoryId';
const url = urlObject.buildSearchUrl(this.options);
return getRequest(url).then((data) => {
Expand All @@ -46,7 +50,7 @@ const findCompletedItems = function (options) {
if (options.keywords) {
options.keywords = encodeURIComponent(options.keywords);
}
this.options.operationName = 'findCompletedItems';
this.options.operationName = FIND_COMPLETED_ITEMS;
this.options.additionalParam = constructAdditionalParams(options);
const url = urlObject.buildSearchUrl(this.options);
return getRequest(url).then((data) => {
Expand All @@ -57,6 +61,26 @@ const findCompletedItems = function (options) {
};


/**
* 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 findItemsAdvanced = function (options) {
if (!options) throw new Error('INVALID_REQUEST_PARMS --> check here for input fields https://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html#Input');
if (options.keywords) {
options.keywords = encodeURIComponent(options.keywords);
}
this.options.operationName = FIND_ITEMS_ADV;
this.options.additionalParam = constructAdditionalParams(options);
const url = urlObject.buildSearchUrl(this.options);
return getRequest(url).then((data) => {
return JSON.parse(data).findItemsAdvancedResponse;
}, console.error
);
};


const getVersion = function () {
this.options.operationName = 'getVersion';
const url = urlObject.buildSearchUrl(this.options);
Expand Down Expand Up @@ -126,5 +150,6 @@ module.exports = {
findCompletedItems,
constructAdditionalParams,
findItemsByProduct,
findItemsAdvanced,
getVersion
};
14 changes: 3 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const { getDefaultCategoryTreeId,
getCategorySubtree,
getCategorySuggestions,
getItemAspectsForCategory } = require('./taxonomy-api');
const { findItemsByKeywords,
findItemsByCategory,
findCompletedItems,
findItemsByProduct,
getVersion } = require('./findingApi');
const ebayFindingApi = require('./findingApi');
const { setAccessToken,
getAccessToken,
setHeaders,
Expand Down Expand Up @@ -58,11 +54,6 @@ Ebay.prototype = {
getAccessToken,
setHeaders,
getHeaders,
findItemsByKeywords,
findItemsByCategory,
findCompletedItems,
findItemsByProduct,
getVersion,
getDefaultCategoryTreeId,
getCategoryTree,
getCategorySubtree,
Expand All @@ -74,7 +65,8 @@ Ebay.prototype = {
getShippingCosts,
getItemStatus,
getUserDetails,
...ebayBuyApi
...ebayBuyApi,
...ebayFindingApi
};

module.exports = Ebay;
22 changes: 21 additions & 1 deletion test/findingApi.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const expect = require('chai').expect;
const should = require('chai').should();
const nock = require('nock');
const eBay = require('../src/index');
const { constructAdditionalParams } = require('../src/findingApi');

const nockFindingApi = nock('https://svcs.ebay.com/');

describe('test ebay finding Api', () => {

Expand Down Expand Up @@ -81,4 +82,23 @@ describe('test ebay finding Api', () => {
expect(constructAdditionalParams(optionsWithPagination)).to.be.equal(expected_pag_param);
});
});

describe('test all get apis', () => {
it("test findItemsAdvanced", () => {
let ebay = new eBay({
clientID: 'ABCD'
});
nockFindingApi.get('/services/search/FindingService/v1?SECURITY-APPNAME=ABCD&OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&paginationInput.entriesPerPage=2&keywords=ipad&itemFilter(0).name=ExpeditedShippingType&itemFilter(0).value=OneDayShipping&outputSelector(0)=SellerInfo&GLOBAL-ID=EBAY-US')
.reply(200, { "findItemsAdvancedResponse": [{ "ack": ["Success"] }] });
return ebay.findItemsAdvanced({
entriesPerPage: 2,
keywords: 'ipad',
ExpeditedShippingType: 'OneDayShipping'
}).then((data) => {
expect(data.findItemsAdvancedResponse).not.null;
}, (error) => {
console.log(error);
});
});
})
});

0 comments on commit f3bee06

Please sign in to comment.