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

Commit

Permalink
feat: made cancelfeedsubmissions
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado authored and moltar committed Jun 28, 2020
1 parent e40d30c commit 1e3ad85
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
65 changes: 56 additions & 9 deletions src/sections/feeds.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { boolean, Codec, GetInterface, number, optional, string } from 'purify-ts'
import {
array,
boolean,
Codec,
exactly,
GetInterface,
number,
oneOf,
optional,
string,
} from 'purify-ts'

import { ParsingError } from '../error'
import { HttpClient, RequestMeta, Resource } from '../http'
import {
ensureArray,
ensureString,
mwsDate,
NextToken,
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 @@ -32,7 +36,7 @@ const FeedSubmissionInfo = Codec.interface({
const GetFeedSubmissionList = Codec.interface({
HasToken: optional(boolean),
NextToken: optional(nextTokenCodec('GetFeedSubmissionList')),
FeedSubmissionInfo: optional(ensureArray('FeedSubmissionInfo', FeedSubmissionInfo)),
FeedSubmissionInfo: oneOf([FeedSubmissionInfo, array(FeedSubmissionInfo), exactly('')]),
})

type GetFeedSubmissionList = GetInterface<typeof GetFeedSubmissionList>
Expand Down Expand Up @@ -112,9 +116,52 @@ const GetFeedSubmissionCountResponse = Codec.interface({
}),
})

export interface CancelFeedSubmissionsParameters {
FeedSubmissionIdList?: string[]
FeedTypeList?: string[]
SubmittedFromDate?: Date
SubmittedToDate?: Date
}

const CancelFeedSubmissions = Codec.interface({
Count: number,
FeedSubmissionInfo: oneOf([FeedSubmissionInfo, array(FeedSubmissionInfo), exactly('')]),
})

export type CancelFeedSubmissions = GetInterface<typeof CancelFeedSubmissions>

const CancelFeedSubmissionsResponse = Codec.interface({
CancelFeedSubmissionsResponse: Codec.interface({
CancelFeedSubmissionsResult: CancelFeedSubmissions,
}),
})

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

async cancelFeedSubmissions(
parameters: CancelFeedSubmissionsParameters = {},
): Promise<[CancelFeedSubmissions, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Feeds,
version: FEEDS_API_VERSION,
action: 'CancelFeedSubmissions',
parameters: {
'FeedSubmissionIdList.Id': parameters.FeedSubmissionIdList,
'FeedTypeList.Type': parameters.FeedTypeList,
SubmittedFromDate: parameters.SubmittedFromDate?.toISOString(),
SubmittedToDate: parameters.SubmittedToDate?.toISOString(),
},
})

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

async getFeedSubmissionCount(
parameters: GetFeedSubmissionCountParameters = {},
): Promise<[GetFeedSubmissionCount, RequestMeta]> {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/__snapshots__/feeds.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`feeds cancelFeedSubmissions returns count and submission info of canceled feed submissions 1`] = `
Array [
Object {
"Count": 1,
"FeedSubmissionInfo": Object {
"FeedProcessingStatus": "_CANCELLED_",
"FeedSubmissionId": "2291326430",
"FeedType": "_POST_PRODUCT_DATA_",
"SubmittedDate": 2009-02-20T02:10:35.000Z,
},
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`feeds getFeedSubmissionCount returns count of total number of feed submissions if succesful 1`] = `
Array [
Object {
Expand Down

0 comments on commit 1e3ad85

Please sign in to comment.