Skip to content

Commit

Permalink
add support for both COMMA delimited csv files
Browse files Browse the repository at this point in the history
  • Loading branch information
BL committed May 10, 2018
1 parent 2e0cb73 commit 9791827
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
0.0.16
- Added example of MerchantFulfillment
- Added support for the comma delimiter report
- Added example of Comma delimiter report

0.0.15
- Bug fixed ResponseMetadata (RequestId) in success response
Expand Down
22 changes: 19 additions & 3 deletions lib/AmazonMwsResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ AmazonMwsResource.prototype = {
}
}

function parseCSVFile(res, responseString, callback) {
function parseCSVFile(res, responseString, delimiter, callback) {
var data = [];
csv.fromString(responseString, {headers: true, delimiter: '\t', ignoreEmpty: true})
csv.fromString(responseString, {headers: true, delimiter: delimiter, ignoreEmpty: true})
.on('data', function (value) {
data.push(value);
})
Expand Down Expand Up @@ -192,7 +192,23 @@ AmazonMwsResource.prototype = {
return callback(null, items);
} else {
debug('It is NON-XML Response');
parseCSVFile(res, responseString, callback);
var TAB_DELIMITER = '\t';
var COMMA_DELIMITER = ',';
try {
parseCSVFile(res, responseString, TAB_DELIMITER, callback);
} catch (Exception) {
debug('It is TAB_DELIMITER Exception ', Exception);
debug('Let us try to delimit using COMMA_DELIMITER');
try {
parseCSVFile(res, responseString, COMMA_DELIMITER, callback);
} catch (Exception) {
debug('It is COMMA_DELIMITER Exception ', Exception);
debug('Parsing using both TAB_DELIMITER & COMMA_DELIMITER Failed.');
debug('It may due to empty response or invalid request.');
return callback(new Error('Parsing fail.'));
}
}

}
}

Expand Down

0 comments on commit 9791827

Please sign in to comment.