| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using cwebplusApp.Shared.Models;
- using Json.Net;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Net.Http;
- using System.Threading.Tasks;
-
- namespace cwebplusApp.Shared.Services {
-
- // REST interface responsible to submit lost or found reports and get the available master data.
- public class LFBicycleRest : ILFBicycleRest {
-
- private static readonly string VERSION = "v1";
-
- private readonly HttpClient httpClient;
-
- public LFBicycleRest() {
- this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") };
- }
-
- public async Task<List<ColorItem>> GetColors() {
- HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
-
- if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
- ColorItem[] colors = JsonNet.Deserialize<ColorItem[]>(await httpResult.Content.ReadAsStringAsync());
- return new List<ColorItem>(colors);
- }
- throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
- }
-
- public async Task<List<BicycleType>> GetBicycleTypes() {
- HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/types", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
-
- if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
- BicycleType[] bicycleTypes = JsonNet.Deserialize<BicycleType[]>(await httpResult.Content.ReadAsStringAsync());
- return new List<BicycleType>(bicycleTypes);
- }
- throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
- }
-
- public async Task<List<Brand>> GetBrands() {
- HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/brands", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
-
- if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) {
- Brand[] brands = JsonNet.Deserialize<Brand[]>(await httpResult.Content.ReadAsStringAsync());
- return new List<Brand>(brands);
- }
- throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
- }
-
- }
- }
|