Skip to content

Commit 2500bcf

Browse files
smulderpajaydev
authored andcommitted
Change Filters to String for buy-api search / add sorting / add gtin search (#19)
* change filter handling for buy-api search to simply use a string * clean some console.logs out * add sorting to buy-api query * Add gtin and sort as queryParams / allow gtin as top level search option
1 parent 59e5f9b commit 2500bcf

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Ebay API Client for node js.
55
The intent is to simplify the request process by handling the tedious logic. It's a thin wrapper around eBay Api.
66

77
[![npm version](https://badge.fury.io/js/ebay-node-api.svg)](https://badge.fury.io/js/ebay-node-api)
8-
[![Build Status](https://travis-ci.org/ajay2507/ebay-node-api.svg?branch=master)](https://travis-ci.org/ajay2507/ebay-node-api)
8+
[![Build Status](https://travis-ci.org/ajay2507/ebay-node-api.svg?branch=master)](https://travis-ci.org/ajay2507/ebay-node-api)
99

1010

1111
## Table of Contents
@@ -47,15 +47,15 @@ npm install ebay-node-api
4747
let eBay = require('ebay-node-api')
4848

4949
let ebay = new eBay({
50-
clientID: "-- Client APP ID ----",
50+
clientID: "-- Client APP ID ----",
5151
// options - optional HTTP request timeout to apply to all requests.
5252
})
5353
```
5454
Creates a new `Ebay` instance.
5555

5656
### Getting Client ID:
5757

58-
Join eBay developers program.
58+
Join eBay developers program.
5959
Register your app here https://go.developer.ebay.com/quick-start-guide.
6060

6161
#### Options
@@ -193,7 +193,8 @@ ebay.getAccessToken()
193193
ebay.searchItems({
194194
keyword: "drone",
195195
limit: 3,
196-
filter: { maxDeliveryCost: 0 }
196+
// filter: { maxDeliveryCost: 0 } old object based filter method
197+
filter: 'maxDeliveryCost:0' // new string based filter method. Format here: https://developer.ebay.com/api-docs/buy/static/ref-buy-browse-filters.html#conditionIds
197198
}).then((data) => {
198199
console.log(data);
199200
// Data is in format of JSON
@@ -209,7 +210,8 @@ ebay.getAccessToken()
209210
ebay.searchItems({
210211
keyword: "iphone",
211212
limit: 3,
212-
filter: { price: "[300..800]", priceCurrency: "USD", conditions: "NEW" }
213+
// filter: { price: "[300..800]", priceCurrency: "USD", conditions: "NEW" } old object based filter method
214+
filter: 'price:[300..800],priceCurrency:USD,conditions{NEW}' // new string based filter method. Format here: https://developer.ebay.com/api-docs/buy/static/ref-buy-browse-filters.html#conditionIds
213215
}).then((data) => {
214216
console.log(data);
215217
// Data is in format of JSON
@@ -265,5 +267,5 @@ Willing to share your idea or ready to contribute, check [here](https://github.c
265267
MIT.
266268

267269
## Examples:
268-
I have mentioned the examples here
270+
I have mentioned the examples here
269271
https://github.com/ajay2507/ebay-node-api/tree/master/demo.

src/buy-api.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ const getItemByItemGroup = function (itemGroupId) {
4343

4444
const searchItems = function (searchConfig) {
4545
if (!searchConfig) throw new Error("Error --> Missing or invalid input parameter to search");
46-
if (!searchConfig.keyword && !searchConfig.categoryId) throw new Error("Error --> Keyword or category id is required in query param");
46+
if (!searchConfig.keyword && !searchConfig.categoryId && !searchConfig.gtin) throw new Error("Error --> Keyword or category id is required in query param");
4747
if (!this.options.access_token) throw new Error("Error -->Missing Access token, Generate access token");
4848
const auth = "Bearer " + this.options.access_token;
4949
let queryParam = searchConfig.keyword ? "q=" + searchConfig.keyword : "";
50+
queryParam = queryParam + (searchConfig.gtin ? "&gtin=" + searchConfig.gtin : '');
5051
queryParam = queryParam + (searchConfig.categoryId ? "&category_ids=" + searchConfig.categoryId : '');
5152
queryParam = queryParam + (searchConfig.limit ? "&limit=" + searchConfig.limit : "");
53+
queryParam = queryParam + (searchConfig.sort ? "&sort=" + searchConfig.sort : "");
5254
if (searchConfig.fieldgroups != undefined) queryParam = queryParam + "&fieldgroups=" + searchConfig.fieldgroups.toString();
53-
if (searchConfig.filter != undefined) queryParam = queryParam + "&filter=" + JSON.stringify(searchConfig.filter).replace(/[{}]/g, "").replace(/[""]/g, "");
54-
console.log(queryParam);
55+
if (searchConfig.filter != undefined) queryParam = queryParam + "&filter=" + encodeURIComponent(searchConfig.filter);
56+
// console.log(queryParam);
5557
return new Promise((resolve, reject) => {
5658
makeRequest('api.ebay.com', `/buy/browse/v1/item_summary/search?${queryParam}`, 'GET', this.options.body, auth).then((result) => {
5759
resolve(result);

src/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let getRequest = function getRequest(url) {
2020

2121
let makeRequest = function postRequest(hostName, endpoint, methodName, data, token) {
2222
methodName == "POST" ? dataString = qs.stringify(data) : '';
23-
console.log(endpoint);
23+
// console.log(endpoint);
2424
const options = {
2525
"hostname": hostName,
2626
"path": endpoint,
@@ -57,4 +57,4 @@ let base64Encode = (encodeData) => {
5757
return buff.toString('base64');
5858
}
5959

60-
module.exports = { getRequest, makeRequest, base64Encode };
60+
module.exports = { getRequest, makeRequest, base64Encode };

0 commit comments

Comments
 (0)