riot_lol_api 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +6 -0
- data/README.md +11 -6
- data/Rakefile +6 -1
- data/curl_import.rb +142 -123
- data/lib/core_ext/hash/riot_lol_api.rb +49 -0
- data/lib/core_ext/string/riot_lol_api.rb +9 -0
- data/lib/riot_lol_api.rb +15 -12
- data/lib/riot_lol_api/clients.rb +58 -325
- data/lib/riot_lol_api/{model/players.rb → concerns/inits.rb} +2 -3
- data/lib/riot_lol_api/helper_classes.rb +2 -5
- data/lib/riot_lol_api/models.rb +5 -3
- data/lib/riot_lol_api/models/aggregated_stats.rb +7 -0
- data/lib/riot_lol_api/models/altimages.rb +7 -0
- data/lib/riot_lol_api/models/banned_champions.rb +7 -0
- data/lib/riot_lol_api/models/bans.rb +7 -0
- data/lib/riot_lol_api/models/blocks.rb +9 -0
- data/lib/riot_lol_api/models/champion_masteries.rb +7 -0
- data/lib/riot_lol_api/models/champions.rb +16 -0
- data/lib/riot_lol_api/models/class_base.rb +7 -0
- data/lib/riot_lol_api/models/creepspermindeltas.rb +7 -0
- data/lib/riot_lol_api/models/csdiffpermindeltas.rb +7 -0
- data/lib/riot_lol_api/models/damagetakendiffpermindeltas.rb +7 -0
- data/lib/riot_lol_api/models/damagetakenpermindeltas.rb +7 -0
- data/lib/riot_lol_api/models/data.rb +7 -0
- data/lib/riot_lol_api/models/effects.rb +7 -0
- data/lib/riot_lol_api/models/entries.rb +7 -0
- data/lib/riot_lol_api/models/fellow_players.rb +7 -0
- data/lib/riot_lol_api/models/game_lists.rb +7 -0
- data/lib/riot_lol_api/models/games.rb +12 -0
- data/lib/riot_lol_api/models/goldpermindeltas.rb +7 -0
- data/lib/riot_lol_api/models/golds.rb +7 -0
- data/lib/riot_lol_api/models/images.rb +17 -0
- data/lib/riot_lol_api/models/infos.rb +7 -0
- data/lib/riot_lol_api/models/items.rb +11 -0
- data/lib/riot_lol_api/models/leagues.rb +10 -0
- data/lib/riot_lol_api/models/leveltips.rb +7 -0
- data/lib/riot_lol_api/{model → models}/maps.rb +4 -7
- data/lib/riot_lol_api/models/masteries.rb +14 -0
- data/lib/riot_lol_api/models/matches.rb +11 -0
- data/lib/riot_lol_api/models/mini_series.rb +7 -0
- data/lib/riot_lol_api/models/observers.rb +7 -0
- data/lib/riot_lol_api/models/pages.rb +11 -0
- data/lib/riot_lol_api/models/participantidentities.rb +7 -0
- data/lib/riot_lol_api/models/participants.rb +7 -0
- data/lib/riot_lol_api/models/passives.rb +9 -0
- data/lib/riot_lol_api/models/player_stat_ranks.rb +9 -0
- data/lib/riot_lol_api/models/player_stat_summaries.rb +9 -0
- data/lib/riot_lol_api/models/players.rb +7 -0
- data/lib/riot_lol_api/models/recommendeds.rb +9 -0
- data/lib/riot_lol_api/models/runes.rb +7 -0
- data/lib/riot_lol_api/models/skins.rb +7 -0
- data/lib/riot_lol_api/models/slots.rb +9 -0
- data/lib/riot_lol_api/models/spells.rb +12 -0
- data/lib/riot_lol_api/{model → models}/stats.rb +3 -10
- data/lib/riot_lol_api/models/summoners.rb +110 -0
- data/lib/riot_lol_api/models/teams.rb +11 -0
- data/lib/riot_lol_api/models/timelines.rb +9 -0
- data/lib/riot_lol_api/models/vars.rb +7 -0
- data/lib/riot_lol_api/models/xpdiffpermindeltas.rb +7 -0
- data/lib/riot_lol_api/models/xppermindeltas.rb +7 -0
- data/lib/riot_lol_api/requests/champion_masteries.rb +11 -0
- data/lib/riot_lol_api/requests/champions.rb +23 -0
- data/lib/riot_lol_api/requests/games.rb +23 -0
- data/lib/riot_lol_api/requests/items.rb +23 -0
- data/lib/riot_lol_api/requests/masteries.rb +23 -0
- data/lib/riot_lol_api/requests/runes.rb +23 -0
- data/lib/riot_lol_api/requests/spells.rb +23 -0
- data/lib/riot_lol_api/requests/summoners.rb +29 -0
- data/lib/riot_lol_api/supports/regions.rb +33 -0
- data/lib/riot_lol_api/version.rb +1 -1
- data/riot_lol_api.gemspec +19 -16
- data/spec/factories/champion.rb +8 -8
- data/spec/factories/client.rb +7 -5
- data/spec/factories/game.rb +18 -18
- data/spec/factories/page.rb +8 -8
- data/spec/factories/summoner.rb +10 -9
- data/spec/mock_response/championmastery_by_summoner.json +7 -0
- data/spec/mock_response/championmastery_by_summoner_by_champion.json +7 -0
- data/spec/mock_response/championmastery_score.json +7 -0
- data/spec/mock_response/championmastery_top.json +7 -0
- data/spec/mock_response/get_all_champions_by_ids.json +4 -5
- data/spec/mock_response/get_all_champions_by_ids_all_data.json +4 -5
- data/spec/mock_response/get_all_item.json +4 -5
- data/spec/mock_response/get_all_masteries.json +5 -6
- data/spec/mock_response/get_all_runes.json +4 -5
- data/spec/mock_response/get_all_summoner_spells.json +5 -6
- data/spec/mock_response/get_all_summoner_spells_by_ids.json +4 -5
- data/spec/mock_response/get_champion_by_id.json +3 -4
- data/spec/mock_response/get_champion_by_id_all_data.json +4 -5
- data/spec/mock_response/get_featured_games.json +7 -7
- data/spec/mock_response/get_item_by_id.json +5 -6
- data/spec/mock_response/get_mastery_by_id.json +5 -6
- data/spec/mock_response/get_match_by_id.json +4 -5
- data/spec/mock_response/get_player_league.json +5 -6
- data/spec/mock_response/get_player_stat_ranked.json +5 -6
- data/spec/mock_response/get_player_stat_summaries.json +5 -6
- data/spec/mock_response/get_realm.json +5 -5
- data/spec/mock_response/get_rune_by_id.json +4 -5
- data/spec/mock_response/get_summoner_by_id.json +5 -6
- data/spec/mock_response/get_summoner_by_name.json +5 -6
- data/spec/mock_response/get_summoner_games_by_id.json +5 -6
- data/spec/mock_response/get_summoner_masteries_by_id.json +5 -6
- data/spec/mock_response/get_summoner_runes_by_id.json +5 -6
- data/spec/mock_response/get_summoner_spell_by_id.json +5 -6
- data/spec/mock_response/get_version.json +5 -6
- data/spec/mock_response/match_list.json +12 -0
- data/spec/mock_response/realm.json +12 -0
- data/spec/mock_response/summoner.json +5 -6
- data/spec/{riot_lol_api_spec.rb → riot_lol_api/riot_lol_api_spec.rb} +135 -164
- data/spec/riot_lol_api/riot_lol_api_supports_spec.rb +8 -0
- data/spec/spec_helper.rb +7 -2
- metadata +144 -77
- data/lib/core_ext/hash.rb +0 -29
- data/lib/core_ext/string.rb +0 -5
- data/lib/riot_lol_api/model/aggregated_stats.rb +0 -14
- data/lib/riot_lol_api/model/altimages.rb +0 -14
- data/lib/riot_lol_api/model/banned_champions.rb +0 -14
- data/lib/riot_lol_api/model/bans.rb +0 -14
- data/lib/riot_lol_api/model/blocks.rb +0 -16
- data/lib/riot_lol_api/model/champions.rb +0 -23
- data/lib/riot_lol_api/model/class_base.rb +0 -14
- data/lib/riot_lol_api/model/creepspermindeltas.rb +0 -14
- data/lib/riot_lol_api/model/csdiffpermindeltas.rb +0 -14
- data/lib/riot_lol_api/model/damagetakendiffpermindeltas.rb +0 -13
- data/lib/riot_lol_api/model/damagetakenpermindeltas.rb +0 -14
- data/lib/riot_lol_api/model/data.rb +0 -14
- data/lib/riot_lol_api/model/effects.rb +0 -14
- data/lib/riot_lol_api/model/entries.rb +0 -14
- data/lib/riot_lol_api/model/fellow_players.rb +0 -14
- data/lib/riot_lol_api/model/game_lists.rb +0 -14
- data/lib/riot_lol_api/model/games.rb +0 -19
- data/lib/riot_lol_api/model/goldpermindeltas.rb +0 -14
- data/lib/riot_lol_api/model/golds.rb +0 -14
- data/lib/riot_lol_api/model/images.rb +0 -24
- data/lib/riot_lol_api/model/infos.rb +0 -14
- data/lib/riot_lol_api/model/items.rb +0 -18
- data/lib/riot_lol_api/model/leagues.rb +0 -17
- data/lib/riot_lol_api/model/leveltips.rb +0 -14
- data/lib/riot_lol_api/model/masteries.rb +0 -30
- data/lib/riot_lol_api/model/matches.rb +0 -18
- data/lib/riot_lol_api/model/mini_series.rb +0 -14
- data/lib/riot_lol_api/model/observers.rb +0 -14
- data/lib/riot_lol_api/model/pages.rb +0 -18
- data/lib/riot_lol_api/model/participantidentities.rb +0 -13
- data/lib/riot_lol_api/model/participants.rb +0 -14
- data/lib/riot_lol_api/model/passives.rb +0 -16
- data/lib/riot_lol_api/model/player_stat_ranks.rb +0 -16
- data/lib/riot_lol_api/model/player_stat_summaries.rb +0 -16
- data/lib/riot_lol_api/model/recommendeds.rb +0 -16
- data/lib/riot_lol_api/model/runes.rb +0 -14
- data/lib/riot_lol_api/model/skins.rb +0 -14
- data/lib/riot_lol_api/model/slots.rb +0 -16
- data/lib/riot_lol_api/model/spells.rb +0 -19
- data/lib/riot_lol_api/model/summoners.rb +0 -160
- data/lib/riot_lol_api/model/teams.rb +0 -18
- data/lib/riot_lol_api/model/timelines.rb +0 -16
- data/lib/riot_lol_api/model/vars.rb +0 -14
- data/lib/riot_lol_api/model/xpdiffpermindeltas.rb +0 -14
- data/lib/riot_lol_api/model/xppermindeltas.rb +0 -14
- data/spec/mock_response/get_match_history.json +0 -13
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module CoreExt
|
4
|
+
module Hash
|
5
|
+
module RiotLolApi
|
6
|
+
|
7
|
+
def lol_symbolize
|
8
|
+
new_hash = {}
|
9
|
+
each do |k, v|
|
10
|
+
if v.is_a? Array
|
11
|
+
populate_new_hash_from_array(new_hash: new_hash, key: k, values: v)
|
12
|
+
elsif v.is_a? ::Hash
|
13
|
+
new_hash[k.lol_symbolize] = initalize_lol_object(name_class: classify(k), values: v)
|
14
|
+
else
|
15
|
+
new_hash[k.lol_symbolize] = v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
new_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def populate_new_hash_from_array(new_hash:, key:, values:)
|
24
|
+
key_sym = key.lol_symbolize
|
25
|
+
new_hash[key_sym] = []
|
26
|
+
return populate_new_hash_with_lol_object(new_hash: new_hash, key: key, values: values) if values.first.is_a? ::Hash
|
27
|
+
values.each do |tab|
|
28
|
+
new_hash[key_sym] << tab
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def populate_new_hash_with_lol_object(new_hash:, key:, values:)
|
33
|
+
name_class = classify key
|
34
|
+
values.each do |tab|
|
35
|
+
new_hash[key.lol_symbolize] << initalize_lol_object(name_class: name_class, values: tab)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initalize_lol_object(name_class:, values:)
|
40
|
+
Object.const_get("::RiotLolApi::Model::#{name_class}").new(values.lol_symbolize)
|
41
|
+
end
|
42
|
+
|
43
|
+
def classify(name)
|
44
|
+
name.singularize.camelize
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/riot_lol_api.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require 'riot_lol_api/version'
|
2
|
+
require 'riot_lol_api/helper_classes'
|
3
|
+
require 'riot_lol_api/clients'
|
4
|
+
require 'riot_lol_api/models'
|
5
|
+
require 'core_ext/string/riot_lol_api'
|
6
|
+
require 'core_ext/hash/riot_lol_api'
|
7
|
+
require 'riot_lol_api/models/class_base'
|
8
|
+
|
9
|
+
Hash.include CoreExt::Hash::RiotLolApi
|
10
|
+
String.include CoreExt::String::RiotLolApi
|
8
11
|
|
9
12
|
module RiotLolApi
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
# # http://ddragon.leagueoflegends.com/tool/euw/fr_FR
|
14
|
+
# RiotLolApi::RATE_LIMIT = 0
|
15
|
+
# RiotLolApi::RATE_LIMIT_REQ_MAX = 10
|
16
|
+
# RiotLolApi::RATE_LIMIT_SEC_MAX = 10
|
17
|
+
# RiotLolApi::RATE_LIMIT_RESET_DATE = Time.now
|
15
18
|
end
|
data/lib/riot_lol_api/clients.rb
CHANGED
@@ -1,330 +1,63 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
|
+
require 'riot_lol_api/requests/summoners'
|
4
|
+
require 'riot_lol_api/requests/champions'
|
5
|
+
require 'riot_lol_api/requests/items'
|
6
|
+
require 'riot_lol_api/requests/masteries'
|
7
|
+
require 'riot_lol_api/requests/runes'
|
8
|
+
require 'riot_lol_api/requests/spells'
|
9
|
+
require 'riot_lol_api/requests/games'
|
10
|
+
require 'riot_lol_api/requests/champion_masteries'
|
3
11
|
|
4
12
|
module RiotLolApi
|
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
|
-
else
|
56
|
-
data.merge!({:api_key => RiotLolApi::TOKEN})
|
57
|
-
end
|
58
|
-
|
59
|
-
# Set domaine url
|
60
|
-
domaine_url = "#{domaine}.#{overide_base_uri||BASE_URL_API}"
|
61
|
-
response = HTTParty.get("https://#{domaine_url}#{url}", :query => data)
|
62
|
-
case response.code
|
63
|
-
when 200
|
64
|
-
JSON.parse(response.body)
|
65
|
-
when 404
|
66
|
-
puts "Error server"
|
67
|
-
nil
|
68
|
-
when 500...600
|
69
|
-
puts "ERROR #{response.code}"
|
70
|
-
nil
|
71
|
-
end
|
72
|
-
else
|
73
|
-
puts "No TOKEN, you have to define RiotLolApi::TOKEN"
|
74
|
-
nil
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# SUMMONER
|
79
|
-
|
80
|
-
def get_summoner_by_name name
|
81
|
-
name = name.downcase
|
82
|
-
name.strip!
|
83
|
-
response = Client.get("#{@region}/v1.4/summoner/by-name/#{name}",@region)
|
84
|
-
unless response.nil?
|
85
|
-
RiotLolApi::Model::Summoner.new(response[name].to_symbol.merge({:region => @region}))
|
86
|
-
else
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def get_summoner_by_id id
|
92
|
-
response = Client.get("#{@region}/v1.4/summoner/#{id}",@region)
|
93
|
-
unless response.nil?
|
94
|
-
RiotLolApi::Model::Summoner.new(response[id.to_s].to_symbol.merge({:region => @region}))
|
95
|
-
else
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def get_summoners_by_id id
|
101
|
-
response = Client.get("#{@region}/v1.4/summoner/#{id}",@region)
|
102
|
-
unless response.nil?
|
103
|
-
summoners = Array.new
|
104
|
-
response.each do |id, data|
|
105
|
-
summoners << RiotLolApi::Model::Summoner.new(response[data['id'].to_s].to_symbol.merge({:region => @region}))
|
106
|
-
end
|
107
|
-
summoners
|
108
|
-
else
|
109
|
-
nil
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# CHAMPION
|
114
|
-
|
115
|
-
def get_champion_by_id id, data = nil, locale = 'en_US'
|
116
|
-
if data.nil?
|
117
|
-
data = {:locale => locale}
|
118
|
-
else
|
119
|
-
data.merge!({:locale => locale})
|
120
|
-
end
|
121
|
-
|
122
|
-
response = Client.get("static-data/#{@region}/v1.2/champion/#{id}","global",data)
|
123
|
-
unless response.nil?
|
124
|
-
RiotLolApi::Model::Champion.new(response.to_symbol)
|
125
|
-
else
|
126
|
-
nil
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def get_all_champions data = nil, sort_id = 'false', locale = 'en_US'
|
131
|
-
if data.nil?
|
132
|
-
data = {:locale => locale, :dataById => sort_id}
|
133
|
-
else
|
134
|
-
data.merge!({:locale => locale, :dataById => sort_id})
|
135
|
-
end
|
136
|
-
|
137
|
-
response = Client.get("static-data/#{@region}/v1.2/champion","global",data)
|
138
|
-
unless response.nil?
|
139
|
-
tab_champions = Array.new
|
140
|
-
response["data"].each do |champion|
|
141
|
-
tab_champions << RiotLolApi::Model::Champion.new(champion[1].to_symbol)
|
142
|
-
end
|
143
|
-
tab_champions
|
144
|
-
else
|
145
|
-
nil
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# ITEM
|
150
|
-
|
151
|
-
def get_all_items data = nil, locale = 'en_US'
|
152
|
-
if data.nil?
|
153
|
-
data = {:locale => locale}
|
154
|
-
else
|
155
|
-
data.merge!({:locale => locale})
|
156
|
-
end
|
157
|
-
|
158
|
-
response = Client.get("static-data/#{@region}/v1.2/item","global",data)
|
159
|
-
unless response.nil?
|
160
|
-
tab_items = Array.new
|
161
|
-
response["data"].each do |item|
|
162
|
-
tab_items << RiotLolApi::Model::Item.new(item[1].to_symbol)
|
163
|
-
end
|
164
|
-
tab_items
|
165
|
-
else
|
166
|
-
nil
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_item_by_id id, data = nil, locale = 'en_US'
|
171
|
-
if data.nil?
|
172
|
-
data = {:locale => locale}
|
173
|
-
else
|
174
|
-
data.merge!({:locale => locale})
|
175
|
-
end
|
176
|
-
|
177
|
-
response = Client.get("static-data/#{@region}/v1.2/item/#{id}","global",data)
|
178
|
-
unless response.nil?
|
179
|
-
RiotLolApi::Model::Item.new(response.to_symbol)
|
180
|
-
else
|
181
|
-
nil
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# MASTERY
|
186
|
-
|
187
|
-
def get_all_masteries data = nil, locale = 'en_US'
|
188
|
-
if data.nil?
|
189
|
-
data = {:locale => locale}
|
190
|
-
else
|
191
|
-
data.merge!({:locale => locale})
|
192
|
-
end
|
193
|
-
|
194
|
-
response = Client.get("static-data/#{@region}/v1.2/mastery","global",data)
|
195
|
-
unless response.nil?
|
196
|
-
tab_masteries = Array.new
|
197
|
-
response["data"].each do |mastery|
|
198
|
-
tab_masteries << RiotLolApi::Model::Mastery.new(mastery[1].to_symbol)
|
199
|
-
end
|
200
|
-
tab_masteries
|
201
|
-
else
|
202
|
-
nil
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def get_mastery_by_id id, data = nil, locale = 'en_US'
|
207
|
-
if data.nil?
|
208
|
-
data = {:locale => locale}
|
209
|
-
else
|
210
|
-
data.merge!({:locale => locale})
|
211
|
-
end
|
212
|
-
|
213
|
-
response = Client.get("static-data/#{@region}/v1.2/mastery/#{id}","global",data)
|
214
|
-
unless response.nil?
|
215
|
-
RiotLolApi::Model::Mastery.new(response.to_symbol)
|
216
|
-
else
|
217
|
-
nil
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
# RUNE
|
222
|
-
|
223
|
-
def get_all_runes data = nil, locale = 'en_US'
|
224
|
-
if data.nil?
|
225
|
-
data = {:locale => locale}
|
226
|
-
else
|
227
|
-
data.merge!({:locale => locale})
|
228
|
-
end
|
229
|
-
|
230
|
-
response = Client.get("static-data/#{@region}/v1.2/rune","global",data)
|
231
|
-
unless response.nil?
|
232
|
-
tab_runes = Array.new
|
233
|
-
response["data"].each do |rune|
|
234
|
-
tab_runes << RiotLolApi::Model::Rune.new(rune[1].to_symbol)
|
235
|
-
end
|
236
|
-
tab_runes
|
237
|
-
else
|
238
|
-
nil
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def get_rune_by_id id, data = nil, locale = 'en_US'
|
243
|
-
if data.nil?
|
244
|
-
data = {:locale => locale}
|
245
|
-
else
|
246
|
-
data.merge!({:locale => locale})
|
247
|
-
end
|
248
|
-
|
249
|
-
response = Client.get("static-data/#{@region}/v1.2/rune/#{id}","global",data)
|
250
|
-
unless response.nil?
|
251
|
-
RiotLolApi::Model::Rune.new(response.to_symbol)
|
252
|
-
else
|
253
|
-
nil
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
# SUMMONER SPELL
|
258
|
-
|
259
|
-
def get_all_summoner_spells data = nil, sort_id = 'false', locale = 'en_US'
|
260
|
-
if data.nil?
|
261
|
-
data = {:locale => locale, :dataById => sort_id}
|
262
|
-
else
|
263
|
-
data.merge!({:locale => locale, :dataById => sort_id})
|
264
|
-
end
|
265
|
-
|
266
|
-
response = Client.get("static-data/#{@region}/v1.2/summoner-spell","global",data)
|
267
|
-
unless response.nil?
|
268
|
-
tab_summoner_spells = Array.new
|
269
|
-
response["data"].each do |summoner_spell|
|
270
|
-
tab_summoner_spells << RiotLolApi::Model::Spell.new(summoner_spell[1].to_symbol)
|
271
|
-
end
|
272
|
-
tab_summoner_spells
|
273
|
-
else
|
274
|
-
nil
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
def get_summoner_spell_by_id id, data = nil, locale = 'en_US'
|
279
|
-
if data.nil?
|
280
|
-
data = {:locale => locale}
|
281
|
-
else
|
282
|
-
data.merge!({:locale => locale})
|
283
|
-
end
|
284
|
-
|
285
|
-
response = Client.get("static-data/#{@region}/v1.2/summoner-spell/#{id}","global",data)
|
286
|
-
unless response.nil?
|
287
|
-
RiotLolApi::Model::Spell.new(response.to_symbol)
|
288
|
-
else
|
289
|
-
nil
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
def featured_games
|
294
|
-
response = Client.get("observer-mode/rest/featured",@region,nil,'api.pvp.net/')
|
295
|
-
unless response.nil?
|
296
|
-
RiotLolApi::Model::Observer.new(response.to_symbol)
|
297
|
-
else
|
298
|
-
nil
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
def current_game summoner_id, platform_id='EUW1'
|
303
|
-
response = Client.get("observer-mode/rest/consumer/getSpectatorGameInfo/#{platform_id}/#{summoner_id}",@region,nil,'api.pvp.net/')
|
304
|
-
unless response.nil?
|
305
|
-
RiotLolApi::Model::Game.new(response.to_symbol)
|
306
|
-
else
|
307
|
-
nil
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
def match game_id
|
312
|
-
response = Client.get("#{@region}/v2.2/match/#{game_id}",@region)
|
313
|
-
unless response.nil?
|
314
|
-
RiotLolApi::Model::Match.new(response.to_symbol)
|
315
|
-
else
|
316
|
-
nil
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
def get_versions
|
321
|
-
response = Client.get("static-data/#{@region}/v1.2/versions","global")
|
322
|
-
unless response.nil?
|
323
|
-
response
|
324
|
-
else
|
325
|
-
nil
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
end
|
13
|
+
class Client
|
14
|
+
include RiotLolApi::HelperClass
|
15
|
+
include RiotLolApi::Request::Summoner
|
16
|
+
include RiotLolApi::Request::Champion
|
17
|
+
include RiotLolApi::Request::Item
|
18
|
+
include RiotLolApi::Request::Mastery
|
19
|
+
include RiotLolApi::Request::Rune
|
20
|
+
include RiotLolApi::Request::Spell
|
21
|
+
include RiotLolApi::Request::Game
|
22
|
+
include RiotLolApi::Request::ChampionMastery
|
23
|
+
|
24
|
+
BASE_URL_API = 'api.pvp.net/api/lol/'
|
25
|
+
|
26
|
+
attr_accessor :region, :api_key, :platform
|
27
|
+
|
28
|
+
def initialize(options = {})
|
29
|
+
options.each do |key, value|
|
30
|
+
instance_variable_set("@#{key}", value)
|
31
|
+
end
|
32
|
+
yield(self) if block_given?
|
33
|
+
@platform = platform unless region.nil?
|
34
|
+
realm unless region.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
attr_accessor :realm
|
39
|
+
end
|
40
|
+
|
41
|
+
def realm
|
42
|
+
response = get(url: "static-data/#{region}/v1.2/realm", domaine: 'global')
|
43
|
+
self.class.realm = response unless response.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def platform
|
47
|
+
RiotLolApi::Support::Region.new(@region).platform
|
48
|
+
end
|
49
|
+
|
50
|
+
def versions
|
51
|
+
get(url: "static-data/#{@region}/v1.2/versions", domaine: 'global')
|
52
|
+
end
|
53
|
+
|
54
|
+
def get(url:, domaine:, data: {}, overide_base_uri: BASE_URL_API)
|
55
|
+
return fail('need api key') if @api_key.nil?
|
56
|
+
data.merge!(api_key: @api_key)
|
57
|
+
domaine_url = "#{domaine}.#{overide_base_uri}"
|
58
|
+
response = HTTParty.get("https://#{domaine_url}#{url}", query: data)
|
59
|
+
return JSON.parse(response.body) if response.code == 200
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
330
63
|
end
|