ConstructorService.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. namespace AdaptTablet.ErgastAPI.Services.Constructors
  2. {
  3. using System;
  4. using System.Threading.Tasks;
  5. using System.Net;
  6. using Model.Constructor;
  7. using Model.Race;
  8. using Newtonsoft.Json;
  9. using Base;
  10. public class ConstructorService : HttpWebBase, IConstructorService
  11. {
  12. public async Task<ConstructorTable> GetSeasonConstructorCollectionAsync(string season = "current")
  13. {
  14. RaceRootObject data = null;
  15. var url = string.Format("http://ergast.com/api/f1/{0}/constructors.json", season);
  16. HttpWebRequest request = WebRequest.CreateHttp(new Uri(url));
  17. var response = await HttpRequest(request);
  18. if (response != null)
  19. data = JsonConvert.DeserializeObject<RaceRootObject>(response);
  20. return data != null ? data.MRData.ConstructorTable : null;
  21. }
  22. public async Task<ConstructorTable> GetAllConstructorCollectionAsync()
  23. {
  24. RaceRootObject data = null;
  25. const string url = "http://ergast.com/api/f1/constructors.json";
  26. HttpWebRequest request = WebRequest.CreateHttp(new Uri(url));
  27. var response = await HttpRequest(request);
  28. if (response != null)
  29. data = JsonConvert.DeserializeObject<RaceRootObject>(response);
  30. return data != null ? data.MRData.ConstructorTable : null;
  31. }
  32. }
  33. }