Skip to content

Commit 2df071f

Browse files
authored
add binary function to get statements (#182)
* add binary function to get statements * fix
1 parent 493d610 commit 2df071f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

resources/baseResource.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axiosStatic, { AxiosInstance, AxiosRequestHeaders } from "axios"
1+
import axiosStatic, {AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, responseEncoding} from "axios"
22
import { extractUnitError, UnitConfig } from "../types/common"
33

44
export class BaseResource {
@@ -18,12 +18,13 @@ export class BaseResource {
1818
this.axios = config?.axios ?? axiosStatic
1919
}
2020

21-
protected async httpGet<T>(path: string, config?: { headers?: object; params?: object; }) : Promise<T> {
21+
protected async httpGet<T>(path: string, config?: { headers?: object; params?: object; responseEncoding?: responseEncoding;}) : Promise<T> {
2222

2323
const conf = {
2424
headers: this.mergeHeaders(config?.headers),
25-
...(config?.params && { params: (config.params)})
26-
}
25+
...(config?.params && { params: (config.params)}),
26+
...(config?.responseEncoding && {responseEncoding: config.responseEncoding})
27+
} as AxiosRequestConfig
2728

2829
return await this.axios.get<T>(this.resourcePath + path, conf)
2930
.then(r => r.data)

resources/statements.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ export class Statments extends BaseResource {
2727
const url = isPDF ? `/${statementId}/pdf` : `/${statementId}/html`
2828
return this.httpGet<string>(url, {params: parameters})
2929
}
30+
31+
public getBinary(statementId: string, customerId?: string, isPDF = false): Promise<string> {
32+
const parameters = {
33+
...(customerId && { "filter[customerId]": customerId })
34+
}
35+
36+
const url = isPDF ? `/${statementId}/pdf` : `/${statementId}/html`
37+
return this.httpGet<string>(url, {params: parameters, responseEncoding:"binary"})
38+
}
3039
}
3140

3241
export interface StatementsListParams extends BaseListParams {

tests/statements.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Unit } from "../unit"
2-
32
import dotenv from "dotenv"
43
dotenv.config()
54
const unit = new Unit(process.env.UNIT_TOKEN || "test", process.env.UNIT_API_URL || "test")

0 commit comments

Comments
 (0)