Class: RiotLolApi::Client
- Inherits:
-
Object
- Object
- RiotLolApi::Client
- Includes:
- HelperClass
- Defined in:
- lib/riot_lol_api/clients.rb
Constant Summary collapse
- BASE_URL_API =
Constant URL
"api.pvp.net/api/lol/"
Class Attribute Summary collapse
-
.realm ⇒ Object
Returns the value of attribute realm.
Class Method Summary collapse
-
.get(url, domaine, data = nil, overide_base_uri = nil) ⇒ Object
TO DO Set callback to get realm constants.
Instance Method Summary collapse
- #current_game(summoner_id, platform_id = 'EUW1') ⇒ Object
- #featured_games ⇒ Object
- #get_all_champions(data = nil, sort_id = 'false', locale = 'fr_FR') ⇒ Object
-
#get_all_items(data = nil, locale = 'fr_FR') ⇒ Object
ITEM.
-
#get_all_masteries(data = nil, locale = 'fr_FR') ⇒ Object
MASTERY.
-
#get_all_runes(data = nil, locale = 'fr_FR') ⇒ Object
RUNE.
-
#get_all_summoner_spells(data = nil, sort_id = 'false', locale = 'fr_FR') ⇒ Object
SUMMONER SPELL.
-
#get_champion_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
CHAMPION.
- #get_item_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
- #get_mastery_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
- #get_realm ⇒ Object
- #get_rune_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
- #get_summoner_by_id(id) ⇒ Object
-
#get_summoner_by_name(name) ⇒ Object
SUMMONER.
- #get_summoner_spell_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
- #get_versions ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
attr - region.
- #match(game_id) ⇒ Object
Methods included from HelperClass
Constructor Details
#initialize(options = {}) ⇒ Client
attr
-
region
14 15 16 17 18 19 20 21 22 |
# File 'lib/riot_lol_api/clients.rb', line 14 def initialize( = {}) .each do |key, value| self.class.send(:attr_accessor, key.to_sym) instance_variable_set("@#{key}", value) end if RiotLolApi::Client.realm.nil? && !self.region.nil? self.get_realm end end |
Class Attribute Details
.realm ⇒ Object
Returns the value of attribute realm.
25 26 27 |
# File 'lib/riot_lol_api/clients.rb', line 25 def realm @realm end |
Class Method Details
.get(url, domaine, data = nil, overide_base_uri = nil) ⇒ Object
TO DO Set callback to get realm constants
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 |
# File 'lib/riot_lol_api/clients.rb', line 41 def self.get url, domaine,data = nil, overide_base_uri = nil unless RiotLolApi::TOKEN.nil? # Check limit rate # RiotLolApi::RATE_LIMIT += 1 # if Time.now - RiotLolApi::RATE_LIMIT_RESET_DATE > RiotLolApi::RATE_LIMIT_SEC_MAX # RiotLolApi::RATE_LIMIT_RESET_DATE = Time.now # else # if RiotLolApi::RATE_LIMIT == RiotLolApi::RATE_LIMIT_REQ_MAX # end # Set data params if data.nil? data = {:api_key => RiotLolApi::TOKEN} else data.merge!({:api_key => RiotLolApi::TOKEN}) end # Set domaine url domaine_url = "#{domaine}.#{overide_base_uri||BASE_URL_API}" response = HTTParty.get("https://#{domaine_url}#{url}", :query => data) case response.code when 200 JSON.parse(response.body) when 404 puts "Error server" nil when 500...600 puts "ERROR #{response.code}" nil end else puts "No TOKEN, you have to define RiotLolApi::TOKEN" nil end end |
Instance Method Details
#current_game(summoner_id, platform_id = 'EUW1') ⇒ Object
290 291 292 293 294 295 296 297 |
# File 'lib/riot_lol_api/clients.rb', line 290 def current_game summoner_id, platform_id='EUW1' response = Client.get("observer-mode/rest/consumer/getSpectatorGameInfo/#{platform_id}/#{summoner_id}",@region,nil,'api.pvp.net/') unless response.nil? RiotLolApi::Model::Game.new(response.to_symbol) else nil end end |
#featured_games ⇒ Object
281 282 283 284 285 286 287 288 |
# File 'lib/riot_lol_api/clients.rb', line 281 def featured_games response = Client.get("observer-mode/rest/featured",@region,nil,'api.pvp.net/') unless response.nil? RiotLolApi::Model::Observer.new(response.to_symbol) else nil end end |
#get_all_champions(data = nil, sort_id = 'false', locale = 'fr_FR') ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/riot_lol_api/clients.rb', line 118 def get_all_champions data = nil, sort_id = 'false', locale = 'fr_FR' if data.nil? data = {:locale => locale, :dataById => sort_id} else data.merge!({:locale => locale, :dataById => sort_id}) end response = Client.get("static-data/#{@region}/v1.2/champion","global",data) unless response.nil? tab_champions = Array.new response["data"].each do |champion| tab_champions << RiotLolApi::Model::Champion.new(champion[1].to_symbol) end tab_champions else nil end end |
#get_all_items(data = nil, locale = 'fr_FR') ⇒ Object
ITEM
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/riot_lol_api/clients.rb', line 139 def get_all_items data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/item","global",data) unless response.nil? tab_items = Array.new response["data"].each do |item| tab_items << RiotLolApi::Model::Item.new(item[1].to_symbol) end tab_items else nil end end |
#get_all_masteries(data = nil, locale = 'fr_FR') ⇒ Object
MASTERY
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/riot_lol_api/clients.rb', line 175 def get_all_masteries data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/mastery","global",data) unless response.nil? tab_masteries = Array.new response["data"].each do |mastery| tab_masteries << RiotLolApi::Model::Mastery.new(mastery[1].to_symbol) end tab_masteries else nil end end |
#get_all_runes(data = nil, locale = 'fr_FR') ⇒ Object
RUNE
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/riot_lol_api/clients.rb', line 211 def get_all_runes data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/rune","global",data) unless response.nil? tab_runes = Array.new response["data"].each do |rune| tab_runes << RiotLolApi::Model::Rune.new(rune[1].to_symbol) end tab_runes else nil end end |
#get_all_summoner_spells(data = nil, sort_id = 'false', locale = 'fr_FR') ⇒ Object
SUMMONER SPELL
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/riot_lol_api/clients.rb', line 247 def get_all_summoner_spells data = nil, sort_id = 'false', locale = 'fr_FR' if data.nil? data = {:locale => locale, :dataById => sort_id} else data.merge!({:locale => locale, :dataById => sort_id}) end response = Client.get("static-data/#{@region}/v1.2/summoner-spell","global",data) unless response.nil? tab_summoner_spells = Array.new response["data"].each do |summoner_spell| tab_summoner_spells << RiotLolApi::Model::Spell.new(summoner_spell[1].to_symbol) end tab_summoner_spells else nil end end |
#get_champion_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
CHAMPION
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/riot_lol_api/clients.rb', line 103 def get_champion_by_id id, data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/champion/#{id}","global",data) unless response.nil? RiotLolApi::Model::Champion.new(response.to_symbol) else nil end end |
#get_item_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/riot_lol_api/clients.rb', line 158 def get_item_by_id id, data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/item/#{id}","global",data) unless response.nil? RiotLolApi::Model::Item.new(response.to_symbol) else nil end end |
#get_mastery_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/riot_lol_api/clients.rb', line 194 def get_mastery_by_id id, data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/mastery/#{id}","global",data) unless response.nil? RiotLolApi::Model::Mastery.new(response.to_symbol) else nil end end |
#get_realm ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/riot_lol_api/clients.rb', line 28 def get_realm response = Client.get("static-data/#{self.region}/v1.2/realm", "global") unless response.nil? self.class.realm = response else nil end end |
#get_rune_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/riot_lol_api/clients.rb', line 230 def get_rune_by_id id, data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/rune/#{id}","global",data) unless response.nil? RiotLolApi::Model::Rune.new(response.to_symbol) else nil end end |
#get_summoner_by_id(id) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/riot_lol_api/clients.rb', line 92 def get_summoner_by_id id response = Client.get("#{@region}/v1.4/summoner/#{id}",@region) unless response.nil? RiotLolApi::Model::Summoner.new(response[id.to_s].to_symbol.merge({:region => @region})) else nil end end |
#get_summoner_by_name(name) ⇒ Object
SUMMONER
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/riot_lol_api/clients.rb', line 81 def get_summoner_by_name name name = name.downcase name.strip! response = Client.get("#{@region}/v1.4/summoner/by-name/#{name}",@region) unless response.nil? RiotLolApi::Model::Summoner.new(response[name].to_symbol.merge({:region => @region})) else nil end end |
#get_summoner_spell_by_id(id, data = nil, locale = 'fr_FR') ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/riot_lol_api/clients.rb', line 266 def get_summoner_spell_by_id id, data = nil, locale = 'fr_FR' if data.nil? data = {:locale => locale} else data.merge!({:locale => locale}) end response = Client.get("static-data/#{@region}/v1.2/summoner-spell/#{id}","global",data) unless response.nil? RiotLolApi::Model::Spell.new(response.to_symbol) else nil end end |