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

Commit

Permalink
feat: made listRecommendationByNextToken
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jul 8, 2020
1 parent e2683d9 commit f1f79a7
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/sections/recommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Codec, enumeration, GetInterface, number, optional, string } from 'puri

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { ensureArray, mwsDate, nextToken as nextTokenCodec } from '../parsing'
import { ensureArray, mwsDate, NextToken, nextToken as nextTokenCodec } from '../parsing'
import { getServiceStatusByResource } from './shared'
import { FulfillmentChannelEnum } from './types'

Expand Down Expand Up @@ -177,9 +177,38 @@ const ListRecommendationsResponse = Codec.interface({
}),
})

const ListRecommendationsByNextTokenResponse = Codec.interface({
ListRecommendationsByNextTokenResponse: Codec.interface({
ListRecommendationsByNextTokenResult: ListRecommendations,
}),
})

export class Recommendations {
constructor(private httpClient: HttpClient) {}

async listRecommendationsByNextToken(
nextToken: NextToken<'ListRecommendations'>,
): Promise<[ListRecommendations, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Recommendations,
version: RECOMMENDATIONS_API_VERSION,
action: 'ListRecommendationsByNextToken',
parameters: {
NextToken: nextToken.token,
},
})

return ListRecommendationsByNextTokenResponse.decode(response).caseOf({
Right: (x) => [
x.ListRecommendationsByNextTokenResponse.ListRecommendationsByNextTokenResult,
meta,
],
Left: (error) => {
throw new ParsingError(error)
},
})
}

async listRecommendations(
parameters: ListRecommendationsParameters,
): Promise<[ListRecommendations, RequestMeta]> {
Expand All @@ -189,6 +218,8 @@ export class Recommendations {
action: 'ListRecommendations',
parameters: {
MarketplaceId: parameters.MarketplaceId,
RecommendationCategory: parameters.RecommendationCategory,
'CategoryQueryList.CategoryQuery': parameters.CategoryQueryList,
},
})

Expand Down
169 changes: 169 additions & 0 deletions test/unit/__snapshots__/recommendations.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,172 @@ Array [
},
]
`;

exports[`recommendations listRecommendationsByNextToken returns a list of recommendations if next token is valid 1`] = `
Array [
Object {
"AdvertisingRecommendations": Array [
Object {
"AvailableQuantity": 1,
"BrandName": "String",
"ItemIdentifier": Object {
"Asin": "String",
"Sku": "String",
"Upc": "String",
},
"ItemName": "String",
"LastUpdated": 1969-07-21T02:56:03.000Z,
"LowestPricePlusShipping": Object {
"Amount": 100,
"CurrencyCode": "String",
},
"ProductCategory": "String",
"RecommendationId": "String",
"RecommendationReason": "String",
"SalesForTheLast30Days": 1,
"SalesRank": 1,
},
],
"FulfillmentRecommendations": Array [
Object {
"AverageCustomerReview": 100,
"BrandName": "String",
"ItemDimensions": Object {
"Height": Object {
"Unit": "String",
"Value": 100,
},
"Length": Object {
"Unit": "String",
"Value": 100,
},
"Weight": Object {
"Unit": "String",
"Value": 100,
},
"Width": Object {
"Unit": "String",
"Value": 100,
},
},
"ItemIdentifier": Object {
"Asin": "String",
"Sku": "String",
"Upc": "String",
},
"ItemName": "String",
"LastUpdated": 1969-07-21T02:56:03.000Z,
"NumberOfCustomerReviews": 1,
"NumberOfOffers": 1,
"NumberOfOffersFulfilledByAmazon": 1,
"ProductCategory": "String",
"RecommendationId": "String",
"RecommendationReason": "String",
"SalesRank": 1,
},
],
"GlobalSellingRecommendations": Array [
Object {
"AverageCustomerReview": 100,
"BrandName": "String",
"ItemDimensions": Object {
"Height": Object {
"Unit": "String",
"Value": 100,
},
"Length": Object {
"Unit": "String",
"Value": 100,
},
"Weight": Object {
"Unit": "String",
"Value": 100,
},
"Width": Object {
"Unit": "String",
"Value": 100,
},
},
"ItemIdentifier": Object {
"Asin": "String",
"Sku": "String",
"Upc": "String",
},
"ItemName": "String",
"LastUpdated": 1969-07-21T02:56:03.000Z,
"NumberOfCustomerReviews": 1,
"NumberOfOffers": 1,
"NumberOfOffersFulfilledByAmazon": 1,
"ProductCategory": "String",
"RecommendationId": "String",
"RecommendationReason": "String",
"SalesRank": 1,
},
],
"InventoryRecommendations": Array [
Object {
"AvailableQuantity": 1,
"DaysOutOfStockLast30Days": 1,
"DaysUntilStockRunsOut": 1,
"FulfillmentChannel": "String",
"ItemIdentifier": Object {
"Asin": "String",
"Sku": "String",
"Upc": "String",
},
"ItemName": "String",
"LastUpdated": 1969-07-21T02:56:03.000Z,
"RecommendationId": "String",
"RecommendationReason": "String",
},
],
"NextToken": NextToken {
"action": "ListRecommendations",
"token": "String",
},
"PricingRecommendations": Array [
Object {
"Condition": "String",
"FulfillmentChannel": "String",
"ItemIdentifier": Object {
"Asin": "String",
"Sku": "String",
"Upc": "String",
},
"ItemName": "String",
"LastUpdated": 1969-07-21T02:56:03.000Z,
"LowestAmazonFulfilledOfferPrice": Object {
"Amount": 100,
"CurrencyCode": "String",
},
"LowestMerchantFulfilledOfferPrice": Object {
"Amount": 100,
"CurrencyCode": "String",
},
"LowestPricePlusShipping": Object {
"Amount": 100,
"CurrencyCode": "String",
},
"MedianPricePlusShipping": Object {
"Amount": 100,
"CurrencyCode": "String",
},
"PriceDifferenceToLowPrice": Object {
"Amount": 100,
"CurrencyCode": "String",
},
"RecommendationId": "String",
"RecommendationReason": "String",
"SubCondition": "String",
},
],
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

0 comments on commit f1f79a7

Please sign in to comment.