1 | |
2 | type Ably = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * List channel subscriptions |
7 | * Get a list of push notification subscriptions to channels. |
8 | */ |
9 | export async function main( |
10 | auth: Ably, |
11 | format: "json" | "jsonp" | "msgpack" | "html" | undefined, |
12 | channel: string | undefined, |
13 | deviceId: string | undefined, |
14 | clientId: string | undefined, |
15 | limit: string | undefined, |
16 | X_Ably_Version: string, |
17 | ) { |
18 | const url = new URL(`https://rest.ably.io/push/channelSubscriptions`); |
19 | for (const [k, v] of [ |
20 | ["format", format], |
21 | ["channel", channel], |
22 | ["deviceId", deviceId], |
23 | ["clientId", clientId], |
24 | ["limit", limit], |
25 | ]) { |
26 | if (v !== undefined && v !== "" && k !== undefined) { |
27 | url.searchParams.append(k, v); |
28 | } |
29 | } |
30 | const response = await fetch(url, { |
31 | method: "GET", |
32 | headers: { |
33 | "X-Ably-Version": X_Ably_Version, |
34 | Authorization: "Bearer " + auth.apiKey, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|