public static string BuildPayload(string title, List <string> options, bool multi = false, Enums.DupCheck dupCheck = Enums.DupCheck.Normal, bool captcha = false) { JObject json = new JObject(); json.Add("title", title); json.Add("options", new JArray(options)); json["multi"] = multi; switch (dupCheck) { case Enums.DupCheck.Disabled: json.Add("dupcheck", "disabled"); break; case Enums.DupCheck.Normal: json.Add("dupcheck", "normal"); break; case Enums.DupCheck.Permissive: json.Add("dupcheck", "permissive"); break; } json["captcha"] = captcha; return(json.ToString()); }
public static async Task <CreatedPoll> CreatePoll(string title, List <string> options, bool multi = false, Enums.DupCheck dupCheck = Enums.DupCheck.Normal, bool captcha = false) { if (options.Count < 2 || options.Count > 30) { throw new Exceptions.BadParameterException("Invalid number of options provided. You must provide at least 2 options, but no more than 30."); } string payload = Helpers.BuildPayload(title, options, multi, dupCheck, captcha); var resp = await Helpers.MakePostRequest(apiEndpoint, payload); return(new CreatedPoll(JObject.Parse(resp))); }
/// <summary> /// [SYNC] This call will attempt to create a poll and return an object housing all the details about the poll. /// </summary> /// <param name="title">The title that is presented to the voter.</param> /// <param name="options">List of strings to be included as options in the poll. Max: 30, Min: 2.</param> /// <param name="multi">Boolean value dictating whether voters can select multiple choices or not.</param> /// <param name="dupCheck">Enum reflecting the kind of duplication checking Strawpoll should do.</param> /// <param name="captcha">Boolean value dicating whether or not a captcha should be required.</param> /// <returns>CreatedPoll is returned, which houses all poll data.</returns> public async static Task <CreatedPoll> CreatePollAsync(string title, List <string> options, bool multi = false, Enums.DupCheck dupCheck = Enums.DupCheck.Normal, bool captcha = false) => await Internal.Calls.CreatePoll(title, options, multi, dupCheck, captcha);
/// <summary> /// [SYNC] This call will attempt to create a poll and return an object housing all the details about the poll. /// </summary> /// <param name="title">The title that is presented to the voter.</param> /// <param name="options">List of strings to be included as options in the poll. Max: 30, Min: 2.</param> /// <param name="multi">Boolean value dictating whether voters can select multiple choices or not.</param> /// <param name="dupCheck">Enum reflecting the kind of duplication checking Strawpoll should do.</param> /// <param name="captcha">Boolean value dicating whether or not a captcha should be required.</param> /// <returns>CreatedPoll is returned, which houses all poll data.</returns> public static CreatedPoll CreatePoll(string title, List <string> options, bool multi = false, Enums.DupCheck dupCheck = Enums.DupCheck.Normal, bool captcha = false) => Task.Run(() => Internal.Calls.CreatePoll(title, options, multi, dupCheck, captcha)).Result;