-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataFetcher.cs
53 lines (42 loc) · 1.33 KB
/
DataFetcher.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.Json;
using PokeNetApi.Objects;
namespace PokeNetApi
{
/// <summary>
/// Fetches actual object representations of data from PokeAPI
/// </summary>
public class DataFetcher
{
HttpBackend backend = new HttpBackend();
/// <summary>
/// Returns raw string data from a given path in PokeAPI
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public async Task<string> GetDataAsync(string path)
{
return await backend.GetStringAsync(path);
}
/// <summary>
/// Returns Pokemon instance of the pokemon at the given path in PokeAPI
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public async Task<Pokemon> GetPokemonAsync(string path)
{
Stream jsonStream = await backend.GetStreamAsync(path);
JsonSerializerOptions options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
Pokemon pokemon = await JsonSerializer.DeserializeAsync<Pokemon>(jsonStream, options);
return pokemon;
}
}
}