-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrawlSharpClient.cs
129 lines (117 loc) · 3.18 KB
/
BrawlSharpClient.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using BrawlSharp.Model;
using BrawlSharp.Model.Leaderboard;
using BrawlSharp.Model.Player.BattleLog;
using RestSharp;
using System.Threading.Tasks;
namespace BrawlSharp
{
public class BrawlSharpClient
{
readonly RestClient client;
public BrawlSharpClient(string token)
{
client = new RestClient("https://api.brawlstars.com/v1");
client.AddDefaultHeader("User-Agent", "BrawlSharp/2.0.0");
client.AddDefaultHeader("Authorization", $"Bearer {token}");
}
public async Task<Model.Player.Player> GetPlayerAsync(string tag)
{
try
{
return await client.GetJsonAsync<Model.Player.Player>($"/players/%23{tag}");
}
catch
{
throw;
}
}
public async Task<BattleLog> GetPlayerBattleLogAsync(string tag)
{
try
{
return await client.GetJsonAsync<BattleLog>($"/players/%23{tag}/battlelog");
}
catch
{
throw;
}
}
public async Task<Model.Club.Club> GetClubAsync(string tag)
{
try
{
return await client.GetJsonAsync<Model.Club.Club>($"/clubs/%23{tag}");
}
catch
{
throw;
}
}
public async Task<PlayerRankings> GetPlayerLeaderboardAsync(string country = "global")
{
try
{
return await client.GetJsonAsync<PlayerRankings>($"/rankings/{country}/players");
}
catch
{
throw;
}
}
public async Task<ClubRankings> GetClubLeaderboardAsync(string country = "global")
{
try
{
return await client.GetJsonAsync<ClubRankings>($"/rankings/{country}/clubs");
}
catch
{
throw;
}
}
public async Task<PlayerRankings> GetBrawlerLeaderboardAsync(int brawler, string country = "global")
{
try
{
return await client.GetJsonAsync<PlayerRankings>($"/rankings/{country}/brawlers/{brawler}");
}
catch
{
throw;
}
}
public async Task<AllBrawlers> GetBrawlersAsync()
{
try
{
return await client.GetJsonAsync<AllBrawlers>("/brawlers");
}
catch
{
throw;
}
}
public async Task<Model.Brawler> GetBrawlerAsync(int brawler)
{
try
{
return await client.GetJsonAsync<Model.Brawler>($"/brawlers/{brawler}");
}
catch
{
throw;
}
}
public async Task<Event[]> GetEventsAsync()
{
try
{
return await client.GetJsonAsync<Event[]>("/events/rotation");
}
catch
{
throw;
}
}
}
}