|
|
|
@@ -1,5 +1,7 @@ |
|
|
|
using cwebplusApp.Shared.Models;
|
|
|
|
using Json.Net;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
@@ -13,40 +15,66 @@ namespace cwebplusApp.Shared.Services { |
|
|
|
|
|
|
|
private static readonly string VERSION = "v1";
|
|
|
|
|
|
|
|
private readonly HttpClient httpClient;
|
|
|
|
private HttpClient httpClient;
|
|
|
|
[Inject]
|
|
|
|
public IConfiguration Configuration { get; set; }
|
|
|
|
|
|
|
|
public LFBicycleRest() {
|
|
|
|
this.httpClient = new HttpClient { BaseAddress = new Uri("https://integrate.dynalias.net:9443/Fundvelo/") };
|
|
|
|
public void Initialize(IConfiguration configuration) {
|
|
|
|
this.Configuration = configuration;
|
|
|
|
string hostBaseUrl = Configuration.GetValue<string>("host_base_url");
|
|
|
|
Console.WriteLine("host_base_url: " + hostBaseUrl);
|
|
|
|
|
|
|
|
if (!String.IsNullOrEmpty(hostBaseUrl)) {
|
|
|
|
this.httpClient = new HttpClient { BaseAddress = new Uri(hostBaseUrl) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<List<ColorItem>> GetColors() {
|
|
|
|
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/colors", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
|
|
|
|
if (httpClient != null) {
|
|
|
|
string subResourceUrl = Configuration.GetValue<string>("subresource_url_colors");
|
|
|
|
if (!String.IsNullOrEmpty(subResourceUrl)) {
|
|
|
|
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
|
|
|
|
throw new HttpRequestException("HTTP client not initialized!");
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<List<BicycleType>> GetBicycleTypes() {
|
|
|
|
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/types", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
|
|
|
|
if (httpClient != null) {
|
|
|
|
string subResourceUrl = Configuration.GetValue<string>("subresource_url_types");
|
|
|
|
if (!String.IsNullOrEmpty(subResourceUrl)) {
|
|
|
|
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
|
|
|
|
throw new HttpRequestException("HTTP client not initialized!");
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<List<Brand>> GetBrands() {
|
|
|
|
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format("api/{0}/{1}/fundvelo/brands", VERSION, CultureInfo.CurrentCulture.TwoLetterISOLanguageName));
|
|
|
|
if (httpClient != null) {
|
|
|
|
string subResourceUrl = Configuration.GetValue<string>("subresource_url_brands");
|
|
|
|
if (!String.IsNullOrEmpty(subResourceUrl)) {
|
|
|
|
HttpResponseMessage httpResult = await httpClient.GetAsync(string.Format(subResourceUrl, 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new HttpRequestException("HTTP error " + httpResult.StatusCode);
|
|
|
|
throw new HttpRequestException("HTTP client not initialized!");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|