コード例 #1
0
        //Performs web API call process to retrieve random quote and author
        //Comination Check class direct here to initialize
        //Uses Newtonsoft Json to deserialize
        public static async Task GetQuote()
        {
            string urlRanQuote = "https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?";

            WebApiRequest.InitializeClient();

            using (HttpResponseMessage message = await WebApiRequest.client.GetAsync(urlRanQuote))
            {
                if (message.IsSuccessStatusCode)
                {
                    string response = await WebApiRequest.client.GetStringAsync(urlRanQuote);

                    var charRemove = new string[] { "?", "(", ")" };
                    foreach (var item in charRemove)
                    {
                        response = response.Replace(item, string.Empty);
                    }

                    QuoteModel quoteItems = JsonConvert.DeserializeObject <QuoteModel>(response);

                    Result_Success.quoteReveal  = quoteItems.quoteText;
                    Result_Success.authorReveal = quoteItems.quoteAuthor;
                }
                else
                {
                    throw new Exception(message.ReasonPhrase);
                }
            }
        }
コード例 #2
0
        //Performs web API call to retrieve random number combination
        public static async Task GetRanComb()
        {
            string urlRanNum = "https://www.random.org/integers/?num=4&min=0&max=7&col=1&base=10&format=plain&rnd=new";

            WebApiRequest.InitializeClient();

            using (HttpResponseMessage message = await WebApiRequest.client.GetAsync(urlRanNum))
            {
                if (message.IsSuccessStatusCode)
                {
                    string response = await message.Content.ReadAsStringAsync();

                    //-------flag - uncomment to reveal for debugging-------//
                    //MessageBox.Show(response);

                    NumModel.NumberModel.apiRanNum = response;
                }
                else
                {
                    throw new Exception(message.ReasonPhrase);
                }
            }
        }