PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LFBicycleRest.cs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using cwebplusApp.Shared.Models;
  2. using Json.Net;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Net.Http;
  7. using System.Threading.Tasks;
  8. namespace cwebplusApp.Shared.Services {
  9. // REST interface responsible to submit lost or found reports and get the available master data.
  10. public class LFBicycleRest : ILFBicycleRest {
  11. private static readonly string VERSION = "v1";
  12. private readonly HttpClient httpClient;
  13. public LFBicycleRest() {
  14. this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") };
  15. }
  16. public async Task<List<ColorItem>> GetColors() {
  17. HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
  18. if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
  19. ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync());
  20. return new List<ColorItem>(colors);
  21. }
  22. throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
  23. }
  24. public async Task<List<BicycleType>> GetBicycleTypes() {
  25. HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/types", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
  26. if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
  27. BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync());
  28. return new List<BicycleType>(bicycleTypes);
  29. }
  30. throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
  31. }
  32. public async Task<List<Brand>> GetBrands() {
  33. HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/brands", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
  34. if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
  35. Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync());
  36. return new List<Brand>(brands);
  37. }
  38. throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
  39. }
  40. }
  41. }