-
Notifications
You must be signed in to change notification settings - Fork 1
/
Request.cs
35 lines (28 loc) · 901 Bytes
/
Request.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Shared.Exceptions;
using System.Net.Http;
using System.Threading.Tasks;
using System.Text.Json;
namespace DDragonAccessLayer
{
class Requests
{
private const string ROOT_URI = "https://ddragon.leagueoflegends.com";
private readonly HttpClient client = new HttpClient();
public Requests()
{
client.DefaultRequestHeaders.Add("User-Agent", "MasteryPointsStats Crawler Service");
}
public async Task<T> Get<T>(
string path)
{
var res = await client.GetAsync($"{ROOT_URI}/{path}");
if (!res.IsSuccessStatusCode)
{
throw new ResponseException(res);
}
var bodyStream = await res.Content.ReadAsStreamAsync();
var data = await JsonSerializer.DeserializeAsync<T>(bodyStream);
return data;
}
}
}