1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main(auth: Motimate, filter_id_: string | undefined) { |
7 | const url = new URL(`https://motimateapp.com/public_api/badges`) |
8 |
|
9 | for (const [k, v] of [['filter[id]', filter_id_]]) { |
10 | if (v !== undefined && v !== '' && k !== undefined) { |
11 | url.searchParams.append(k, v) |
12 | } |
13 | } |
14 |
|
15 | const response = await fetch(url, { |
16 | method: 'GET', |
17 | headers: { |
18 | Authorization: 'Bearer ' + auth.token |
19 | } |
20 | }) |
21 |
|
22 | if (!response.ok) { |
23 | const text = await response.text() |
24 | throw new Error(`${response.status} ${text}`) |
25 | } |
26 |
|
27 | return await response.json() |
28 | } |
29 |
|