-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRiotAPI.vb
193 lines (166 loc) · 9.42 KB
/
RiotAPI.vb
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
Imports System.Net
Imports System.Web
Imports System.IO
Imports System.Reflection
Imports Newtonsoft.Json.Linq
Imports System.Xml
Imports Newtonsoft
Public Class RiotAPI
Shared key As String
Shared apiVersion As Integer
Shared dt As String = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")
Shared methodName As String
Shared API_URL_PLATFORM As String = "https://{0}.api.riotgames.com/lol/platform/v{1}/"
Shared API_URL_CHAMPION_MASTERY As String = "https://{0}.api.riotgames.com/lol/champion-mastery/v{1}/"
Shared API_URL_SPECTATOR As String = "https://{0}.api.riotgames.com/lol/spectator/v{1}/"
Shared API_URL_STATIC As String = "https://{0}.api.riotgames.com/lol/static-data/v{1}/"
Shared API_URL_MATCH As String = "https://{0}.api.riotgames.com/lol/match/v{1}/"
Shared API_URL_LEAGUE As String = "https://{0}.api.riotgames.com/lol/league/v{1}/"
Shared API_URL_SUMMONER As String = "https://{0}.api.riotgames.com/lol/summoner/v{1}/"
Public Sub New(apiKey As String, apiver As Integer)
key = apiKey
apiVersion = apiver
End Sub
#Region "Misc"
Shared Sub AddCache(url As String)
'Dim file As System.IO.StreamWriter
'File = My.Computer.FileSystem.OpenTextFileWriter("Cache/" & dt & "-" & methodName & ".json", True)
'File.WriteLine(JValue.Parse(request(url)).ToString(Formatting.Indented))
'File.Close()
End Sub
Public Shared Function request(ByVal url As String) As String
Dim req As WebRequest = WebRequest.Create(url)
req.Headers.Add("X-Riot-Token", key)
Dim res As System.Net.WebResponse = req.GetResponse()
Using stream As System.IO.Stream = res.GetResponseStream()
Dim sr As New System.IO.StreamReader(stream, Text.Encoding.GetEncoding("utf-8"))
Dim r = sr.ReadToEnd()
Return r
End Using
End Function
Public Shared Function getChampions(patch As String) As Champions
Dim req As WebRequest = WebRequest.Create("http://ddragon.leagueoflegends.com/cdn/" & patch & "/data/en_US/champion.json")
Dim res As System.Net.WebResponse = req.GetResponse()
Using stream As System.IO.Stream = res.GetResponseStream()
Dim sr As New System.IO.StreamReader(stream, Text.Encoding.GetEncoding("utf-8"))
Dim r As String = sr.ReadToEnd()
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of Champions)(r)
End Using
End Function
Public Function getAllGameData() As AllGameDataDTO
System.Net.ServicePointManager.ServerCertificateValidationCallback = Function(senderX, certificate, chain, sslPolicyErrors)
Return True
End Function
Dim req As WebRequest = WebRequest.Create("https://127.0.0.1:2999/liveclientdata/allgamedata")
Dim res As System.Net.WebResponse = req.GetResponse()
Using stream As System.IO.Stream = res.GetResponseStream()
Dim sr As New System.IO.StreamReader(stream, Text.Encoding.GetEncoding("utf-8"))
Dim r As String = sr.ReadToEnd()
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of AllGameDataDTO)(r)
End Using
End Function
Public Function getVersion() As List(Of String)
Dim req As WebRequest = WebRequest.Create("https://ddragon.leagueoflegends.com/api/versions.json")
Dim res As System.Net.WebResponse = req.GetResponse()
Using stream As System.IO.Stream = res.GetResponseStream()
Dim sr As New System.IO.StreamReader(stream, Text.Encoding.GetEncoding("utf-8"))
Dim r As String = sr.ReadToEnd()
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of String))(r)
End Using
End Function
#End Region
#Region "Summoner"
Public Function GetSummonerByName(ByVal name As String, ByVal platform As String) As SummonerDTO
Dim api_call As String = "summoners/by-name/" & name & ""
Dim url As String = String.Format(API_URL_SUMMONER, platform, apiVersion) + api_call
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Json.JsonConvert.DeserializeObject(Of SummonerDTO)(request(url))
End Function
Public Function GetSummoners(encryptedSummonerId As String, ByVal platform As String) As SummonerDTO
Dim api_call = "summoners/"
Dim url As String = String.Format(API_URL_SUMMONER, platform, apiVersion) + api_call + encryptedSummonerId
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of SummonerDTO)(request(url))
End Function
Public Function GetSummonersByAccount(encryptedAccountId As String, ByVal platform As String) As SummonerDTO
Dim api_call = "summoners/by-account/"
Dim url As String = String.Format(API_URL_SUMMONER, platform, apiVersion) + api_call + encryptedAccountId
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of SummonerDTO)(request(url))
End Function
Public Function GetSummonersByPUUID(encryptedPUUID As String, ByVal platform As String) As SummonerDTO
Dim api_call = "summoners/by-puuid/"
Dim url As String = String.Format(API_URL_SUMMONER, platform, apiVersion) + api_call + encryptedPUUID
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of SummonerDTO)(request(url))
End Function
#End Region
#Region "Matches"
Public Function GetMatches(matchId As String, ByVal platform As String) As MatchDTO
Dim api_call = "matches/"
Dim url = String.Format(API_URL_MATCH, platform, apiVersion) + api_call + matchId
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of MatchDTO)(request(url))
End Function
Public Function GetMatchlistsByAccountID(encryptedAccountId As String, ByVal platform As String)
Dim api_call = "matchlists/by-account/"
Dim url = String.Format(API_URL_MATCH, platform, apiVersion) + api_call + encryptedAccountId
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(request(url))
End Function
Public Function GetTimelinesByMatch(matchId As String, ByVal platform As String) As MatchTimelineDTO
Dim api_call = "timelines/by-match/"
Dim url = String.Format(API_URL_MATCH, platform, apiVersion) + api_call + matchId
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of MatchTimelineDTO)(request(url))
End Function
#End Region
#Region "Champion Mastery"
Public Function GetChampionMasteryBySummoner(encryptedSummonerId As String, ByVal platform As String) As List(Of ChampionMasteryDTO)
Dim api_call = "champion-masteries/by-summoner/"
Dim url = String.Format(API_URL_CHAMPION_MASTERY, platform, apiVersion) + api_call + encryptedSummonerId
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of ChampionMasteryDTO))(request(url))
End Function
Public Function GetChampionMasteryBySummonerAndChampionId(encryptedSummonerId As String, championId As Integer, ByVal platform As String) As ChampionMasteryDTO
Dim api_call = "champion-masteries/by-summoner/" + encryptedSummonerId + "/by-champion/" + championId.ToString
Dim url = String.Format(API_URL_CHAMPION_MASTERY, platform, apiVersion) + api_call
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of ChampionMasteryDTO)(request(url))
End Function
Public Function GetScoresBySummoner(encryptedSummonerId As String) As Integer
Dim api_call = "scores/by-summoner/" + encryptedSummonerId
Dim url = API_URL_CHAMPION_MASTERY + api_call
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return request(url)
End Function
#End Region
#Region "League"
Public Function GetLeagueBySummonerID(ByVal id As String, ByVal platform As String)
Dim api_call As String = "entries/by-summoner/" & id & ""
Dim url As String = String.Format(API_URL_LEAGUE, platform, apiVersion) + api_call
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of LeagueEntryDTO))(request(url))
End Function
#End Region
#Region "Spectator"
Public Function SpectateActiveGame(ByVal id As String, ByVal platform As String) As CurrentGameInfoDTO
Dim api_call As String = "active-games/by-summoner/" & id & ""
Dim url As String = String.Format(API_URL_SPECTATOR, platform, apiVersion) + api_call
methodName = System.Reflection.MethodBase.GetCurrentMethod().Name
AddCache(url)
Return Json.JsonConvert.DeserializeObject(Of CurrentGameInfoDTO)(request(url))
End Function
#End Region
End Class