This repository has been archived by the owner on Nov 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from bizon/tusbar/add-sellers-participations
Add sellers.listMarketplaceParticipations API
- Loading branch information
Showing
10 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...lib/client/parsers/sellers/__snapshots__/list-marketplace-participations-response.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`lib.client.parsers.sellers.list-marketplace-participations-response should parse the ListMarketplaceParticipationsByNextTokenResponse example response from MWS doc 1`] = ` | ||
Object { | ||
"listMarketplaceParticipationsResult": Object { | ||
"marketplaces": Array [ | ||
Object { | ||
"defaultCountryCode": "US", | ||
"defaultCurrencyCode": "USD", | ||
"defaultLanguageCode": "en_US", | ||
"domainName": "www.amazon.com", | ||
"marketplaceId": "ATVPDKIKX0DER", | ||
"name": "Amazon.com", | ||
}, | ||
], | ||
"nextToken": "MRgZW55IGNhcm5hbCBwbGVhc3VyZS6=", | ||
"participations": Array [ | ||
Object { | ||
"hasSellerSuspendedListings": false, | ||
"marketplaceId": "ATVPDKIKX0DER", | ||
"sellerId": "A135KKEKWF1JAI6", | ||
}, | ||
], | ||
}, | ||
"responseMetadata": Object { | ||
"requestId": "efeab958-74e2-45d4-9018-2323084413b5", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`lib.client.parsers.sellers.list-marketplace-participations-response should parse the ListMarketplaceParticipationsResponse example response from MWS doc 1`] = ` | ||
Object { | ||
"listMarketplaceParticipationsResult": Object { | ||
"marketplaces": Array [ | ||
Object { | ||
"defaultCountryCode": "US", | ||
"defaultCurrencyCode": "USD", | ||
"defaultLanguageCode": "en_US", | ||
"domainName": "www.amazon.com", | ||
"marketplaceId": "ATVPDKIKX0DER", | ||
"name": "Amazon.com", | ||
}, | ||
], | ||
"nextToken": "MRgZW55IGNhcm5hbCBwbGVhc3VyZS6=", | ||
"participations": Array [ | ||
Object { | ||
"hasSellerSuspendedListings": false, | ||
"marketplaceId": "ATVPDKIKX0DER", | ||
"sellerId": "A135KKEKJAIBJ56", | ||
}, | ||
], | ||
}, | ||
"responseMetadata": Object { | ||
"requestId": "efeab958-74e2-45d4-9018-2323084413b5", | ||
}, | ||
} | ||
`; |
81 changes: 81 additions & 0 deletions
81
__tests__/lib/client/parsers/sellers/list-marketplace-participations-response.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const parseXml = require('../../../../../lib/client/parsers') | ||
const parseListMarketplaceParticipationsResponse = require('../../../../../lib/client/parsers/sellers/list-marketplace-participations-response') | ||
|
||
describe('lib.client.parsers.sellers.list-marketplace-participations-response', () => { | ||
it('should parse the ListMarketplaceParticipationsResponse example response from MWS doc', () => { | ||
const doc = parseXml( | ||
`<?xml version="1.0"?> | ||
<ListMarketplaceParticipationsResponse xmlns="https://mws.amazonservices.com/Sellers/2011-07-01"> | ||
<ListMarketplaceParticipationsResult> | ||
<NextToken>MRgZW55IGNhcm5hbCBwbGVhc3VyZS6=</NextToken> | ||
<ListParticipations> | ||
<Participation> | ||
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId> | ||
<SellerId>A135KKEKJAIBJ56</SellerId> | ||
<HasSellerSuspendedListings>No</HasSellerSuspendedListings> | ||
</Participation> | ||
</ListParticipations> | ||
<ListMarketplaces> | ||
<Marketplace> | ||
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId> | ||
<Name>Amazon.com</Name> | ||
<DefaultCountryCode>US</DefaultCountryCode> | ||
<DefaultCurrencyCode>USD</DefaultCurrencyCode> | ||
<DefaultLanguageCode>en_US</DefaultLanguageCode> | ||
<DomainName>www.amazon.com</DomainName> | ||
</Marketplace> | ||
</ListMarketplaces> | ||
</ListMarketplaceParticipationsResult> | ||
<ResponseMetadata> | ||
<RequestId>efeab958-74e2-45d4-9018-2323084413b5</RequestId> | ||
</ResponseMetadata> | ||
</ListMarketplaceParticipationsResponse>` | ||
) | ||
|
||
const res = parseListMarketplaceParticipationsResponse( | ||
'/sellers:ListMarketplaceParticipationsResponse', | ||
doc | ||
) | ||
|
||
expect(res).toMatchSnapshot() | ||
}) | ||
|
||
it('should parse the ListMarketplaceParticipationsByNextTokenResponse example response from MWS doc', () => { | ||
const doc = parseXml( | ||
`<?xml version="1.0"?> | ||
<ListMarketplaceParticipationsByNextTokenResponse xmlns="https://mws.amazonservices.com/Sellers/2011-07-01"> | ||
<ListMarketplaceParticipationsByNextTokenResult> | ||
<NextToken>MRgZW55IGNhcm5hbCBwbGVhc3VyZS6=</NextToken> | ||
<ListParticipations> | ||
<Participation> | ||
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId> | ||
<SellerId>A135KKEKWF1JAI6</SellerId> | ||
<HasSellerSuspendedListings>No</HasSellerSuspendedListings> | ||
</Participation> | ||
</ListParticipations> | ||
<ListMarketplaces> | ||
<Marketplace> | ||
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId> | ||
<Name>Amazon.com</Name> | ||
<DefaultCountryCode>US</DefaultCountryCode> | ||
<DefaultCurrencyCode>USD</DefaultCurrencyCode> | ||
<DefaultLanguageCode>en_US</DefaultLanguageCode> | ||
<DomainName>www.amazon.com</DomainName> | ||
</Marketplace> | ||
</ListMarketplaces> | ||
</ListMarketplaceParticipationsByNextTokenResult> | ||
<ResponseMetadata> | ||
<RequestId>efeab958-74e2-45d4-9018-2323084413b5</RequestId> | ||
</ResponseMetadata> | ||
</ListMarketplaceParticipationsByNextTokenResponse>` | ||
) | ||
|
||
const res = parseListMarketplaceParticipationsResponse( | ||
'/sellers:ListMarketplaceParticipationsByNextTokenResponse', | ||
doc, | ||
true | ||
) | ||
|
||
expect(res).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const throttle = require('../throttle') | ||
|
||
const parseXml = require('../parsers') | ||
const parseListMarketplaceParticipationsResponse = require('../parsers/sellers/list-marketplace-participations-response') | ||
|
||
const RESOURCE = 'Sellers' | ||
const VERSION = '2011-07-01' | ||
|
||
const _listMarketplaceParticipations = Symbol('listMarketplaceParticipations') | ||
|
||
class Orders { | ||
constructor(client) { | ||
this.client = client | ||
|
||
this.listMarketplaceParticipations = throttle(this[_listMarketplaceParticipations].bind(this), 1, 15, { | ||
amount: 1, | ||
interval: 60 * 1000 | ||
}) | ||
} | ||
|
||
async [_listMarketplaceParticipations]({ | ||
nextToken | ||
}) { | ||
const hasToken = Boolean(nextToken) | ||
|
||
const {body} = await this.client.get(RESOURCE, VERSION, hasToken ? { | ||
Action: 'ListMarketplaceParticipationsByNextToken', | ||
NextToken: nextToken | ||
} : { | ||
Action: 'ListMarketplaceParticipations' | ||
}, { | ||
retry: { | ||
retries: 15 | ||
}, | ||
timeout: (60 + Math.random()) * 1000 | ||
}) | ||
|
||
const {getOrderResult} = parseListMarketplaceParticipationsResponse( | ||
hasToken ? | ||
'/sellers:ListMarketplaceParticipationsByNextTokenResponse' : | ||
'/sellers:ListMarketplaceParticipationsResponse', | ||
parseXml(body), | ||
) | ||
|
||
return getOrderResult.orders | ||
} | ||
|
||
clearRestores() { | ||
this.getOrders.abort() | ||
this.listOrders.abort() | ||
this.listOrderItems.abort() | ||
this.getServiceStatus.abort() | ||
} | ||
} | ||
|
||
module.exports = Orders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lib/client/parsers/sellers/list-marketplace-participations-response.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const parseResponseMetadata = require('../base/response-metadata') | ||
|
||
const parseListMarketplaceParticipationsResult = require('./list-marketplace-participations-result') | ||
|
||
module.exports = (key, node, token = false) => ({ | ||
listMarketplaceParticipationsResult: parseListMarketplaceParticipationsResult( | ||
token ? | ||
`${key}/sellers:ListMarketplaceParticipationsByNextTokenResult` : | ||
`${key}/sellers:ListMarketplaceParticipationsResult`, | ||
node | ||
), | ||
responseMetadata: parseResponseMetadata(`${key}/sellers:ResponseMetadata`, node) | ||
}) |
15 changes: 15 additions & 0 deletions
15
lib/client/parsers/sellers/list-marketplace-participations-result.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const select = require('../select') | ||
const {parseStr} = require('../base') | ||
|
||
const parseParticipation = require('./participation') | ||
const parseMarketplace = require('./marketplace') | ||
|
||
module.exports = (key, node) => ({ | ||
nextToken: parseStr(`${key}/sellers:NextToken`, node), | ||
participations: select(`${key}/sellers:ListParticipations/sellers:Participation`, node).map(n => { | ||
return parseParticipation('.', n) | ||
}), | ||
marketplaces: select(`${key}/sellers:ListMarketplaces/sellers:Marketplace`, node).map(n => { | ||
return parseMarketplace('.', n) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const {parseStr} = require('../base') | ||
|
||
module.exports = (key, node) => ({ | ||
marketplaceId: parseStr(`${key}/sellers:MarketplaceId`, node), | ||
name: parseStr(`${key}/sellers:Name`, node), | ||
defaultCountryCode: parseStr(`${key}/sellers:DefaultCountryCode`, node), | ||
defaultCurrencyCode: parseStr(`${key}/sellers:DefaultCurrencyCode`, node), | ||
defaultLanguageCode: parseStr(`${key}/sellers:DefaultLanguageCode`, node), | ||
domainName: parseStr(`${key}/sellers:DomainName`, node) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const {parseStr} = require('../base') | ||
|
||
module.exports = (key, node) => ({ | ||
marketplaceId: parseStr(`${key}/sellers:MarketplaceId`, node), | ||
sellerId: parseStr(`${key}/sellers:SellerId`, node), | ||
hasSellerSuspendedListings: parseStr(`${key}/sellers:HasSellerSuspendedListings`, node) === 'Yes' | ||
}) |