Class: LolApi::Client
- Inherits:
-
Object
- Object
- LolApi::Client
- Defined in:
- lib/lol_api/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #champion_by_id(id, options = {}) ⇒ Object
- #champions(options = {}) ⇒ Object
- #configure {|config| ... } ⇒ Object
- #connection ⇒ Object
- #history_by_id(id) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #item_by_id(id, options = {}) ⇒ Object
- #items(options = {}) ⇒ Object
- #masteries(options = {}) ⇒ Object
- #mastery_by_id(id = 0, options = {}) ⇒ Object
- #match_details(id, timeline = true) ⇒ Object
- #run_request(prefix, method, options = {}, interface = 'static-data', region = 'euw', id = '', version = 'v1.2') ⇒ Object
- #summoner_by_id(id) ⇒ Object
- #summoner_by_name(name) ⇒ Object
- #summoner_masteries(id) ⇒ Object
- #summoner_runes(id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 |
# File 'lib/lol_api/client.rb', line 16 def initialize( = {}) @config = Configuration.new() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/lol_api/client.rb', line 14 def config @config end |
Instance Method Details
#champion_by_id(id, options = {}) ⇒ Object
34 35 36 37 |
# File 'lib/lol_api/client.rb', line 34 def champion_by_id(id, = {}) response = run_request('global','champion', , 'static-data', 'euw', id.to_s, 'v1.2') Champion.new(response) if response["id"] end |
#champions(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/lol_api/client.rb', line 25 def champions( ={}) response = run_request('global', 'champion', , 'static-data', 'euw', '', 'v1.2') if response && (champions = response["data"]) champions.map do | champ | Champion.new(champ[1]) end end end |
#configure {|config| ... } ⇒ Object
19 20 21 |
# File 'lib/lol_api/client.rb', line 19 def configure yield config end |
#connection ⇒ Object
22 23 24 |
# File 'lib/lol_api/client.rb', line 22 def connection @connection ||= Connection.new end |
#history_by_id(id) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/lol_api/client.rb', line 58 def history_by_id(id) response = run_request('euw','matchhistory', {}, '', "euw", id.to_s, "v2.2") if matches = response['matches'] matches.map do |match| HistoryMatch.new(match) end end end |
#item_by_id(id, options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/lol_api/client.rb', line 48 def item_by_id(id, = {}) response = run_request('global','item', , 'static-data', 'euw', id.to_s, 'v1.2') Item.new(response) if response["id"] end |
#items(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/lol_api/client.rb', line 38 def items( = {}) response = run_request('global','item', , 'static-data', 'euw', '', 'v1.2') if response && (items = response['data']) items.map do |item| Item.new(item[1]) end end end |
#masteries(options = {}) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/lol_api/client.rb', line 66 def masteries( = {}) response = run_request('global', 'mastery', , 'static-data', 'euw', '', 'v1.2') if response && masteries = response['data'] masteries.map do |mastery| Mastery.new(mastery) end end end |
#mastery_by_id(id = 0, options = {}) ⇒ Object
75 76 77 78 |
# File 'lib/lol_api/client.rb', line 75 def mastery_by_id(id=0, = {}) response = run_request('global', 'mastery', , 'static-data', 'euw', id, 'v1.2') Mastery.new(response) if response["id"] end |
#match_details(id, timeline = true) ⇒ Object
53 54 55 56 |
# File 'lib/lol_api/client.rb', line 53 def match_details(id, timeline = true) response = run_request('euw', 'match', {:includeTimeline => timeline}, '', 'euw', id.to_s, 'v2.2') Match.new(response) if response['region'] end |
#run_request(prefix, method, options = {}, interface = 'static-data', region = 'euw', id = '', version = 'v1.2') ⇒ Object
100 101 102 103 |
# File 'lib/lol_api/client.rb', line 100 def run_request(prefix, method, = {}, interface='static-data' , region = 'euw', id = '', version = 'v1.2') url = "https://#{prefix}.api.pvp.net/api/lol#{("/" << interface) unless interface == ''}/#{region}/#{version}/#{method}/#{id}" connection.request(:get, url, .merge(api_key: config.api_key)) end |
#summoner_by_id(id) ⇒ Object
85 86 87 88 |
# File 'lib/lol_api/client.rb', line 85 def summoner_by_id(id) response = run_request('euw', 'summoner', {}, '', 'euw', id, 'v1.4') Summoner.new(response[id.to_s]) if response[id.to_s] end |
#summoner_by_name(name) ⇒ Object
80 81 82 83 |
# File 'lib/lol_api/client.rb', line 80 def summoner_by_name(name) response = run_request('euw', 'summoner/by-name', {}, '', 'euw', name, 'v1.4') Summoner.new(response[name]) if response[name] end |
#summoner_masteries(id) ⇒ Object
90 91 92 93 |
# File 'lib/lol_api/client.rb', line 90 def summoner_masteries(id) response = run_request('euw', 'summoner', {}, '', 'euw', id.to_s << "/masteries", 'v1.4') SummonerMasteries.new(response[id.to_s]) if response[id.to_s] end |
#summoner_runes(id) ⇒ Object
95 96 97 98 |
# File 'lib/lol_api/client.rb', line 95 def summoner_runes(id) response = run_request('euw', 'summoner', {}, '', 'euw', id.to_s << "/runes", 'v1.4') SummonerRunes.new(response[id.to_s]) if response[id.to_s] end |