Skip to content

Commit f275408

Browse files
authored
Added findItemsineBayStores support (#94)
* v2.7.7 * simple * add find items in ebay stores api
1 parent c52bdcb commit f275408

File tree

7 files changed

+108
-71
lines changed

7 files changed

+108
-71
lines changed

demo/findingApi.js renamed to demo/finding.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ ebay.getVersion().then((data) => {
7474
}, (error) => {
7575
console.log(error);
7676
});
77+
78+
79+
// Find ebay stores here https://www.ebay.com/sns
80+
// https://developer.ebay.com/devzone/finding/callref/findItemsIneBayStores.html
81+
ebay.findItemsIneBayStores({storeName: 'Battery Gallery'}).then((data) => {
82+
console.log(data);
83+
}, (error) => {
84+
console.log(error);
85+
});

demo/getAccessToken.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
const EbayToken = require('oauth-ebay');
1+
const Ebay = require('../src/index');
22
const { clientId, clientSecret } = require('./credentials/index');
33

4-
let ebay = new EbayToken({
4+
let ebay = new Ebay({
55
clientID: clientId,
66
clientSecret: clientSecret,
7-
grantType: 'client_credentials'
7+
body: {
8+
grant_type: 'client_credentials',
9+
scope: 'https://api.ebay.com/oauth/api_scope'
10+
11+
}
812
});
9-
ebay.getAccessToken().then((data) => {
10-
console.log(data);
11-
}, (error) => {
12-
console.log(error);
13-
});
13+
14+
//console.log(ebay.getAccessToken());
15+
16+
// // //Search for Items by Keyword.
17+
ebay.getAccessToken()
18+
.then((data) => {
19+
console.log("generate tokensss");
20+
console.log(data);
21+
});
22+
23+
console.log("++++++++++++++++++++");
24+
25+
ebay.getAccessToken()
26+
.then((data) => {
27+
console.log("generate tokensss");
28+
console.log(data);
29+
});
30+
31+
32+
setTimeout(() => {
33+
ebay.getAccessToken()
34+
.then((data) => {
35+
console.log("generate tokensss");
36+
console.log(data);
37+
});
38+
}, 7200);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ebay-node-api",
3-
"version": "2.8.4",
3+
"version": "2.8.5",
44
"description": "Ebay node api client",
55
"main": "./src/index.js",
66
"homepage": "https://github.com/pajaydev/ebay-node-api",
@@ -9,7 +9,7 @@
99
"test": "mocha && npm run lint",
1010
"docs": "docsify init ./docs",
1111
"serve-docs": "docsify serve docs",
12-
"publish": "gh-pages --dist docs --dotfiles --message 'chore: Publish docs'",
12+
"docs-publish": "gh-pages --dist docs --dotfiles --message 'chore: Publish docs'",
1313
"prepublish": "npm run test"
1414
},
1515
"author": "Ajaykumar prathap",

src/common-utils/index.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,42 @@ const { makeRequest } = require('../request');
44
const base64Encode = (encodeData) => {
55
const buff = Buffer.from(encodeData);;
66
return buff.toString('base64');
7-
}
7+
};
8+
9+
/**
10+
* Constructs query param based on some logic to support filter and aspect_filter params.
11+
* output will be keywords=iphone&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=FreeShippingOnly&itemFilter(1).value=true&itemFilter(2).name=SoldItemsOnly&itemFilter(2).value=true
12+
* @param {Object} options
13+
*/
14+
const constructAdditionalParams = (options) => {
15+
let params = '';
16+
let count = 0;
17+
for (let key in options) {
18+
if (options.hasOwnProperty(key)) {
19+
if (key === 'entriesPerPage' || key === 'pageNumber') {
20+
params = `${params}paginationInput.${key}=${options[key]}&`;
21+
}
22+
else if (key === 'keywords' || key === 'categoryId' || key === 'productId' || key === 'sortOrder' || key === 'storeName') {
23+
const encodeParam = encodeURIComponent(options[key]);
24+
params = `${params}${key}=${encodeParam}&`;
25+
}
26+
else if (key === 'affiliate') {
27+
const innerParams = options[key];
28+
for (let innerKey in innerParams) {
29+
params = `${params}${key}.${innerKey}=${innerParams[innerKey]}&`;
30+
}
31+
}
32+
else {
33+
params = `${params}itemFilter(${count}).name=${key}&
34+
itemFilter(${count}).value=${options[key]}&`;
35+
count += 1;
36+
}
37+
}
38+
}
39+
// replace extra space
40+
params = params.replace(/\s/g, '');
41+
return params.substring(0, params.length - 1);
42+
};
843

944
module.exports = {
1045
setAccessToken: function (token) {
@@ -63,5 +98,6 @@ module.exports = {
6398
}
6499
return url;
65100
},
66-
base64Encode
101+
base64Encode,
102+
constructAdditionalParams
67103
};

src/findingApi.js renamed to src/finding.js

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
const urlObject = require('./buildURL');
44
const { getRequest } = require('./request');
5+
const utils = require('./common-utils/index');
56
const FIND_ITEMS_BY_KEYWORD = 'findItemsByKeywords';
67
const FIND_ITEMS_BY_CATEGORY = 'findItemsByCategory';
78
const FIND_COMPLETED_ITEMS = 'findCompletedItems';
89
const FIND_ITEMS_ADV = 'findItemsAdvanced';
10+
const FIND_EBAY_STORES = 'findItemsIneBayStores';
911

1012
const findItemsByKeywords = function (options) {
1113
if (!options) {
@@ -16,7 +18,7 @@ const findItemsByKeywords = function (options) {
1618
// support only keyword string.
1719
if (!options.keywords) options = { keywords: options };
1820
options.keywords = encodeURIComponent(options.keywords);
19-
this.options.additionalParam = constructAdditionalParams(options);
21+
this.options.additionalParam = utils.constructAdditionalParams(options);
2022
const url = urlObject.buildSearchUrl(this.options);
2123
return getRequest(url).then((data) => {
2224
return JSON.parse(data).findItemsByKeywordsResponse;
@@ -48,7 +50,7 @@ const findCompletedItems = function (options) {
4850
options.keywords = encodeURIComponent(options.keywords);
4951
}
5052
this.options.operationName = FIND_COMPLETED_ITEMS;
51-
this.options.additionalParam = constructAdditionalParams(options);
53+
this.options.additionalParam = utils.constructAdditionalParams(options);
5254
const url = urlObject.buildSearchUrl(this.options);
5355
return getRequest(url).then((data) => {
5456
return JSON.parse(data).findCompletedItemsResponse;
@@ -69,8 +71,9 @@ const findItemsAdvanced = function (options) {
6971
options.keywords = encodeURIComponent(options.keywords);
7072
}
7173
this.options.operationName = FIND_ITEMS_ADV;
72-
this.options.additionalParam = constructAdditionalParams(options);
74+
this.options.additionalParam = utils.constructAdditionalParams(options);
7375
const url = urlObject.buildSearchUrl(this.options);
76+
console.log(url);
7477
return getRequest(url).then((data) => {
7578
return JSON.parse(data).findItemsAdvancedResponse;
7679
}, console.error // eslint-disable-line no-console
@@ -96,57 +99,36 @@ const findItemsByProduct = function (options) {
9699
if (!options.productId) throw new Error('INVALID_REQUEST_PARMS --> Product ID is required.');
97100
let type = options.type ? options.type : 'ReferenceID';
98101
this.options.operationName = 'findItemsByProduct';
99-
this.options.additionalParam = constructAdditionalParams(options);
102+
this.options.additionalParam = utils.constructAdditionalParams(options);
100103
let url = urlObject.buildSearchUrl(this.options);
101104
url = `${url}&productId.@type=${type}`;
105+
console.log(url);
102106
return getRequest(url).then((data) => {
103107
return JSON.parse(data).findItemsByProductResponse;
104108

105109
}, console.error // eslint-disable-line no-console
106110
);
107111
};
108112

113+
const findItemsIneBayStores = function (options) {
114+
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Please enter the Valid input.');
115+
if (!options.storeName) throw new Error('INVALID_REQUEST_PARMS --> Store name is required.');
116+
this.options.operationName = FIND_EBAY_STORES;
117+
this.options.additionalParam = utils.constructAdditionalParams(options);
118+
console.log(urlObject.buildSearchUrl(this.options));
119+
return getRequest(urlObject.buildSearchUrl(this.options)).then((data) => {
120+
return JSON.parse(data).findItemsIneBayStoresResponse;
109121

110-
/**
111-
* Constructs query param based on some logic to support filter and aspect_filter params.
112-
* output will be keywords=iphone&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=FreeShippingOnly&itemFilter(1).value=true&itemFilter(2).name=SoldItemsOnly&itemFilter(2).value=true
113-
* @param {Object} options
114-
*/
115-
const constructAdditionalParams = (options) => {
116-
let params = '';
117-
let count = 0;
118-
for (let key in options) {
119-
if (options.hasOwnProperty(key)) {
120-
if (key === 'entriesPerPage' || key === 'pageNumber') {
121-
params = `${params}paginationInput.${key}=${options[key]}&`;
122-
}
123-
else if (key === 'keywords' || key === 'categoryId' || key === 'productId' || key === 'sortOrder') {
124-
params = `${params}${key}=${options[key]}&`;
125-
}
126-
else if (key === 'affiliate') {
127-
const innerParams = options[key];
128-
for (let innerKey in innerParams) {
129-
params = `${params}${key}.${innerKey}=${innerParams[innerKey]}&`;
130-
}
131-
}
132-
else {
133-
params = `${params}itemFilter(${count}).name=${key}&
134-
itemFilter(${count}).value=${options[key]}&`;
135-
count += 1;
136-
}
137-
}
138-
}
139-
// replace extra space
140-
params = params.replace(/\s/g, '');
141-
return params.substring(0, params.length - 1);
122+
}, console.error // eslint-disable-line no-console
123+
);
142124
};
143125

144126
module.exports = {
145127
findItemsByKeywords,
146128
findItemsByCategory,
147129
findCompletedItems,
148-
constructAdditionalParams,
149130
findItemsByProduct,
150131
findItemsAdvanced,
132+
findItemsIneBayStores,
151133
getVersion
152134
};

src/index.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
'use strict';
22
const ebayBuyApi = require('./buy-api');
33
const shoppingApi = require('./shopping');
4-
const { getDefaultCategoryTreeId,
5-
getCategoryTree,
6-
getCategorySubtree,
7-
getCategorySuggestions,
8-
getItemAspectsForCategory } = require('./taxonomy-api');
9-
const ebayFindingApi = require('./findingApi');
10-
const { setAccessToken,
11-
getAccessToken,
12-
setHeaders,
13-
getHeaders
14-
} = require('./common-utils');
4+
const taxonomyApi = require('./taxonomy-api');
5+
const ebayFindingApi = require('./finding');
6+
const commonUtils = require('./common-utils');
157
const { getSimilarItems, getMostWatchedItems } = require('./merchandising');
168
const { PROD_BASE_URL, SANDBOX_BASE_URL, BASE_SANDBX_SVC_URL, BASE_SVC_URL } = require('./constants');
179
const PROD_ENV = 'PROD';
@@ -42,25 +34,18 @@ function Ebay(options) {
4234
options.baseSvcUrl = BASE_SANDBX_SVC_URL;
4335
}
4436
this.options = options;
45-
setHeaders(this, options.headers);
37+
commonUtils.setHeaders(this, options.headers);
4638
this.options.globalID = options.countryCode || 'EBAY-US';
4739
this.options.siteId = options.siteId || '0';
4840
}
4941

5042
Ebay.prototype = {
51-
setAccessToken,
52-
getAccessToken,
53-
setHeaders,
54-
getHeaders,
55-
getDefaultCategoryTreeId,
56-
getCategoryTree,
57-
getCategorySubtree,
58-
getCategorySuggestions,
59-
getItemAspectsForCategory,
6043
getMostWatchedItems,
6144
getSimilarItems,
45+
...commonUtils,
6246
...shoppingApi,
6347
...ebayBuyApi,
48+
...taxonomyApi,
6449
...ebayFindingApi
6550
};
6651

test/finding.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const expect = require('chai').expect;
33
const should = require('chai').should();
44
const nock = require('nock');
55
const Ebay = require('../src/index');
6-
const { constructAdditionalParams } = require('../src/findingApi');
6+
const { constructAdditionalParams } = require('../src/common-utils/index');
77
const nockFindingApi = nock('https://svcs.ebay.com/');
88

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

0 commit comments

Comments
 (0)