Class: LoLBase::Connection
- Inherits:
-
Object
- Object
- LoLBase::Connection
- Includes:
- HTTParty
- Defined in:
- lib/lolbase/connection.rb
Instance Method Summary collapse
-
#get(path, options = {}) ⇒ Object
Override HTTParty’s get method to append the API key and to process errors returned from request.
-
#initialize(key = nil) ⇒ Connection
constructor
A new instance of Connection.
-
#summoner(identifier, region = LoLBase.config.default_region) ⇒ Object
Syntactic sugar: lookup summoner by name or by ID.
- #summoner_by_id(id, region = LoLBase.config.default_region) ⇒ Object
- #summoner_by_name(name, region = LoLBase.config.default_region) ⇒ Object
Constructor Details
#initialize(key = nil) ⇒ Connection
Returns a new instance of Connection.
25 26 27 28 |
# File 'lib/lolbase/connection.rb', line 25 def initialize(key = nil) @key = key || LoLBase.config.default_key self end |
Instance Method Details
#get(path, options = {}) ⇒ Object
Override HTTParty’s get method to append the API key and to process errors returned from request
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lolbase/connection.rb', line 13 def get(path, = {}) if [:query].nil? .merge!({ query: { api_key: @key } }) else [:query].merge!({ api_key: @key }) end response = self.class.get path, raise LoLBaseError, response. if response.code != 200 response.body end |
#summoner(identifier, region = LoLBase.config.default_region) ⇒ Object
Syntactic sugar: lookup summoner by name or by ID
31 32 33 34 35 36 37 |
# 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 |