This commit is contained in:
2020-02-26 21:50:58 +01:00
parent 78c21ade79
commit 64cdaf8e9f
15 changed files with 353 additions and 66 deletions

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using EstusShots.Shared.Models;
namespace EstusShots.Client
{
public class EstusShotsClient
{
private readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
};
private string ApiUrl { get; }
private HttpClient HttpClient { get; }
public EstusShotsClient(string apiUrl)
{
ApiUrl = apiUrl;
HttpClient = new HttpClient {Timeout = TimeSpan.FromSeconds(10)};
}
public async Task<List<Season>> GetSeasons()
{
var response = HttpClient.GetAsync(ApiUrl + "seasons").Result;
var jsonData = await response.Content.ReadAsStringAsync();
var data = JsonSerializer.Deserialize<List<Season>>(jsonData, _serializerOptions);
return data;
}
}
}