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

Commit

Permalink
feat: get report count
Browse files Browse the repository at this point in the history
  • Loading branch information
justinemmanuelmercado committed Jun 10, 2020
1 parent 5ab10e3 commit 6f5aeff
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/sections/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getServiceStatusByResource } from './shared'

const REPORTS_API_VERSION = '2009-01-01'
/**
* List of supported strings
* Should probably define an enum for this
* List of supported strings.
* Could probably define an enum for this
* http://docs.developer.amazonservices.com/en_CA/reports/Reports_ReportType.html#ReportTypeCategories__ListingsReports
*/
const ReportType = string
Expand Down Expand Up @@ -167,9 +167,51 @@ const GetReportListByNextTokenResponse = Codec.interface({
})

type GetReportListResult = GetInterface<typeof GetReportListResult>

const GetReportCount = Codec.interface({
Count: number,
})

const GetReportCountResponse = Codec.interface({
GetReportCountResponse: Codec.interface({
GetReportCountResult: GetReportCount,
}),
})

interface GetReportCountParameters {
ReportTypeList?: ReportType[]
Acknowledged?: boolean
AvailableFromDate?: Date
AvailableToDate?: Date
}

type GetReportCount = GetInterface<typeof GetReportCount>
export class Reports {
constructor(private httpClient: HttpClient) {}

async getReportCount(
parameters: GetReportCountParameters,
): Promise<[GetReportCount, RequestMeta]> {
const [response, meta] = await this.httpClient.request('POST', {
resource: Resource.Report,
version: REPORTS_API_VERSION,
action: 'GetReportRequestCount',
parameters: {
'ReportTypeList.Type': parameters.ReportTypeList,
Acknowledged: parameters.Acknowledged,
AvailableFromDate: parameters.AvailableFromDate?.toISOString(),
AvailableToDate: parameters.AvailableToDate?.toISOString(),
},
})

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

async getReportListByNextToken(
parameters: GetReportListByNextTokenParameters,
): Promise<[GetReportListResult, RequestMeta]> {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/__snapshots__/reports.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Array [
]
`;

exports[`reports getReportCount returns report count if succesful 1`] = `
Array [
Object {
"Count": 166,
},
Object {
"quotaMax": 1000,
"quotaRemaining": 999,
"quotaResetOn": 2020-04-06T10:22:23.582Z,
"requestId": "0",
"timestamp": 2020-05-06T09:22:23.582Z,
},
]
`;

exports[`reports getReportList returns report info and next token if succesful 1`] = `
Array [
Object {
Expand Down

0 comments on commit 6f5aeff

Please sign in to comment.