-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ajay2507/view-item-search
merging branch Browse Api call
- Loading branch information
Showing
5 changed files
with
132 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
npm-debug.log | ||
npm-debug.log | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
let { getRequest, makeRequest, base64Encode } = require('./request'); | ||
|
||
const getItem = function (itemId) { | ||
if (!itemId) throw new Error("Item Id is required"); | ||
if (!this.options.access_token) throw new Error("Missing Access token, Generate access token"); | ||
const auth = "Bearer " + this.options.access_token; | ||
const id = encodeURIComponent(itemId); | ||
return makeRequest('api.ebay.com', `/buy/browse/v1/item/${id}`, 'GET', this.options.body, auth).then((result) => { | ||
console.log("Success"); | ||
let resultJSON = JSON.parse(result); | ||
//this.setAccessToken(resultJSON); | ||
return resultJSON; | ||
}); | ||
}; | ||
|
||
const getItemByLegacyId = function (legacyOptions) { | ||
console.log(legacyOptions); | ||
if (!legacyOptions) throw new Error("Error Required input to get Items By LegacyID"); | ||
if (!this.options.access_token) throw new Error("Missing Access token, Generate access token"); | ||
if (!legacyOptions.legacyItemId) throw new Error("Error Legacy Item Id is required"); | ||
const auth = "Bearer " + this.options.access_token; | ||
let param = "legacy_item_id=" + legacyOptions.legacyItemId; | ||
param += legacyOptions.legacyVariationSku ? "&legacy_variation_sku=" + legacyOptions.legacyVariationSku : ''; | ||
|
||
return new promise | ||
|
||
makeRequest('api.ebay.com', `/buy/browse/v1/item/get_item_by_legacy_id?${param}`, 'GET', this.options.body, auth).then((result) => { | ||
let resultJSON = JSON.parse(result); | ||
//this.setAccessToken(resultJSON); | ||
return resultJSON; | ||
}).then((error) => { | ||
console.log(error.errors); | ||
console.log("Error Occurred ===> " + error.errors[0].message); | ||
}); | ||
}; | ||
|
||
const getItemByItemGroup = function (itemGroupId) { | ||
if (typeof itemGroupId == "object") throw new Error("Expecting String or number (Item group id)"); | ||
if (!itemGroupId) throw new Error("Error Item Group ID is required"); | ||
if (!this.options.access_token) throw new Error("Missing Access token, Generate access token"); | ||
const auth = "Bearer " + this.options.access_token; | ||
return new Promise((resolve, reject) => { | ||
makeRequest('api.ebay.com', `/buy/browse/v1/item/get_items_by_item_group?item_group_id=${itemGroupId}`, 'GET', this.options.body, auth).then((result) => { | ||
resolve(JSON.parse(result)); | ||
}); | ||
}) | ||
}; | ||
|
||
const searchItems = function (searchConfig) { | ||
if (!searchConfig) throw new Error("Error --> Missing or invalid input parameter to search"); | ||
if (!searchConfig.keyword || !searchConfig.categoryId) throw new Error("Error --> Keyword or category id is required in query param"); | ||
if (!this.options.access_token) throw new Error("Error -->Missing Access token, Generate access token"); | ||
if (searchConfig.fieldgroups.length > 0 && !Array.isArray(searchConfig.fieldgroups)) throw new Error("Error -->Field groups should be an array"); | ||
const auth = "Bearer " + this.options.access_token; | ||
let queryParam = searchConfig.keyword ? "q=" + searchConfig.keyword + "&" : ""; | ||
queryParam = queryParam + searchConfig.categoryId ? "category_ids=" + searchConfig.categoryId + "&" : ''; | ||
queryParam = queryParam + searchConfig.limit ? "limit=" + searchConfig.limit + "&" : ""; | ||
queryParam = queryParam + searchConfig.fieldgroups.length > 0 ? "fieldgroups=" + searchConfig.fieldgroups.toString() + "&" : ""; | ||
return new Promise((resolve, reject) => { | ||
makeRequest('api.ebay.com', `buy/browse/v1/item_summary/search?${queryparam}`, 'GET', this.options.body, auth).then((result) => { | ||
resolve(JSON.parse(result)); | ||
}); | ||
}) | ||
}; | ||
|
||
module.exports = { | ||
getItem, | ||
getItemByLegacyId, | ||
getItemByItemGroup, | ||
searchItems | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters