Skip to content

Commit

Permalink
Merge pull request #27 from bhushankumarl/development
Browse files Browse the repository at this point in the history
Add basic Test cases, Add jshint lint checking, Code Reformatting
  • Loading branch information
Bhushankumar L authored Jul 24, 2018
2 parents dc6637d + c0908c4 commit 19bbfc6
Show file tree
Hide file tree
Showing 40 changed files with 854 additions and 192 deletions.
3 changes: 3 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
examples/typeScript
test/
12 changes: 10 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
"exports": true,
"module": true,
"Buffer": true,
"JSON": true
"JSON": true,
"async": true,
/* MOCHA */
"describe": false,
"it": false,
"before": false,
"beforeEach": false,
"after": false,
"afterEach": false
},
"maxparams": 6,
"maxdepth": 15,
Expand Down Expand Up @@ -40,7 +48,7 @@
"smarttabs": true,
"indent": 2,
"latedef": "nofunc",
"unused": false,
"unused": true,
"enforceall": true,
"-W024": true,
"-W089": false,
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "0.12"
- "4"
- "5"
- "6"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0.0.18
- Add basic Test cases
- Add jshint lint checking
- Code Reformatting
- Add support for parsing special characters
- Add support for API which return data as binary file format
- Extend support for GetLowestPricedOffersForASIN, GetLowestPricedOffersForSKU and other product methods
- Added test cases for Feeds, Finances, Fulfillment Inventory, Fulfillment Outbound Shipment, Fulfillment Inbound Shipment, Products, Orders, Sellers

0.0.17
- Extend support for TypeScript typed definition : feeds, finances, fulfillmentInboundShipment, fulfillmentInventory, fulfillmentOutboundShipment, merchantFulfillment, orders, products, sellers

Expand Down
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ You can find [examples here](https://github.com/bhushankumarl/amazon-mws/tree/ma
$ npm install amazon-mws --save
```

## Test Cases
```bash
$ npm run test.mocha
```

## Debugging

Run the DEBUG:
Expand All @@ -31,14 +36,24 @@ export AWS_ACCESS_KEY_ID=KEY
export AWS_SECRET_ACCESS_KEY=SECRET
```

## Configuration
## Configuration Using JavaScript

Set your Access Key and Access Secret.

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

## Configuration Using TypeScript

```
import * as MwsApi from 'amazon-mws';
const amazonMws = new MwsApi();
amazonMws.setApiKey(accessKey, accessSecret);
```


### Feeds

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

### Products

#### Get Lowest Priced Offers For ASIN
```js
amazonMws.products.searchFor({
'Version': '2011-10-01',
'Action': 'GetLowestPricedOffersForASIN',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'MarketplaceId': 'MARKET_PLACE_ID',
'ASIN': 'ASIN',
'ItemCondition': 'New'
}, function (error, response) {
if (error) {
console.log('error products', error);
return;
}
console.log('response ', response);
});
```

#### Get Lowest Priced Offers For SKU
```js
amazonMws.products.searchFor({
'Version': '2011-10-01',
'Action': 'GetLowestPricedOffersForSKU',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'MarketplaceId': 'MARKET_PLACE_ID',
'SellerSKU': 'SELLER_SKU',
'ItemCondition': 'New'
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response ', response);
});
```

#### List Matching Products
```js
amazonMws.products.search({
Expand Down Expand Up @@ -438,6 +491,7 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY

#### Get Report
###### This will provide you JSON report/data.
###### This will not provide you Throttling details in Header.
```js
amazonMws.reports.search({
'Version': '2009-01-01',
Expand Down Expand Up @@ -479,6 +533,31 @@ var amazonMws = require('amazon-mws')('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY
});
```

#### Get Report
###### Using TypeScript.
```
const accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
const accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';
import * as MwsApi from 'amazon-mws';
const amazonMws = new MwsApi();
amazonMws.setApiKey(accessKey, accessSecret);
try {
const response: any = await amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReport',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ReportId': 'REPORT_ID'
});
console.log('response', response);
} catch (error: any) {
console.log('error ', error);
}
```

#### Additionally all api returns Throttling: Limits to how often you can submit requests
Reference : http://docs.developer.amazonservices.com/en_CA/dev_guide/DG_Throttling.html
```json
Expand Down
2 changes: 1 addition & 1 deletion examples/javaScript/feeds/file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amznenvelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>AUV38W4NKU8JH</MerchantIdentifier>
<MerchantIdentifier>XXXXXXXXXXXXXXX</MerchantIdentifier>
</Header>
<MessageType>Inventory</MessageType>
<Message>
Expand Down
33 changes: 33 additions & 0 deletions examples/javaScript/feeds/getFeedSubmissionResultRaw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
var fs = require('fs');

var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';

var amazonMws = require('../../../lib/amazon-mws')(accessKey, accessSecret);
var fse = require('fs-extra');

/**
* Use __RAW__ to get the raw response in response->data;
* This along with __CHARSET__ do not get written in the request.
* */
function feedRequest() {
var FeedSubmissionId = '10101010XXX';
amazonMws.feeds.search({
'Version': '2009-01-01',
'Action': 'GetFeedSubmissionResult',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'FeedSubmissionId': FeedSubmissionId,
__RAW__: true
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
fse.writeFileSync('response.txt', response.data);
console.log('Headers', response.Headers);
});
}

feedRequest();
26 changes: 26 additions & 0 deletions examples/javaScript/products/getLowestPricedOffersForASIN.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';

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

var productRequest = function () {
amazonMws.products.searchFor({
'Version': '2011-10-01',
'Action': 'GetLowestPricedOffersForASIN',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'MarketplaceId': 'MARKET_PLACE_ID',
'ASIN': 'ASIN',
'ItemCondition': 'New'
}, function (error, response) {
if (error) {
console.log('error products', error);
return;
}
console.log('response ', response);
});
};

productRequest();
26 changes: 26 additions & 0 deletions examples/javaScript/products/getLowestPricedOffersForSKU.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var accessKey = process.env.AWS_ACCESS_KEY_ID || 'YOUR_KEY';
var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';

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

var productRequest = function () {
amazonMws.products.searchFor({
'Version': '2011-10-01',
'Action': 'GetLowestPricedOffersForSKU',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'MarketplaceId': 'MARKET_PLACE_ID',
'SellerSKU': 'SELLER_SKU',
'ItemCondition': 'New'
}, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response ', response);
});
};

productRequest();
7 changes: 6 additions & 1 deletion examples/javaScript/reports/getReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ var accessSecret = process.env.AWS_SECRET_ACCESS_KEY || 'YOUR_SECRET';

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

/**
* This will not provide you Throttling details in Header.
* Amazon MWS itself not providing Throttling detail in GetReport call.
*/

var reportRequest = function () {
amazonMws.reports.search({
'Version': '2009-01-01',
'Action': 'GetReport',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'ReportId':'REPORT_ID'
'ReportId': 'REPORT_ID'
}, function (error, response) {
if (error) {
console.log('error ', error);
Expand Down
2 changes: 1 addition & 1 deletion examples/javaScript/reports/getReportList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var reportRequest = function () {
'Version': '2009-01-01',
'Action': 'GetReportList',
'SellerId': 'SELLER_ID',
'MWSAuthToken': 'MWS_AUTH_TOKEN',
'MWSAuthToken': 'MWS_AUTH_TOKEN'
//'ReportTypeList.Type.1': 'REPORT_TYPE_LIST' //optional
}, function (error, response) {
if (error) {
Expand Down
26 changes: 13 additions & 13 deletions examples/typeScript/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "trello-sample",
"version": "1.0.0",
"description": "trello",
"license": "MIT",
"dependencies": {
"@types/node": "^8.0.53",
"@types/es6-promise": "0.0.33",
"babel-eslint": "^8.0.1",
"babel-preset-node6": "^11.0.0",
"amazon-mws": "^0.0.16",
"node-expat": "^2.3.16"
},
"devDependencies": {}
"name": "amazon-mws-typescript-sample",
"version": "1.0.0",
"description": "trello",
"license": "MIT",
"dependencies": {
"@types/node": "^8.0.53",
"@types/es6-promise": "0.0.33",
"babel-eslint": "^8.0.1",
"babel-preset-node6": "^11.0.0",
"amazon-mws": "*",
"node-expat": "^2.3.16"
},
"devDependencies": {}
}
6 changes: 5 additions & 1 deletion examples/typeScript/reports/getReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import * as MwsApi from 'amazon-mws';
const amazonMws = new MwsApi();
amazonMws.setApiKey(accessKey, accessSecret);

/**
* This will not provide you Throttling details in Header.
* Amazon MWS itself not providing Throttling detail in GetReport call.
*/

const reportRequest = async () => {

try {
Expand All @@ -21,7 +26,6 @@ const reportRequest = async () => {
console.log('error ', error);
}


};

reportRequest();
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ declare class Orders extends BaseAmazonMWS {

declare class Products extends BaseAmazonMWS {

searchFor(params: any): Promise<any>;

}

declare class Reports extends BaseAmazonMWS {
Expand Down
Loading

0 comments on commit 19bbfc6

Please sign in to comment.