1 | |
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Actimo, |
8 | clientId: string | undefined, |
9 | count: string | undefined, |
10 | limit: string | undefined, |
11 | offset: string | undefined, |
12 | order: string | undefined, |
13 | search: string | undefined |
14 | ) { |
15 | const url = new URL(`https://actimo.com/api/v1/academy`) |
16 |
|
17 | for (const [k, v] of [ |
18 | ['clientId', clientId], |
19 | ['count', count], |
20 | ['limit', limit], |
21 | ['offset', offset], |
22 | ['order', order], |
23 | ['search', search] |
24 | ]) { |
25 | if (v !== undefined && v !== '' && k !== undefined) { |
26 | url.searchParams.append(k, v) |
27 | } |
28 | } |
29 |
|
30 | const response = await fetch(url, { |
31 | method: 'GET', |
32 | headers: { |
33 | 'api-key': auth.apiKey |
34 | }, |
35 | body: undefined |
36 | }) |
37 |
|
38 | if (!response.ok) { |
39 | const text = await response.text() |
40 | throw new Error(`${response.status} ${text}`) |
41 | } |
42 |
|
43 | return await response.json() |
44 | } |
45 |
|