Class: Lol::Client
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#region ⇒ String
Name of region.
Instance Method Summary collapse
-
#api_url(version, path) ⇒ String
Returns a full url for an API call.
-
#champion ⇒ Object
Calls the latest API version of champion.
-
#champion11 ⇒ Array
Retrieve all champions, v1.1.
-
#game(*args) ⇒ Object
Calls the latest API version of game returning the list of recent games played by a summoner.
-
#game11(summoner_id) ⇒ Array
Returns a list of the recent games played by a summoner.
-
#get(url) ⇒ Object
Calls the API via HTTParty and handles errors.
-
#initialize(api_key, options = {}) ⇒ Lol::Client
constructor
Initializes a Lol::Client.
-
#league(summoner_id) ⇒ Object
Calls the latest API version of league.
-
#league21(summoner_id) ⇒ Array
Retrieves leagues data for summoner, including leagues for all of summoner’s teams, v2.1.
Constructor Details
#initialize(api_key, options = {}) ⇒ Lol::Client
Initializes a Lol::Client
81 82 83 84 |
# File 'lib/lol/client.rb', line 81 def initialize api_key, = {} @api_key = api_key @region = .delete(:region) || "euw" end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/lol/client.rb', line 15 def api_key @api_key end |
#region ⇒ String
Returns name of region.
11 12 13 |
# File 'lib/lol/client.rb', line 11 def region @region end |
Instance Method Details
#api_url(version, path) ⇒ String
Returns a full url for an API call
21 22 23 24 |
# File 'lib/lol/client.rb', line 21 def api_url version, path lol = version == "v1.1" ? "lol" : "" File.join "http://prod.api.pvp.net/api/", lol, "/#{region}/#{version}/", "#{path}?api_key=#{api_key}" end |
#champion ⇒ Object
Calls the latest API version of champion
38 39 40 |
# File 'lib/lol/client.rb', line 38 def champion champion11 end |
#champion11 ⇒ Array
Retrieve all champions, v1.1
44 45 46 |
# File 'lib/lol/client.rb', line 44 def champion11 get(api_url("v1.1", "champion"))["champions"].map {|c| Champion.new(c)} end |
#game(*args) ⇒ Object
Calls the latest API version of game returning the list of recent games played by a summoner
50 51 52 |
# File 'lib/lol/client.rb', line 50 def game *args game11 *args end |
#game11(summoner_id) ⇒ Array
Returns a list of the recent games played by a summoner
57 58 59 60 61 62 |
# File 'lib/lol/client.rb', line 57 def game11 summoner_id summoner_api_path = "game/by-summoner/#{summoner_id}/recent" get(api_url("v1.1", summoner_api_path))["games"].map do |game_data| Game.new game_data end end |
#get(url) ⇒ Object
Calls the API via HTTParty and handles errors
28 29 30 31 32 33 34 35 |
# File 'lib/lol/client.rb', line 28 def get url response = self.class.get(url) if response["status"] raise InvalidAPIResponse.new(response["status"]["message"]) else response end end |
#league(summoner_id) ⇒ Object
Calls the latest API version of league
65 66 67 |
# File 'lib/lol/client.rb', line 65 def league summoner_id league21 summoner_id end |
#league21(summoner_id) ⇒ Array
Retrieves leagues data for summoner, including leagues for all of summoner’s teams, v2.1
71 72 73 |
# File 'lib/lol/client.rb', line 71 def league21 summoner_id get(api_url("v2.1", "league/by-summoner/#{summoner_id}"))[summoner_id].map {|l| League.new} end |