Skip to content

Commit

Permalink
Added filtering to findItemsByCategory api (#104)
Browse files Browse the repository at this point in the history
* v2.7.7

* fix encodeURI issue

* version bump

* added filtering for findItemsByCategory api

* version bump

* version bump
  • Loading branch information
pajaydev authored Jun 7, 2020
1 parent 8fd0bb5 commit ffa4bf3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ ebay.getAccessToken()
// To check the format of Data, Go to this url (https://developer.ebay.com/api- docs/buy/browse/resources/item_summary/methods/search#w4-w1-w4-SearchforItemsbyKeyword-0)
})
});

// perform Advance Search Items by Keyword or category or both
// Search Buy It Now ipad items with one day shipping. (https://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html)
ebay.findItemsAdvanced({
entriesPerPage: 2,
keywords: 'ipad',
ExpeditedShippingType: 'OneDayShipping',
ListingType: 'AuctionWithBIN'
}).then((data) => {
console.log(data);
}, (error) => {
console.log(error);
});
```

[More Examples](https://pajaydev.github.io/ebay-node-api)
Expand Down
5 changes: 4 additions & 1 deletion demo/finding.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ let ebay = new Ebay({
clientID: clientId,
});

ebay.findItemsByCategory(10181).then((data) => {
ebay.findItemsByCategory({
categoryId: 10181,
Condition: 1000
}).then((data) => {
console.log(data);
}, (error) => {
console.log(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.8.6",
"version": "2.8.7",
"description": "Ebay node api client",
"main": "./src/index.js",
"homepage": "https://github.com/pajaydev/ebay-node-api",
Expand Down
3 changes: 1 addition & 2 deletions src/buildURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const buildURL = {
baseUrl += options.param ? '&' + options.param + '=' + options.name : '';
baseUrl += options.additionalParam ? '&' + options.additionalParam : '';
baseUrl += options.sortOrder ? '&sortOrder=' + options.sortOrder : '';
baseUrl += '&outputSelector(0)=SellerInfo';
baseUrl += '&outputSelector(1)=PictureURLLarge';
baseUrl += '&outputSelector(0)=SellerInfo&outputSelector(1)=PictureURLLarge';
baseUrl += options.limit ? '&paginationInput.entriesPerPage=' + options.limit : '';
baseUrl += options.globalID ? '&GLOBAL-ID=' + options.globalID : '';
baseUrl += options.pageNumber ? '&paginationInput.pageNumber=' + options.pageNumber : '';
Expand Down
19 changes: 9 additions & 10 deletions src/finding.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const FIND_ITEMS_ADV = 'findItemsAdvanced';
const FIND_EBAY_STORES = 'findItemsIneBayStores';

const findItemsByKeywords = function (options) {
if (!options) {
throw new Error('INVALID_REQUEST_PARMS --> Keyword is missing, Keyword is required');
}
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Keyword is missing, Keyword is required');
this.options.operationName = FIND_ITEMS_BY_KEYWORD;
// support only keyword string.
if (!options.keywords) options = { keywords: options };
Expand All @@ -24,11 +22,15 @@ 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;
/**
* searches for items on eBay using specific eBay category ID numbers (input category ID numbers using categoryId).
* @param {Object} options
*/
const findItemsByCategory = function (options) {
if (!options) throw new Error('INVALID_REQUEST_PARMS --> Category ID is null or invalid');
if (!options.categoryId) options = { categoryId: options };
this.options.operationName = FIND_ITEMS_BY_CATEGORY;
this.options.param = 'categoryId';
this.options.additionalParam = utils.constructAdditionalParams(options);
const url = urlObject.buildSearchUrl(this.options);
return getRequest(url).then((data) => {
return JSON.parse(data).findItemsByCategoryResponse;
Expand All @@ -49,7 +51,6 @@ const findCompletedItems = function (options) {
const url = urlObject.buildSearchUrl(this.options);
return getRequest(url).then((data) => {
return JSON.parse(data).findCompletedItemsResponse;

}, console.error // eslint-disable-line no-console
);
};
Expand Down Expand Up @@ -94,7 +95,6 @@ const findItemsByProduct = function (options) {
let url = `${urlObject.buildSearchUrl(this.options)}&productId.@type=${type}`;
return getRequest(url).then((data) => {
return JSON.parse(data).findItemsByProductResponse;

}, console.error // eslint-disable-line no-console
);
};
Expand All @@ -106,7 +106,6 @@ const findItemsIneBayStores = function (options) {
this.options.additionalParam = utils.constructAdditionalParams(options);
return getRequest(urlObject.buildSearchUrl(this.options)).then((data) => {
return JSON.parse(data).findItemsIneBayStoresResponse;

}, console.error // eslint-disable-line no-console
);
};
Expand Down

0 comments on commit ffa4bf3

Please sign in to comment.