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

Commit

Permalink
docs: add MWS class usage to docs and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 30, 2020
1 parent 76ccb91 commit 74133f2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 22 deletions.
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ $ npm i -s @scaleleap/amazon-mws-api-sdk
## Example
---

```TypeScript
```typescript
import {
amazonMarketplaces,
HttpClient,
Sellers,
Orders
Orders,
MWS
} from '@scaleleap/amazon-mws-api-sdk'

const mwsOptions = {
Expand All @@ -38,19 +39,23 @@ const mwsOptions = {
sellerId: '',
secretKey: '',
}

// Using sections directly
const main = async () => {
const http = new HttpClient(mwsOptions)

// Get status for Sellers API
/**
* Get status for Sellers API
*/
const sellers = new Sellers(http)
const [serviceStatus] = await sellers.getServiceStatus()
if (serviceStatus.Status === 'GREEN') {
console.log(`Sellers API is up on ${serviceStatus.Timestamp}!`)
}

// List Orders
/**
* List Orders
*/
const orders = new Orders(http)
// or
const [ordersList, requestMeta] = await orders.listOrders({
MarketplaceId: [amazonMarketplaces.US.id],
CreatedAfter: new Date(Date.now() - 100 * 24 * 60 * 60 * 1000)
Expand All @@ -60,6 +65,32 @@ const main = async () => {
console.log(`Order ID is ${order.AmazonOrderId}`)
})
}

// Using MWS client
const main = async () => {
const http = new HttpClient(mwsOptions)
const mws = new MWS(http)
/**
* Get status for Sellers API
*/
const [serviceStatus] = await mws.sellers.getServiceStatus()
if (serviceStatus.Status === 'GREEN') {
console.log(`Sellers API is up on ${serviceStatus.Timestamp}!`)
}

/**
* List Orders
*/
const [ordersList, requestMeta] = await mws.orders.listOrders({
MarketplaceId: [amazonMarketplaces.US.id],
CreatedAfter: new Date(Date.now() - 100 * 24 * 60 * 60 * 1000)
})

ordersList.Orders.forEach((order) => {
console.log(`Order ID is ${order.AmazonOrderId}`)
})
}

```
## [More examples in the `/examples` folder!](examples)

Expand Down
27 changes: 27 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [Next tokens](#next-tokens)
* [Creating `NextToken`s](#creating--nexttoken-s)
* [Reusing next tokens from a previous response](#reusing-next-tokens-from-a-previous-response)
* [MWS Class](#mws-class)
* [Sections](#sections)
* [Sellers](#sellers)
* [listMarketplaceParticipations](#listmarketplaceparticipations)
Expand Down Expand Up @@ -224,6 +225,32 @@ This is returned along with the API's response
}
```

## MWS Class
It is also possible to use the `MWS` access the sections and all their actions

**Example**
```typescript
// Using MWS client
const usingMws = async () => {
const http = new HttpClient(mwsOptions)

/**
* Configure MWS with the same http client
*/
const mws = new MWS(http)

const [serviceStatus] = await mws.sellers.getServiceStatus()
/**
* Also available
* mws.orders, mws.feeds, mws.finances, mws.fulfillmentInventory,
* mws.products, mws.reports, mws.subscriptions
*/
if (serviceStatus.Status === 'GREEN') {
console.log(`Sellers API is up on ${serviceStatus.Timestamp}!`)
}
}
```

# Sections

---
Expand Down
42 changes: 26 additions & 16 deletions examples/get-service-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* import from '@scaleleap/amazon-mws-api-sdk'
*/
import { amazonMarketplaces, HttpClient, Sellers } from '@scaleleap/amazon-mws-api-sdk'
import { amazonMarketplaces, HttpClient, MWS, Sellers } from '@scaleleap/amazon-mws-api-sdk'

/**
* Configure the HttpClient
Expand All @@ -19,18 +19,17 @@ const mwsOptions = {
secretKey: '',
}

const http = new HttpClient(mwsOptions)

/**
* Configure which API you need
* Sellers, Orders, Fulfillment Inventory, Products, Reports, Subscriptions, Finances, Feeds
* Get service status of the Sellers API using sections directly
*/
const sellers = new Sellers(http)
const usingSections = async () => {
const http = new HttpClient(mwsOptions)

/**
* Get service status of the Sellers API
*/
const main = async () => {
/**
* Configure which API you need
* Sellers, Orders, Fulfillment Inventory, Products, Reports, Subscriptions, Finances, Feeds
*/
const sellers = new Sellers(http)
/**
* Returns a tuple containing
* [0] Actual response data in JS object format
Expand All @@ -41,11 +40,22 @@ const main = async () => {
if (serviceStatus.Status === 'GREEN') {
console.log(`Sellers API is up on ${serviceStatus.Timestamp}!`)
}
}

/**
* Check out Amazon's official docs for other available endpoints
* and definitions of possible request and response parameters
* http://docs.developer.amazonservices.com/en_CA/dev_guide/index.html
* Under the folder API References
*/
// Using MWS client
const usingMws = async () => {
const http = new HttpClient(mwsOptions)
const mws = new MWS(http)

const [serviceStatus] = await mws.sellers.getServiceStatus()
if (serviceStatus.Status === 'GREEN') {
console.log(`Sellers API is up on ${serviceStatus.Timestamp}!`)
}
}

/**
* Check out Amazon's official docs for other available endpoints
* and definitions of possible request and response parameters
* http://docs.developer.amazonservices.com/en_CA/dev_guide/index.html
* Under the folder API References
*/

0 comments on commit 74133f2

Please sign in to comment.