/
GameClient.jl
175 lines (156 loc) · 5.99 KB
/
GameClient.jl
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
module GameClient # LOLTools
using HTTP, JSON2
function http_action(verb, endpoint::HTTP.URI, path::String, headers::Vector{Pair{String,String}}=Vector{Pair{String,String}}(), query::Union{Nothing,Dict{String,String}}=nothing, body=nothing)
url = string(merge(endpoint, path=path))
sc = HTTP.Servers.SSLConfig(false)
args = (query=query, sslconfig=sc)
if body === nothing
verb(url, headers; args...)
else
verb(url, headers; body=body, args...)
end
end
function lol_replay_server(; host="127.0.0.1", port=2999)::HTTP.URI
merge(HTTP.URI("https://"), host=host, port=port, path="/")
end
function call_api(endpoint::HTTP.URI, action::Function, path::String)
resp = action(HTTP.get, endpoint, path)
data = JSON2.read(IOBuffer(resp.body))
end
function call_api(endpoint::HTTP.URI, action::Function, path::String, data)
headers = ["Content-Type" => "application/json"]
body = JSON2.write(data)
resp = action(HTTP.post, endpoint, path, headers, nothing, body)
data = JSON2.read(IOBuffer(resp.body))
end
"""
replay_game( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_game( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/game")
end
"""
replay_particles( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_particles( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/particles")
end
"""
replay_particles(particles ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_particles(particles ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/particles", particles)
end
"""
replay_playback( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_playback( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/playback")
end
"""
replay_playback(playback ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_playback(playback ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/playback", playback)
end
"""
replay_render( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_render( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/render")
end
"""
replay_render(render ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_render(render ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/render", render)
end
"""
replay_recording( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_recording( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/recording")
end
"""
replay_recording(recording ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_recording(recording ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/recording", recording)
end
"""
replay_sequence( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_sequence( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/sequence")
end
"""
replay_sequence(sequence ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function replay_sequence(sequence ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/replay/sequence", sequence)
end
"""
swagger_v2_swagger( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function swagger_v2_swagger( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/swagger/v2/swagger.json")
end
"""
swagger_v3_openapi( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
"""
function swagger_v3_openapi( ;
endpoint::HTTP.URI = lol_replay_server(),
action::Function = http_action)
data = call_api(endpoint, action, "/swagger/v3/openapi.json")
end
end # module LOLTools.GameClient