1 |
|
2 | type Adrapid = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adrapid, |
8 | offset?: string | undefined, |
9 | limit?: string | undefined, |
10 | search?: string | undefined, |
11 | status?: 'exporting' | 'ready' | 'failed' | undefined |
12 | ) { |
13 | const url = new URL(`https://api.adrapid.com/banners`) |
14 |
|
15 | for (const [k, v] of [ |
16 | ['offset', offset], |
17 | ['limit', limit], |
18 | ['search', search], |
19 | ['status', status] |
20 | ]) { |
21 | if (v !== undefined && v !== '' && k !== undefined) { |
22 | url.searchParams.append(k, v) |
23 | } |
24 | } |
25 |
|
26 | const response = await fetch(url, { |
27 | method: 'GET', |
28 | headers: { |
29 | Authorization: 'Bearer ' + auth.token |
30 | }, |
31 | body: undefined |
32 | }) |
33 |
|
34 | if (!response.ok) { |
35 | const text = await response.text() |
36 | throw new Error(`${response.status} ${text}`) |
37 | } |
38 |
|
39 | return await response.json() |
40 | } |
41 |
|