Skip to content

Commit 37ab97d

Browse files
authored
Integerate Shopping Api (#30)
* added shopping api * organize shopping url * updated shopping api * remove console log * fix test case
1 parent 395871a commit 37ab97d

14 files changed

+132
-59
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"escape": true
1010
},
1111
"rules": {
12-
"strict": 0,
12+
"strict": [
13+
"error",
14+
"global"
15+
],
1316
"curly": 0,
1417
"no-empty": 0,
1518
"no-underscore-dangle": 0,

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The intent is to simplify the request process by handling the tedious logic. It'
2929
* [Search Items Based on Price and Condition](#searchitemsbyfilter)
3030
* [Taxonomy Api(getDefaultCategoryTreeId, getCategoryTree, getCategorySubtree, getCategorySuggestions)](#taxonomyapi)
3131
* [Get Most Watched item, Get Most Similar Items](#merchandisingapi)
32+
* [Get All Categories, GetUserDetails, GetShippingCost, GetItemStatus](#shoppingapi)
3233
* [Test](#test)
3334
* [Issues](#issues)
3435
* [Contribution](#contribution)

demo/getAllCategories.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

demo/getUserDetails.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

demo/shopping.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const Ebay = require('../src/index');
4+
5+
let ebay = new Ebay({
6+
clientID: "--AppID/ClientID--",
7+
});
8+
9+
ebay.getAllCategories('1234').then((data) => {
10+
console.log(data); //extract data.CategoryArray
11+
}, (error) => {
12+
console.log(error);
13+
});
14+
15+
16+
// Get User Profile
17+
// https://developer.ebay.com/devzone/shopping/docs/callref/GetUserProfile.html
18+
ebay.getUserDetails({ userId: "ajaykumapratha_0", details: true }).then((data) => {
19+
console.log(data);
20+
}, (error) => {
21+
console.log(error);
22+
});
23+
24+
25+
// Get Item Status
26+
// https://developer.ebay.com/devzone/shopping/docs/callref/GetItemStatus.html
27+
ebay.getItemStatus(["153265274986", "153265274986"]).then((data) => {
28+
console.log(data);
29+
}, (error) => {
30+
console.log(error);
31+
});
32+
33+
// https://developer.ebay.com/devzone/shopping/docs/callref/GetShippingCosts.html
34+
ebay.getShippingCosts({
35+
itemId: "153265274986", destCountryCode: 'US',
36+
destPostalCode: '95128'
37+
}).then((data) => {
38+
console.log(data);
39+
}, (error) => {
40+
console.log(error);
41+
});

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"devDependencies": {
2828
"chai": "^4.1.2",
2929
"eslint": "^5.8.0",
30-
"make-string": "^1.0.2",
3130
"mocha": "^5.0.1",
3231
"nock": "^9.2.3",
3332
"sinon": "^4.4.5"

src/buildURL.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
/**
23
* This method is used to build the url based on
34
* the type of request.
@@ -13,15 +14,14 @@ const buildURL = {
1314
* @private
1415
*/
1516
buildSearchUrl(options) {
16-
console.log(options);
1717
let base_url = `http://${options.baseSvcUrl}/services/search/FindingService/v1?`;
1818
base_url += "SECURITY-APPNAME=" + options.clientID;
1919
base_url += "&OPERATION-NAME=" + options.operationName;
2020
base_url += "&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON";
2121
base_url += options.param ? "&" + options.param + "=" + options.name : '';
2222
base_url += options.limit ? "&paginationInput.entriesPerPage=" + options.limit : '';
2323
base_url += options.globalID ? "&GLOBAL-ID=" + options.globalID : '';
24-
base_url += options.pageNumber ? "&paginationInput.pageNumber=" + options.pageNumber: '';
24+
base_url += options.pageNumber ? "&paginationInput.pageNumber=" + options.pageNumber : '';
2525

2626
return base_url;
2727
},
@@ -34,7 +34,7 @@ const buildURL = {
3434
* @private
3535
*/
3636
buildShoppingUrl(options) {
37-
let base_url = `http://${options.baseUrl}/Shopping?`;
37+
let base_url = `https://${options.baseUrl}/Shopping?`;
3838
base_url += "appid=" + options.clientID;
3939
base_url += "&callname=" + options.operationName;
4040
base_url += "&version=967&siteid=0&responseencoding=JSON&";

src/buy-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
'use strict';
22
const makeString = require('make-string');
33
const { makeRequest } = require('./request');
44

src/index.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
//let baseURL = "http://svcs.ebay.com/services/search/FindingService/v1";
1+
'use strict';
22
const { getRequest, makeRequest, base64Encode } = require('./request');
33
const { getItem,
44
getItemByLegacyId,
55
getItemByItemGroup,
66
searchItems } = require('./buy-api');
7+
const { getAllCategories,
8+
getShippingCosts,
9+
getItemStatus,
10+
getUserDetails } = require('./shopping');
711
const { getDefaultCategoryTreeId,
812
getCategoryTree,
913
getCategorySubtree,
@@ -60,40 +64,15 @@ Ebay.prototype = {
6064
)
6165
},
6266

63-
getAllCategories: function (categoryID) {
64-
this.options.name = categoryID ? categoryID : -1;
65-
this.options.operationName = "GetCategoryInfo";
66-
this.options.param = "CategoryID";
67-
const url = urlObject.buildShoppingUrl(this.options);
68-
return getRequest(url).then((data) => {
69-
return JSON.parse(data);
70-
}, console.error
71-
)
72-
},
73-
7467
getVersion: function () {
7568
this.options.operationName = "getVersion";
7669
const url = urlObject.buildSearchUrl(this.options);
77-
console.log(url);
7870
return getRequest(url).then((data) => {
7971
return JSON.parse(data)["getVersionResponse"][0];
8072
}, console.error
8173
)
8274
},
8375

84-
getUserDetails: function (userID) {
85-
if (!userID) throw new Error("User ID is null or invalid");
86-
this.options.operationName = "GetUserProfile";
87-
this.options.param = "UserID";
88-
this.options.name = userID;
89-
this.options.includeSelector = this.options.details ? "Details" : null;
90-
const url = urlObject.buildShoppingUrl(this.options);
91-
return getRequest(url).then((data) => {
92-
return JSON.parse(data);
93-
}, console.error
94-
)
95-
},
96-
9776
setAccessToken: function (token) {
9877
this.options.access_token = token;
9978
},
@@ -121,7 +100,11 @@ Ebay.prototype = {
121100
getCategorySuggestions,
122101
getItemAspectsForCategory,
123102
getMostWatchedItems,
124-
getSimilarItems
103+
getSimilarItems,
104+
getAllCategories,
105+
getShippingCosts,
106+
getItemStatus,
107+
getUserDetails
125108
};
126109

127110
module.exports = Ebay;

src/request.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
let httpRequest = require("https");
23
const qs = require("querystring");
34

0 commit comments

Comments
 (0)