Class: Lol::Client
- Inherits:
-
Object
- Object
- Lol::Client
- Defined in:
- lib/lol/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
The API key that has been used.
-
#region ⇒ String
Name of region.
-
#ttl ⇒ Fixnum
readonly
The ttl on cached requests.
Instance Method Summary collapse
-
#cache_store ⇒ Hash
Returns an options hash with cache keys.
-
#cached? ⇒ Boolean
True if requests are cached.
- #champion ⇒ ChampionRequest
- #game ⇒ GameRequest
-
#initialize(api_key, options = {}) ⇒ Lol::Client
constructor
Initializes a Lol::Client.
- #league ⇒ LeagueRequest
-
#redis ⇒ Redis
The cache store (if available).
- #set_up_cache(redis_url, ttl) ⇒ Object
- #static ⇒ StaticRequest
- #stats ⇒ StatsRequest
- #summoner ⇒ SummonerRequest
- #team ⇒ TeamRequest
Constructor Details
#initialize(api_key, options = {}) ⇒ Lol::Client
Initializes a Lol::Client
56 57 58 59 60 |
# File 'lib/lol/client.rb', line 56 def initialize api_key, = {} @api_key = api_key @region = .delete(:region) || "euw" set_up_cache(.delete(:redis), .delete(:ttl)) end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns the API key that has been used.
10 11 12 |
# File 'lib/lol/client.rb', line 10 def api_key @api_key end |
#region ⇒ String
Returns name of region.
6 7 8 |
# File 'lib/lol/client.rb', line 6 def region @region end |
#ttl ⇒ Fixnum (readonly)
Returns the ttl on cached requests.
14 15 16 |
# File 'lib/lol/client.rb', line 14 def ttl @ttl end |
Instance Method Details
#cache_store ⇒ Hash
Returns an options hash with cache keys
72 73 74 75 76 77 78 |
# File 'lib/lol/client.rb', line 72 def cache_store { redis: @redis, ttl: @ttl, cached: @cached, } end |
#cached? ⇒ Boolean
Returns true if requests are cached.
81 82 83 |
# File 'lib/lol/client.rb', line 81 def cached? @cached end |
#champion ⇒ ChampionRequest
17 18 19 |
# File 'lib/lol/client.rb', line 17 def champion @champion_request ||= ChampionRequest.new(api_key, region, cache_store) end |
#game ⇒ GameRequest
22 23 24 |
# File 'lib/lol/client.rb', line 22 def game @game_request ||= GameRequest.new(api_key, region, cache_store) end |
#league ⇒ LeagueRequest
32 33 34 |
# File 'lib/lol/client.rb', line 32 def league @league_request ||= LeagueRequest.new(api_key, region, cache_store) end |
#redis ⇒ Redis
Returns the cache store (if available).
86 87 88 |
# File 'lib/lol/client.rb', line 86 def redis @redis end |
#set_up_cache(redis_url, ttl) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/lol/client.rb', line 62 def set_up_cache(redis_url, ttl) return @cached = false unless redis_url @ttl = ttl || 900 @cached = true @redis = Redis.new :url => redis_url end |
#static ⇒ StaticRequest
47 48 49 |
# File 'lib/lol/client.rb', line 47 def static @static_request ||= StaticRequest.new(api_key, region, cache_store) end |
#stats ⇒ StatsRequest
27 28 29 |
# File 'lib/lol/client.rb', line 27 def stats @stats_request ||= StatsRequest.new(api_key, region, cache_store) end |
#summoner ⇒ SummonerRequest
42 43 44 |
# File 'lib/lol/client.rb', line 42 def summoner @summoner_request ||= SummonerRequest.new(api_key, region, cache_store) end |
#team ⇒ TeamRequest
37 38 39 |
# File 'lib/lol/client.rb', line 37 def team @team_request ||= TeamRequest.new(api_key, region, cache_store) end |