Пример #1
0
        public static string CreateRequest(PollRequest req)
        {
            JObject obj = new JObject
            {
                { "title", req.Title },
                { "options", new JArray(req.Options) },
                { "multi", req.Multi ?? true }
            };

            switch (req.Dupcheck ?? DupCheck.Normal)
            {
            case DupCheck.Normal:
                obj.Add("dupcheck", "normal");
                break;

            case DupCheck.Permissive:
                obj.Add("dupcheck", "permissive");
                break;

            case DupCheck.Disabled:
                obj.Add("dupcheck", "disabled");
                break;
            }

            obj.Add("captcha", req.Captcha ?? false);

            return(obj.ToString());
        }
Пример #2
0
        public async Task <Poll> CreatePollAsync(PollRequest poll)
        {
            HttpResponseMessage resultJson;
            var jsondata = Request.CreateRequest(poll);

            using (var client = new HttpClient())
            {
                var content = new StringContent(jsondata, Encoding.UTF8, "application/json");
                resultJson = await client.PostAsync(endpointURL, content);
            }

            return(JsonConvert.DeserializeObject <Poll>(await resultJson.Content.ReadAsStringAsync()));
        }