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.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +5 -0
  4. data/.travis.yml +6 -0
  5. data/README.md +11 -6
  6. data/Rakefile +6 -1
  7. data/curl_import.rb +142 -123
  8. data/lib/core_ext/hash/riot_lol_api.rb +49 -0
  9. data/lib/core_ext/string/riot_lol_api.rb +9 -0
  10. data/lib/riot_lol_api.rb +15 -12
  11. data/lib/riot_lol_api/clients.rb +58 -325
  12. data/lib/riot_lol_api/{model/players.rb → concerns/inits.rb} +2 -3
  13. data/lib/riot_lol_api/helper_classes.rb +2 -5
  14. data/lib/riot_lol_api/models.rb +5 -3
  15. data/lib/riot_lol_api/models/aggregated_stats.rb +7 -0
  16. data/lib/riot_lol_api/models/altimages.rb +7 -0
  17. data/lib/riot_lol_api/models/banned_champions.rb +7 -0
  18. data/lib/riot_lol_api/models/bans.rb +7 -0
  19. data/lib/riot_lol_api/models/blocks.rb +9 -0
  20. data/lib/riot_lol_api/models/champion_masteries.rb +7 -0
  21. data/lib/riot_lol_api/models/champions.rb +16 -0
  22. data/lib/riot_lol_api/models/class_base.rb +7 -0
  23. data/lib/riot_lol_api/models/creepspermindeltas.rb +7 -0
  24. data/lib/riot_lol_api/models/csdiffpermindeltas.rb +7 -0
  25. data/lib/riot_lol_api/models/damagetakendiffpermindeltas.rb +7 -0
  26. data/lib/riot_lol_api/models/damagetakenpermindeltas.rb +7 -0
  27. data/lib/riot_lol_api/models/data.rb +7 -0
  28. data/lib/riot_lol_api/models/effects.rb +7 -0
  29. data/lib/riot_lol_api/models/entries.rb +7 -0
  30. data/lib/riot_lol_api/models/fellow_players.rb +7 -0
  31. data/lib/riot_lol_api/models/game_lists.rb +7 -0
  32. data/lib/riot_lol_api/models/games.rb +12 -0
  33. data/lib/riot_lol_api/models/goldpermindeltas.rb +7 -0
  34. data/lib/riot_lol_api/models/golds.rb +7 -0
  35. data/lib/riot_lol_api/models/images.rb +17 -0
  36. data/lib/riot_lol_api/models/infos.rb +7 -0
  37. data/lib/riot_lol_api/models/items.rb +11 -0
  38. data/lib/riot_lol_api/models/leagues.rb +10 -0
  39. data/lib/riot_lol_api/models/leveltips.rb +7 -0
  40. data/lib/riot_lol_api/{model → models}/maps.rb +4 -7
  41. data/lib/riot_lol_api/models/masteries.rb +14 -0
  42. data/lib/riot_lol_api/models/matches.rb +11 -0
  43. data/lib/riot_lol_api/models/mini_series.rb +7 -0
  44. data/lib/riot_lol_api/models/observers.rb +7 -0
  45. data/lib/riot_lol_api/models/pages.rb +11 -0
  46. data/lib/riot_lol_api/models/participantidentities.rb +7 -0
  47. data/lib/riot_lol_api/models/participants.rb +7 -0
  48. data/lib/riot_lol_api/models/passives.rb +9 -0
  49. data/lib/riot_lol_api/models/player_stat_ranks.rb +9 -0
  50. data/lib/riot_lol_api/models/player_stat_summaries.rb +9 -0
  51. data/lib/riot_lol_api/models/players.rb +7 -0
  52. data/lib/riot_lol_api/models/recommendeds.rb +9 -0
  53. data/lib/riot_lol_api/models/runes.rb +7 -0
  54. data/lib/riot_lol_api/models/skins.rb +7 -0
  55. data/lib/riot_lol_api/models/slots.rb +9 -0
  56. data/lib/riot_lol_api/models/spells.rb +12 -0
  57. data/lib/riot_lol_api/{model → models}/stats.rb +3 -10
  58. data/lib/riot_lol_api/models/summoners.rb +110 -0
  59. data/lib/riot_lol_api/models/teams.rb +11 -0
  60. data/lib/riot_lol_api/models/timelines.rb +9 -0
  61. data/lib/riot_lol_api/models/vars.rb +7 -0
  62. data/lib/riot_lol_api/models/xpdiffpermindeltas.rb +7 -0
  63. data/lib/riot_lol_api/models/xppermindeltas.rb +7 -0
  64. data/lib/riot_lol_api/requests/champion_masteries.rb +11 -0
  65. data/lib/riot_lol_api/requests/champions.rb +23 -0
  66. data/lib/riot_lol_api/requests/games.rb +23 -0
  67. data/lib/riot_lol_api/requests/items.rb +23 -0
  68. data/lib/riot_lol_api/requests/masteries.rb +23 -0
  69. data/lib/riot_lol_api/requests/runes.rb +23 -0
  70. data/lib/riot_lol_api/requests/spells.rb +23 -0
  71. data/lib/riot_lol_api/requests/summoners.rb +29 -0
  72. data/lib/riot_lol_api/supports/regions.rb +33 -0
  73. data/lib/riot_lol_api/version.rb +1 -1
  74. data/riot_lol_api.gemspec +19 -16
  75. data/spec/factories/champion.rb +8 -8
  76. data/spec/factories/client.rb +7 -5
  77. data/spec/factories/game.rb +18 -18
  78. data/spec/factories/page.rb +8 -8
  79. data/spec/factories/summoner.rb +10 -9
  80. data/spec/mock_response/championmastery_by_summoner.json +7 -0
  81. data/spec/mock_response/championmastery_by_summoner_by_champion.json +7 -0
  82. data/spec/mock_response/championmastery_score.json +7 -0
  83. data/spec/mock_response/championmastery_top.json +7 -0
  84. data/spec/mock_response/get_all_champions_by_ids.json +4 -5
  85. data/spec/mock_response/get_all_champions_by_ids_all_data.json +4 -5
  86. data/spec/mock_response/get_all_item.json +4 -5
  87. data/spec/mock_response/get_all_masteries.json +5 -6
  88. data/spec/mock_response/get_all_runes.json +4 -5
  89. data/spec/mock_response/get_all_summoner_spells.json +5 -6
  90. data/spec/mock_response/get_all_summoner_spells_by_ids.json +4 -5
  91. data/spec/mock_response/get_champion_by_id.json +3 -4
  92. data/spec/mock_response/get_champion_by_id_all_data.json +4 -5
  93. data/spec/mock_response/get_featured_games.json +7 -7
  94. data/spec/mock_response/get_item_by_id.json +5 -6
  95. data/spec/mock_response/get_mastery_by_id.json +5 -6
  96. data/spec/mock_response/get_match_by_id.json +4 -5
  97. data/spec/mock_response/get_player_league.json +5 -6
  98. data/spec/mock_response/get_player_stat_ranked.json +5 -6
  99. data/spec/mock_response/get_player_stat_summaries.json +5 -6
  100. data/spec/mock_response/get_realm.json +5 -5
  101. data/spec/mock_response/get_rune_by_id.json +4 -5
  102. data/spec/mock_response/get_summoner_by_id.json +5 -6
  103. data/spec/mock_response/get_summoner_by_name.json +5 -6
  104. data/spec/mock_response/get_summoner_games_by_id.json +5 -6
  105. data/spec/mock_response/get_summoner_masteries_by_id.json +5 -6
  106. data/spec/mock_response/get_summoner_runes_by_id.json +5 -6
  107. data/spec/mock_response/get_summoner_spell_by_id.json +5 -6
  108. data/spec/mock_response/get_version.json +5 -6
  109. data/spec/mock_response/match_list.json +12 -0
  110. data/spec/mock_response/realm.json +12 -0
  111. data/spec/mock_response/summoner.json +5 -6
  112. data/spec/{riot_lol_api_spec.rb → riot_lol_api/riot_lol_api_spec.rb} +135 -164
  113. data/spec/riot_lol_api/riot_lol_api_supports_spec.rb +8 -0
  114. data/spec/spec_helper.rb +7 -2
  115. metadata +144 -77
  116. data/lib/core_ext/hash.rb +0 -29
  117. data/lib/core_ext/string.rb +0 -5
  118. data/lib/riot_lol_api/model/aggregated_stats.rb +0 -14
  119. data/lib/riot_lol_api/model/altimages.rb +0 -14
  120. data/lib/riot_lol_api/model/banned_champions.rb +0 -14
  121. data/lib/riot_lol_api/model/bans.rb +0 -14
  122. data/lib/riot_lol_api/model/blocks.rb +0 -16
  123. data/lib/riot_lol_api/model/champions.rb +0 -23
  124. data/lib/riot_lol_api/model/class_base.rb +0 -14
  125. data/lib/riot_lol_api/model/creepspermindeltas.rb +0 -14
  126. data/lib/riot_lol_api/model/csdiffpermindeltas.rb +0 -14
  127. data/lib/riot_lol_api/model/damagetakendiffpermindeltas.rb +0 -13
  128. data/lib/riot_lol_api/model/damagetakenpermindeltas.rb +0 -14
  129. data/lib/riot_lol_api/model/data.rb +0 -14
  130. data/lib/riot_lol_api/model/effects.rb +0 -14
  131. data/lib/riot_lol_api/model/entries.rb +0 -14
  132. data/lib/riot_lol_api/model/fellow_players.rb +0 -14
  133. data/lib/riot_lol_api/model/game_lists.rb +0 -14
  134. data/lib/riot_lol_api/model/games.rb +0 -19
  135. data/lib/riot_lol_api/model/goldpermindeltas.rb +0 -14
  136. data/lib/riot_lol_api/model/golds.rb +0 -14
  137. data/lib/riot_lol_api/model/images.rb +0 -24
  138. data/lib/riot_lol_api/model/infos.rb +0 -14
  139. data/lib/riot_lol_api/model/items.rb +0 -18
  140. data/lib/riot_lol_api/model/leagues.rb +0 -17
  141. data/lib/riot_lol_api/model/leveltips.rb +0 -14
  142. data/lib/riot_lol_api/model/masteries.rb +0 -30
  143. data/lib/riot_lol_api/model/matches.rb +0 -18
  144. data/lib/riot_lol_api/model/mini_series.rb +0 -14
  145. data/lib/riot_lol_api/model/observers.rb +0 -14
  146. data/lib/riot_lol_api/model/pages.rb +0 -18
  147. data/lib/riot_lol_api/model/participantidentities.rb +0 -13
  148. data/lib/riot_lol_api/model/participants.rb +0 -14
  149. data/lib/riot_lol_api/model/passives.rb +0 -16
  150. data/lib/riot_lol_api/model/player_stat_ranks.rb +0 -16
  151. data/lib/riot_lol_api/model/player_stat_summaries.rb +0 -16
  152. data/lib/riot_lol_api/model/recommendeds.rb +0 -16
  153. data/lib/riot_lol_api/model/runes.rb +0 -14
  154. data/lib/riot_lol_api/model/skins.rb +0 -14
  155. data/lib/riot_lol_api/model/slots.rb +0 -16
  156. data/lib/riot_lol_api/model/spells.rb +0 -19
  157. data/lib/riot_lol_api/model/summoners.rb +0 -160
  158. data/lib/riot_lol_api/model/teams.rb +0 -18
  159. data/lib/riot_lol_api/model/timelines.rb +0 -16
  160. data/lib/riot_lol_api/model/vars.rb +0 -14
  161. data/lib/riot_lol_api/model/xpdiffpermindeltas.rb +0 -14
  162. data/lib/riot_lol_api/model/xppermindeltas.rb +0 -14
  163. 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
@@ -0,0 +1,9 @@
1
+ module CoreExt
2
+ module String
3
+ module RiotLolApi
4
+ def lol_symbolize
5
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,15 +1,18 @@
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"
6
- require "core_ext/hash"
7
- require "riot_lol_api/model/class_base"
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
- # # http://ddragon.leagueoflegends.com/tool/euw/fr_FR
11
- # RiotLolApi::RATE_LIMIT = 0
12
- # RiotLolApi::RATE_LIMIT_REQ_MAX = 10
13
- # RiotLolApi::RATE_LIMIT_SEC_MAX = 10
14
- # RiotLolApi::RATE_LIMIT_RESET_DATE = Time.now
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
@@ -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
- class Client
6
-
7
- include RiotLolApi::HelperClass
8
-
9
- # Constant URL
10
- BASE_URL_API = "api.pvp.net/api/lol/"
11
-
12
- # attr
13
- # - region
14
- def initialize(options = {})
15
- options.each do |key, value|
16
- self.class.send(:attr_accessor, key.to_sym)
17
- instance_variable_set("@#{key}", value)
18
- end
19
- if RiotLolApi::Client.realm.nil? && !self.region.nil?
20
- self.get_realm
21
- end
22
- end
23
-
24
- class << self
25
- attr_accessor :realm
26
- end
27
-
28
- def get_realm
29
- response = Client.get("static-data/#{self.region}/v1.2/realm", "global")
30
- unless response.nil?
31
- self.class.realm = response
32
- else
33
- nil
34
- end
35
- end
36
-
37
- # TO DO
38
- # Set callback to get realm constants
39
- #
40
-
41
- def self.get url, domaine,data = nil, overide_base_uri = nil
42
- unless RiotLolApi::TOKEN.nil?
43
-
44
- # Check limit rate
45
- # RiotLolApi::RATE_LIMIT += 1
46
- # if Time.now - RiotLolApi::RATE_LIMIT_RESET_DATE > RiotLolApi::RATE_LIMIT_SEC_MAX
47
- # RiotLolApi::RATE_LIMIT_RESET_DATE = Time.now
48
- # else
49
- # if RiotLolApi::RATE_LIMIT == RiotLolApi::RATE_LIMIT_REQ_MAX
50
- # end
51
-
52
- # Set data params
53
- if data.nil?
54
- data = {:api_key => RiotLolApi::TOKEN}
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