Comparing version 1.2.1 to 1.3.0
@@ -32,3 +32,3 @@ /** | ||
params: params, | ||
parser: ebay.parseResponse // (default) | ||
parser: ebay.parseResponseJson // (default) | ||
}, | ||
@@ -35,0 +35,0 @@ // gets all the items together in a merged array |
@@ -38,3 +38,3 @@ // example paginated request to FindingService:findItemsAdvanced | ||
perPage: 3, // max 100x100 (10k items) | ||
parser: ebay.parseResponse | ||
parser: ebay.parseResponseJson | ||
}, | ||
@@ -41,0 +41,0 @@ // gets all the items together in a merged array |
@@ -8,4 +8,5 @@ // eBay API client for Node.js | ||
require('./lib/pagination'), | ||
require('./lib/parser'), | ||
require('./lib/xml-converter'), | ||
require('./lib/json-parser'), | ||
require('./lib/errors') | ||
); | ||
); |
@@ -69,2 +69,2 @@ var | ||
} | ||
}; | ||
}; |
@@ -7,2 +7,4 @@ /** | ||
var inherits = require('util').inherits; | ||
exports.EbayClientError = function EbayClientError(message) { | ||
@@ -13,2 +15,3 @@ Error.captureStackTrace(this, this.constructor); | ||
}; | ||
inherits(exports.EbayClientError, Error); | ||
@@ -20,2 +23,3 @@ exports.EbaySystemError = function EbaySystemError(message) { | ||
}; | ||
inherits(exports.EbaySystemError, Error); | ||
@@ -27,1 +31,2 @@ exports.EbayRequestError = function EbayRequestError(message) { | ||
}; | ||
inherits(exports.EbayRequestError, Error); |
@@ -5,3 +5,3 @@ var | ||
//getRequest = require('./get-request').getRequest, | ||
parseResponse = require('./parser').parseResponse; | ||
parseResponseJson = require('./json-parser').parseResponseJson; | ||
@@ -21,3 +21,3 @@ | ||
//options.perPage = options.perPage || 10; | ||
//options.parser = options.parser || parseResponse; | ||
//options.parser = options.parser || parseResponseJson; | ||
// | ||
@@ -79,2 +79,2 @@ //debug('Paginated request to', options.serviceName, 'for', options.pages, 'pages of', options.perPage, 'items each'); | ||
//); //forEach | ||
}; | ||
}; |
@@ -17,2 +17,4 @@ var | ||
// note: sandboxes do not all support SSL. | ||
switch (serviceName) { | ||
@@ -19,0 +21,0 @@ case 'Finding': |
var | ||
_ = require('lodash'), | ||
debug = require('debug')('ebay:request'), | ||
timer = require('debug')('ebay:timer'), | ||
request = require('request'), | ||
@@ -8,14 +9,10 @@ util = require('util'), | ||
xmlBuilder = require('xml'), | ||
xml2js = require('xml2js'), | ||
buildRequestUrl = require('./urls').buildRequestUrl, | ||
getDefaultHeaders = require('./defaults').getDefaultHeaders, | ||
defaultParser = require('./parser').parseResponse, | ||
convertXmlToJson = require('./xml-converter').convertXmlToJson, | ||
parseResponseJson = require('./json-parser').parseResponseJson, | ||
deepToArray = require('./deep-to-array').deepToArray, | ||
EbayClientError = require('./errors').EbayClientError; | ||
_errors = require('./errors'), | ||
EbaySystemError = _errors.EbaySystemError, | ||
EbayRequestError = _errors.EbayRequestError, | ||
EbayClientError = _errors.EbayClientError; | ||
/* | ||
@@ -83,2 +80,4 @@ build XML input for XML requests (POST). | ||
exports.xmlRequest = function(options, callback) { | ||
var _startTime = Date.now(); | ||
debug('XML request', options); | ||
@@ -90,2 +89,5 @@ options = options || {}; | ||
options.xmlConverter = options.xmlConverter || convertXmlToJson; | ||
options.parser = options.parser || parseResponseJson; | ||
options.reqOptions = options.reqOptions || {}; | ||
@@ -101,8 +103,8 @@ options.reqOptions.headers = options.reqOptions.headers || {}; | ||
debug('XML request options', reqOptions); | ||
timer('time to initiate request', Date.now() - _startTime); | ||
options.parser = options.parser || defaultParser; | ||
request.post(reqOptions, function(error, response) { | ||
debug('response', error ? {error: error} : {statusCode: response.statusCode, body: response.body}); | ||
timer('time to response', Date.now() - _startTime); | ||
@@ -130,9 +132,6 @@ if (error) { | ||
function _toJson(next) { | ||
var xmlParser = new xml2js.Parser(); | ||
xmlParser.parseString(response.body, function(error, data) { | ||
if (error) { | ||
debug(error); | ||
return next(new EbayClientError("Error parsing XML: " + error.message)); | ||
} | ||
options.xmlConverter(response.body, options, function(error, data) { | ||
if (error) return next(error); | ||
debug('Parsed XML', data); | ||
timer('time to parsed XML', Date.now() - _startTime); | ||
next(null, data); | ||
@@ -149,2 +148,4 @@ }); | ||
function _done(error, data) { | ||
timer('time to parsed JSON', Date.now() - _startTime); | ||
if (error) { | ||
@@ -166,2 +167,2 @@ if (/Ebay/i.test(error.name)) { | ||
}); | ||
}; | ||
}; |
{ | ||
"name": "ebay-api", | ||
"description": "eBay API Client", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"homepage": "https://github.com/newleafdigital/nodejs-ebay-api", | ||
@@ -6,0 +6,0 @@ "author": "Ben Buckman <ben@newleafdigital.com> (http://newleafdigital.com)", |
@@ -66,3 +66,6 @@ eBay API client for Node.js | ||
e.g. for additional `headers`, or `timeout`. | ||
- `parser`: function which takes the response data and extracts items (or other units depending on the query). | ||
- `xmlConverter`: function which takes the response XML and converts to JSON. | ||
_Module uses [xml2js](https://www.npmjs.com/package/xml2js) by default, but can be overridden._ | ||
- `parser`: function which takes the response data (as JSON object) and extracts items | ||
(or other units depending on the query). | ||
_Module includes a default parser._ | ||
@@ -118,2 +121,12 @@ - `sandbox`: boolean (default false = production). May need to add additional endpoint URLs to the code as needed. | ||
### `parseResponseJson(data, options, callback)` | ||
The default parser. Can be overridden (see `options` on `xmlRequest()`). | ||
### `convertXmlToJson(xmlBody, options, callback)` | ||
The default XML->JS converter. Uses xml2js. Can be overridden (see `options` on `xmlRequest()`). | ||
### `getLatestApiVersions(callback)` | ||
@@ -120,0 +133,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51259
25
1240
166