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

Commit

Permalink
feat: made getFeedSubmissionsListByNT and feedsubmissioninfo
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent bf37943 commit db928a3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
44 changes: 41 additions & 3 deletions src/sections/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { boolean, Codec, GetInterface, optional, unknown } from 'purify-ts'
import { boolean, Codec, GetInterface, optional, string } from 'purify-ts'

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import { nextToken as nextTokenCodec } from '../parsing'
import { ensureString, mwsDate, NextToken, nextToken as nextTokenCodec } from '../parsing'

const FEEDS_API_VERSION = '2009-01-01'
interface GetFeedSubmissionListParameters {
Expand All @@ -14,10 +14,19 @@ interface GetFeedSubmissionListParameters {
SubmittedToDate?: Date
}

const FeedSubmissionInfo = Codec.interface({
FeedSubmissionId: ensureString,
FeedType: string,
SubmittedDate: mwsDate,
FeedProcessingStatus: string,
StartedProcessingDate: optional(mwsDate),
CompletedProcessingDate: optional(mwsDate),
})

const GetFeedSubmissionList = Codec.interface({
HasToken: optional(boolean),
NextToken: optional(nextTokenCodec('GetFeedSubmissionList')),
FeedSubmissionInfo: optional(unknown),
FeedSubmissionInfo: optional(FeedSubmissionInfo),
})

type GetFeedSubmissionList = GetInterface<typeof GetFeedSubmissionList>
Expand All @@ -28,9 +37,38 @@ const GetFeedSubmissionListResponse = Codec.interface({
}),
})

const GetFeedSubmissionListByNextTokenResponse = Codec.interface({
GetFeedSubmissionListByNextTokenResponse: Codec.interface({
GetFeedSubmissionListByNextTokenResult: GetFeedSubmissionList,
}),
})

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

async getFeedSubmissionListByNextToken(
nextToken: NextToken<'GetFeedSubmissionList'>,
): Promise<[GetFeedSubmissionList, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Feeds,
version: FEEDS_API_VERSION,
action: 'GetFeedSubmissionListByNextToken',
parameters: {
NextToken: nextToken.token,
},
})

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

async getFeedSubmissionList(
parameters: GetFeedSubmissionListParameters = {},
): Promise<[GetFeedSubmissionList, RequestMeta]> {
Expand Down
28 changes: 26 additions & 2 deletions test/unit/__snapshots__/feeds.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Array [
Object {
"FeedSubmissionInfo": Object {
"FeedProcessingStatus": "_SUBMITTED_",
"FeedSubmissionId": 2291326430,
"FeedSubmissionId": "2291326430",
"FeedType": "_POST_PRODUCT_DATA_",
"SubmittedDate": "2009-02-20T02:10:35+00:00",
"SubmittedDate": 2009-02-20T02:10:35.000Z,
},
"NextToken": NextToken {
"action": "GetFeedSubmissionList",
Expand All @@ -23,3 +23,27 @@ Array [
},
]
`;

exports[`feeds getFeedSubmissionListByNextToken returns a next token and feed submission info if succesful 1`] = `
Array [
Object {
"FeedSubmissionInfo": Object {
"FeedProcessingStatus": "_SUBMITTED_",
"FeedSubmissionId": "2291326430",
"FeedType": "_POST_PRODUCT_DATA_",
"SubmittedDate": 2009-02-20T02:10:35.000Z,
},
"NextToken": NextToken {
"action": "GetFeedSubmissionList",
"token": "none",
},
},
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 db928a3

Please sign in to comment.