deno.land / x / gesso@v0.1.2 / src / PollChoices.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102import { BaseApi } from "./BaseApi.ts";import { Configuration } from "./Configuration.ts";import { PollChoice, Scope } from "../types/models.ts";import { CreateSinglePollChoiceParams, UpdateSinglePollChoiceParams,} from "../types/params.ts";
export class PollChoices extends BaseApi { constructor(config: Configuration) { super(config); }
public async listPollChoicesInPoll( poll_id: string, body?: unknown, ): Promise<PollChoice> { const endpoint = `/api/v1/polls/${poll_id}/poll_choices`; const url = new URL(endpoint, this.configuration.domain);
const response = await this.get(url, JSON.stringify(body)); if (response.ok) { return await response.json() as PollChoice; }
return Promise.reject(response); }
public async getSinglePollChoice( poll_id: string, id: string, body?: unknown, ): Promise<PollChoice> { const endpoint = `/api/v1/polls/${poll_id}/poll_choices/${id}`; const url = new URL(endpoint, this.configuration.domain);
const response = await this.get(url, JSON.stringify(body)); if (response.ok) { return await response.json() as PollChoice; }
return Promise.reject(response); }
public async createSinglePollChoice( poll_id: string, params?: CreateSinglePollChoiceParams, body?: unknown, ): Promise<Scope> { const endpoint = `/api/v1/polls/${poll_id}/poll_choices`; const url = new URL(endpoint, this.configuration.domain); if (params !== undefined) { for (const [key, value] of Object.entries(params)) { url.searchParams.set(key, JSON.stringify(value)); } } const response = await this.post(url, JSON.stringify(body)); if (response.ok) { return await response.json() as Scope; }
return Promise.reject(response); }
public async updateSinglePollChoice( poll_id: string, id: string, params?: UpdateSinglePollChoiceParams, body?: unknown, ): Promise<Scope> { const endpoint = `/api/v1/polls/${poll_id}/poll_choices/${id}`; const url = new URL(endpoint, this.configuration.domain); if (params !== undefined) { for (const [key, value] of Object.entries(params)) { url.searchParams.set(key, JSON.stringify(value)); } } const response = await this.put(url, JSON.stringify(body)); if (response.ok) { return await response.json() as Scope; }
return Promise.reject(response); }
public async deletePollChoice( poll_id: string, id: string, body?: unknown, ): Promise<Scope> { const endpoint = `/api/v1/polls/${poll_id}/poll_choices/${id}`; const url = new URL(endpoint, this.configuration.domain);
const response = await this.delete(url, JSON.stringify(body)); if (response.ok) { return await response.json() as Scope; }
return Promise.reject(response); }}
Version Info