import _ from 'lodash' ; import RequestMethod from 'constants/requestMethod' ; /**
 * StrawPoll base API URL.
 */ const BaseUrl = 'https://www.strawpoll.me/api/v2' ; /**
 * StrawPoll class.
 */ export default class StrawPoll { param id return public static async fetchPoll ( id ) { const response = await StrawPoll . fetch ( `/polls/${ id }` ) ; return response . json ( ) ; } param title param options param multi param dupcheck param captcha return public static async createPoll ( title , options , multi , dupcheck , captcha ) { const response = await StrawPoll . fetch ( '/polls' , RequestMethod . Post , { captcha , dupcheck , multi , options , title , } ) ; return response . json ( ) ; } param endpoint return private static getUrl ( endpoint ) { return BaseUrl . concat ( endpoint ) ; } param endpoint param method param body return private static async fetch ( endpoint , method = RequestMethod . Get , body ? ) { const url = StrawPoll . getUrl ( endpoint ) ; const init = { method } ; if ( ! _ . isNil ( body ) ) { init . body = JSON . stringify ( body ) ; } const request = new Request ( url , init ) ; return fetch ( request ) ; } } /**
 * Straw Poll duplication check strategies.
 */ export enum StrawPollDuplicationStrategy { Cookie = 'permissive' , Ip = 'normal' , None = 'disabled' } /**
 * Poll.
 */ export type RawPoll = { id : number ; title : string ; options : string [ ] ; votes : number [ ] ; multi : boolean ; dupcheck : string ; captcha : boolean ; } ;