Advertisement
Guest User

APIReader

a guest
Apr 1st, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Threading.Tasks;
  4. using Newtonsoft.Json;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7.  
  8. namespace EuroMillions
  9. {
  10.     public class APIReader
  11.     {
  12.         ObservableCollection<Drawn> drawns;
  13.         public APIReader() {
  14.             this.drawns = new ObservableCollection<Drawn>();
  15.         }
  16.  
  17.         public ObservableCollection<Drawn> getDrawns()
  18.         {
  19.             return drawns;
  20.         }
  21.  
  22.         public  async void getLastDrawnASync()
  23.         {
  24.             var client = new System.Net.Http.HttpClient();
  25.             client.BaseAddress = new Uri("https://nunofcguerreiro.com/");
  26.             var response = await client.GetAsync("api-euromillions-json");
  27.             var drawnsJson = response.Content.ReadAsStringAsync().Result;
  28.             var rootobject =  JsonConvert.DeserializeObject<RootObject>(drawnsJson);
  29.             foreach (var drawn_json in rootobject.drawns)
  30.             {
  31.                 this.drawns.Add(drawn_json);
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement