class LoLBase::Connection
Public Class Methods
new(key = nil)
click to toggle source
# File lib/lolbase/connection.rb, line 25 def initialize(key = nil) @key = key || LoLBase.config.default_key self end
Public Instance Methods
champions(region = LoLBase.config.default_region)
click to toggle source
# File lib/lolbase/connection.rb, line 49 def champions(region = LoLBase.config.default_region) ChampionList.new(region, self) end
get(path, options = {})
click to toggle source
Override HTTParty's get method to append the API key and to process errors returned from request
# File lib/lolbase/connection.rb, line 13 def get(path, options = {}) if options[:query].nil? options.merge!({ query: { api_key: @key } }) else options[:query].merge!({ api_key: @key }) end response = self.class.get path, options raise LoLBaseError, response.message if response.code != 200 response.body end
summoner(identifier, region = LoLBase.config.default_region)
click to toggle source
Syntactic sugar: lookup summoner by name or by ID
# File lib/lolbase/connection.rb, line 31 def summoner(identifier, region = LoLBase.config.default_region) if identifier.is_a? String return summoner_by_name(identifier, region) else return summoner_by_id(identifier, region) end end
summoner_by_id(id, region = LoLBase.config.default_region)
click to toggle source
# File lib/lolbase/connection.rb, line 44 def summoner_by_id(id, region = LoLBase.config.default_region) raise InvalidArgumentError if !id.is_a?(Integer) Summoner.new({ id: id, region: region }, self) end
summoner_by_name(name, region = LoLBase.config.default_region)
click to toggle source
# File lib/lolbase/connection.rb, line 39 def summoner_by_name(name, region = LoLBase.config.default_region) raise InvalidArgumentError if !name.is_a?(String) Summoner.new({ name: name, region: region }, self) end