1 |
|
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | q: string | undefined, |
9 | lang: string | undefined, |
10 | adhookToken: string |
11 | ) { |
12 | const url = new URL(`https://app.adhook.io/v1/promotions/linkedin/targeting/degrees`) |
13 |
|
14 | for (const [k, v] of [ |
15 | ['q', q], |
16 | ['lang', lang] |
17 | ]) { |
18 | if (v !== undefined && v !== '' && k !== undefined) { |
19 | url.searchParams.append(k, v) |
20 | } |
21 | } |
22 |
|
23 | const response = await fetch(url, { |
24 | method: 'GET', |
25 | headers: { |
26 | adhookToken: adhookToken, |
27 | Authorization: `Bearer ${auth.token}` |
28 | }, |
29 | body: undefined |
30 | }) |
31 |
|
32 | if (!response.ok) { |
33 | const text = await response.text() |
34 | throw new Error(`${response.status} ${text}`) |
35 | } |
36 |
|
37 | return await response.json() |
38 | } |
39 |
|