Socket
Socket
Sign inDemoInstall

ebay-api

Package Overview
Dependencies
3
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

examples/GetSingleItem.js

71

index.js

@@ -78,8 +78,14 @@ // eBay API client for Node.js

if (serviceName === 'FindingService') {
url = "https://svcs.ebay.com/services/search/" + serviceName + "/v1?";
switch (serviceName) {
case 'FindingService':
url = "https://svcs.ebay.com/services/search/" + serviceName + "/v1?";
break;
case 'Shopping':
url = "http://open.api.ebay.com/shopping?";
break;
default:
url = "https://svcs.ebay.com/" + serviceName + '?';
}
else {
url = "https://svcs.ebay.com/" + serviceName + '?';
}

@@ -122,2 +128,12 @@ url += buildParams(params); // no trailing &

break;
case 'Shopping':
_.extend(params, {
'appid': appId,
'version': '771',
'siteid': '0',
'responseencoding': 'JSON',
'callname': opType
});
break;
}

@@ -167,8 +183,10 @@

// reduce
var responseKey = options.opType + 'Response';
if (_.isUndefined(data[responseKey])) {
return callback(new Error("Response missing " + responseKey + " element"));
// drill down to item(s). each service has its own structure.
if (options.serviceName !== 'Shopping') {
var responseKey = options.opType + 'Response';
if (_.isUndefined(data[responseKey])) {
return callback(new Error("Response missing " + responseKey + " element"));
}
data = data[responseKey];
}
data = data[responseKey];

@@ -182,3 +200,7 @@ if (_.isArray(data)) {

if (!_.isUndefined(data.ack)) data.ack = flatten(data.ack);
else if (!_.isUndefined(data.Ack)) { // uppercase, standardize.
data.ack = flatten(data.Ack);
delete data.Ack;
}
if (_.isUndefined(data.ack) || data.ack !== 'Success') {

@@ -372,10 +394,24 @@ var errMsg = _.isUndefined(data.errorMessage) ? null : flatten(data.errorMessage);

try {
if (data.searchResult) {
// reduce in steps so successful but empty responses don't throw error
data = !_.isEmpty(data.searchResult) ? _(data.searchResult).first() : null;
items = (data && data.item) || []; // e.g. for FindingService
if (typeof data.Item !== 'undefined') { // e.g. for Shopping::GetSingleItem
items = [ data.Item ]; // preserve array for standardization (?)
}
else if (data.itemRecommendations.item) {
items = data.itemRecommendations.item || []; // e.g. for getMostWatched
else if (typeof data.searchResult !== 'undefined') { // e.g. for FindingService
// reduce in steps so successful-but-empty responses don't throw error
if (!_.isEmpty(data.searchResult)) {
data = _(data.searchResult).first();
if (typeof data !== 'undefined') {
if (typeof data.item !== 'undefined') {
items = data.item;
}
}
}
}
else if (typeof data.itemRecommendations !== 'undefined') {
if (typeof data.itemRecommendations !== 'undefined') {
if (typeof data.itemRecommendations.item !== 'undefined') {
items = _.isArray(data.itemRecommendations.item) ? data.itemRecommendations.item : [];
}
}
}

@@ -390,2 +426,3 @@ // recursively flatten 1-level arrays and "@key:__VALUE__" pairs

}
callback(null, items);

@@ -392,0 +429,0 @@ };

{
"name": "ebay-api",
"description": "eBay API Client",
"version": "0.0.3",
"version": "0.0.4",
"homepage": "https://github.com/newleafdigital/nodejs-ebay-api",

@@ -6,0 +6,0 @@ "author": "Ben Buckman <ben@newleafdigital.com> (http://newleafdigital.com)",

@@ -6,3 +6,3 @@ eBay API client for Node.js

This was built to power the "eBay Picks" section of [AntiquesNearMe.com](http://antiquesnearme.com). It can currently query the FindingService and MerchandisingService via GET requests, and other services can be added as needed. (Pull requests welcome!)
This was built to power the "eBay Picks" section of [AntiquesNearMe.com](http://antiquesnearme.com). It can currently query the FindingService, MerchandisingService, and Shopping API via GET requests, and other services can be added as needed. (Pull requests welcome!)

@@ -9,0 +9,0 @@ ## To use

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc