Skip to content

Commit 19bbfc6

Browse files
author
Bhushankumar L
authored
Merge pull request #27 from bhushankumarl/development
Add basic Test cases, Add jshint lint checking, Code Reformatting
2 parents dc6637d + c0908c4 commit 19bbfc6

40 files changed

+854
-192
lines changed

.jshintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
examples/typeScript
3+
test/

.jshintrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
"exports": true,
77
"module": true,
88
"Buffer": true,
9-
"JSON": true
9+
"JSON": true,
10+
"async": true,
11+
/* MOCHA */
12+
"describe": false,
13+
"it": false,
14+
"before": false,
15+
"beforeEach": false,
16+
"after": false,
17+
"afterEach": false
1018
},
1119
"maxparams": 6,
1220
"maxdepth": 15,
@@ -40,7 +48,7 @@
4048
"smarttabs": true,
4149
"indent": 2,
4250
"latedef": "nofunc",
43-
"unused": false,
51+
"unused": true,
4452
"enforceall": true,
4553
"-W024": true,
4654
"-W089": false,

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3-
- "0.12"
43
- "4"
54
- "5"
65
- "6"

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
0.0.18
2+
- Add basic Test cases
3+
- Add jshint lint checking
4+
- Code Reformatting
5+
- Add support for parsing special characters
6+
- Add support for API which return data as binary file format
7+
- Extend support for GetLowestPricedOffersForASIN, GetLowestPricedOffersForSKU and other product methods
8+
- Added test cases for Feeds, Finances, Fulfillment Inventory, Fulfillment Outbound Shipment, Fulfillment Inbound Shipment, Products, Orders, Sellers
9+
110
0.0.17
211
- Extend support for TypeScript typed definition : feeds, finances, fulfillmentInboundShipment, fulfillmentInventory, fulfillmentOutboundShipment, merchantFulfillment, orders, products, sellers
312

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ You can find [examples here](https://github.com/bhushankumarl/amazon-mws/tree/ma
1515
$ npm install amazon-mws --save
1616
```
1717

18+
## Test Cases
19+
```bash
20+
$ npm run test.mocha
21+
```
22+
1823
## Debugging
1924

2025
Run the DEBUG:
@@ -31,14 +36,24 @@ export AWS_ACCESS_KEY_ID=KEY
3136
export AWS_SECRET_ACCESS_KEY=SECRET
3237
```
3338

34-
## Configuration
39+
## Configuration Using JavaScript
3540

3641
Set your Access Key and Access Secret.
3742

3843
```js
3944
var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY');
4045
```
4146

47+
## Configuration Using TypeScript
48+
49+
```
50+
import * as MwsApi from 'amazon-mws';
51+
52+
const amazonMws = new MwsApi();
53+
amazonMws.setApiKey(accessKey, accessSecret);
54+
```
55+
56+
4257
### Feeds
4358

4459
#### Submit Feed
@@ -346,6 +361,44 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
346361

347362
### Products
348363

364+
#### Get Lowest Priced Offers For ASIN
365+
```js
366+
amazonMws.products.searchFor({
367+
'Version': '2011-10-01',
368+
'Action': 'GetLowestPricedOffersForASIN',
369+
'SellerId': 'SELLER_ID',
370+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
371+
'MarketplaceId': 'MARKET_PLACE_ID',
372+
'ASIN': 'ASIN',
373+
'ItemCondition': 'New'
374+
}, function (error, response) {
375+
if (error) {
376+
console.log('error products', error);
377+
return;
378+
}
379+
console.log('response ', response);
380+
});
381+
```
382+
383+
#### Get Lowest Priced Offers For SKU
384+
```js
385+
amazonMws.products.searchFor({
386+
'Version': '2011-10-01',
387+
'Action': 'GetLowestPricedOffersForSKU',
388+
'SellerId': 'SELLER_ID',
389+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
390+
'MarketplaceId': 'MARKET_PLACE_ID',
391+
'SellerSKU': 'SELLER_SKU',
392+
'ItemCondition': 'New'
393+
}, function (error, response) {
394+
if (error) {
395+
console.log('error ', error);
396+
return;
397+
}
398+
console.log('response ', response);
399+
});
400+
```
401+
349402
#### List Matching Products
350403
```js
351404
amazonMws.products.search({
@@ -438,6 +491,7 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
438491

439492
#### Get Report
440493
###### This will provide you JSON report/data.
494+
###### This will not provide you Throttling details in Header.
441495
```js
442496
amazonMws.reports.search({
443497
'Version': '2009-01-01',
@@ -479,6 +533,31 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
479533
});
480534
```
481535

536+
#### Get Report
537+
###### Using TypeScript.
538+
```
539+
const accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
540+
const accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
541+
542+
import * as MwsApi from 'amazon-mws';
543+
544+
const amazonMws = new MwsApi();
545+
amazonMws.setApiKey(accessKey, accessSecret);
546+
547+
try {
548+
const response: any = await amazonMws.reports.search({
549+
'Version': '2009-01-01',
550+
'Action': 'GetReport',
551+
'SellerId': 'SELLER_ID',
552+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
553+
'ReportId': 'REPORT_ID'
554+
});
555+
console.log('response', response);
556+
} catch (error: any) {
557+
console.log('error ', error);
558+
}
559+
```
560+
482561
#### Additionally all api returns Throttling: Limits to how often you can submit requests
483562
Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttling.html
484563
```json

examples/javaScript/feeds/file.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
33
<Header>
44
<DocumentVersion>1.01</DocumentVersion>
5-
<MerchantIdentifier>AUV38W4NKU8JH</MerchantIdentifier>
5+
<MerchantIdentifier>XXXXXXXXXXXXXXX</MerchantIdentifier>
66
</Header>
77
<MessageType>Inventory</MessageType>
88
<Message>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
var fs = require('fs');
3+
4+
var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
5+
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
6+
7+
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
8+
var fse = require('fs-extra');
9+
10+
/**
11+
* Use __RAW__ to get the raw response in response->data;
12+
* This along with __CHARSET__ do not get written in the request.
13+
* */
14+
function feedRequest() {
15+
var FeedSubmissionId = '10101010XXX';
16+
amazonMws.feeds.search({
17+
'Version': '2009-01-01',
18+
'Action': 'GetFeedSubmissionResult',
19+
'SellerId': 'SELLER_ID',
20+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
21+
'FeedSubmissionId': FeedSubmissionId,
22+
__RAW__: true
23+
}, function (error, response) {
24+
if (error) {
25+
console.log('error ', error);
26+
return;
27+
}
28+
fse.writeFileSync('response.txt', response.data);
29+
console.log('Headers', response.Headers);
30+
});
31+
}
32+
33+
feedRequest();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
4+
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
5+
6+
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
7+
8+
var productRequest = function () {
9+
amazonMws.products.searchFor({
10+
'Version': '2011-10-01',
11+
'Action': 'GetLowestPricedOffersForASIN',
12+
'SellerId': 'SELLER_ID',
13+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
14+
'MarketplaceId': 'MARKET_PLACE_ID',
15+
'ASIN': 'ASIN',
16+
'ItemCondition': 'New'
17+
}, function (error, response) {
18+
if (error) {
19+
console.log('error products', error);
20+
return;
21+
}
22+
console.log('response ', response);
23+
});
24+
};
25+
26+
productRequest();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
4+
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
5+
6+
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
7+
8+
var productRequest = function () {
9+
amazonMws.products.searchFor({
10+
'Version': '2011-10-01',
11+
'Action': 'GetLowestPricedOffersForSKU',
12+
'SellerId': 'SELLER_ID',
13+
'MWSAuthToken': 'MWS_AUTH_TOKEN',
14+
'MarketplaceId': 'MARKET_PLACE_ID',
15+
'SellerSKU': 'SELLER_SKU',
16+
'ItemCondition': 'New'
17+
}, function (error, response) {
18+
if (error) {
19+
console.log('error ', error);
20+
return;
21+
}
22+
console.log('response ', response);
23+
});
24+
};
25+
26+
productRequest();

examples/javaScript/reports/getReport.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
55

66
var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
77

8+
/**
9+
* This will not provide you Throttling details in Header.
10+
* Amazon MWS itself not providing Throttling detail in GetReport call.
11+
*/
12+
813
var reportRequest = function () {
914
amazonMws.reports.search({
1015
'Version': '2009-01-01',
1116
'Action': 'GetReport',
1217
'SellerId': 'SELLER_ID',
1318
'MWSAuthToken': 'MWS_AUTH_TOKEN',
14-
'ReportId':'REPORT_ID'
19+
'ReportId': 'REPORT_ID'
1520
}, function (error, response) {
1621
if (error) {
1722
console.log('error ', error);

0 commit comments

Comments
 (0)