//native
type Ably = {
apiKey: string;
};
/**
* List all channels with at least one subscribed device
* Returns a paginated response of channel names.
*/
export async function main(
auth: Ably,
format: "json" | "jsonp" | "msgpack" | "html" | undefined,
X_Ably_Version: string,
) {
const url = new URL(`https://rest.ably.io/push/channels`);
for (const [k, v] of [["format", format]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-Ably-Version": X_Ably_Version,
Authorization: "Bearer " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 138 days ago