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

Commit

Permalink
feat: get competitive pricing for ASIN response api
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed May 26, 2020
1 parent 18d4b83 commit af305b1
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/sections/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ const GetCompetitivePricingForSKUResponse = Codec.interface({
GetCompetitivePricingForSKUResponse: GetCompetitivePricingForSKUResult,
})

const GetCompetitivePricingForASINResult = ensureArray(
'GetCompetitivePricingForASINResult',
Codec.interface({
Product,
}),
)

type GetCompetitivePricingForASINResult = GetInterface<typeof GetCompetitivePricingForASINResult>

interface GetCompetitivePricingForAsinParameters {
MarketplaceId: string
ASINList: string[]
[key: string]: string | string[]
}

const GetCompetitivePricingForASINResponse = Codec.interface({
GetCompetitivePricingForASINResponse: GetCompetitivePricingForASINResult,
})

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

Expand Down Expand Up @@ -330,4 +349,25 @@ export class Products {
},
})
}

async getCompetitivePricingForAsin(
parameters: GetCompetitivePricingForAsinParameters,
): Promise<[GetCompetitivePricingForASINResult, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Products,
version: PRODUCTS_API_VERSION,
action: 'GetCompetitivePricingForASIN',
parameters: {
'ASINList.ASIN': parameters.ASINList,
MarketplaceId: parameters.MarketplaceId,
},
})

return GetCompetitivePricingForASINResponse.decode(response).caseOf({
Right: (x) => [x.GetCompetitivePricingForASINResponse, meta],
Left: (error) => {
throw new ParsingError(error)
},
})
}
}
53 changes: 53 additions & 0 deletions test/unit/__snapshots__/products.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`products getCompetitivePricingForASIN returns product and competitive prices when response is valid 1`] = `
Array [
Array [
Object {
"Product": Object {
"CompetitivePricing": Object {
"CompetitivePrices": Object {
"CompetitivePrice": Object {
"CompetitivePriceId": 1,
"Price": Object {
"LandedPrice": Object {
"Amount": 34.27,
"CurrencyCode": "USD",
},
"ListingPrice": Object {
"Amount": 34.27,
"CurrencyCode": "USD",
},
"Shipping": Object {
"Amount": 0,
"CurrencyCode": "USD",
},
},
},
},
"NumberOfOfferListings": Object {
"OfferListingCount": Array [
11,
1,
10,
],
},
},
"Identifiers": Object {
"MarketplaceASIN": Object {
"ASIN": "B002KT3XQM",
"MarketplaceId": "ATVPDKIKX0DER",
},
},
"SalesRankings": "",
},
},
],
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": "2020-04-06T10:22:23.582Z",
"requestId": "0",
"timestamp": "2020-05-06T09:22:23.582Z",
},
]
`;

exports[`products getCompetitivePricingForSku returns product and competitive prices when response is valid 1`] = `
Array [
Array [
Expand Down

0 comments on commit af305b1

Please sign in to comment.