Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #55 from bizon/tusbar/add-sellers-participations
Browse files Browse the repository at this point in the history
Add sellers.listMarketplaceParticipations API
  • Loading branch information
tusbar authored Oct 28, 2019
2 parents 384bc63 + f25cc50 commit ec750b2
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ marketplaceId | `String` |
asin | `String` |
itemCondition | `String` |

### Sellers

Version: `2011-07-01`

#### `listMarketplaceParticipations(options)`

Options:

Name | Type | Default
-----|------|--------
nextToken | `String` |

### Reports

Version: `2009-01-01`
Expand Down
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",
},
}
`;
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()
})
})
2 changes: 2 additions & 0 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Finances = require('./models/finances')
const Orders = require('./models/orders')
const Products = require('./models/products')
const Reports = require('./models/reports')
const Sellers = require('./models/sellers')
const Subscriptions = require('./models/subscriptions')

const _signData = Symbol('signData')
Expand Down Expand Up @@ -48,6 +49,7 @@ class Client {
this.orders = new Orders(this)
this.products = new Products(this)
this.reports = new Reports(this)
this.sellers = new Sellers(this)
this.subscriptions = new Subscriptions(this)
}

Expand Down
56 changes: 56 additions & 0 deletions lib/client/models/sellers.js
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
1 change: 1 addition & 0 deletions lib/client/parsers/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
products: 'http://mws.amazonservices.com/schema/Products/2011-10-01',
products2: 'http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd',
reports: 'http://mws.amazonaws.com/doc/2009-01-01/',
sellers: 'https://mws.amazonservices.com/Sellers/2011-07-01',
subscriptions: 'http://mws.amazonservices.com/schema/Subscriptions/2013-07-01'
}
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)
})
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)
})
})
10 changes: 10 additions & 0 deletions lib/client/parsers/sellers/marketplace.js
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)
})
7 changes: 7 additions & 0 deletions lib/client/parsers/sellers/participation.js
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'
})

0 comments on commit ec750b2

Please sign in to comment.