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.
-
#rate_limiter ⇒ Object
readonly
@!attribute rate_limiter.
-
#region ⇒ String
Name of region.
-
#ttl ⇒ Integer
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
- #champion_mastery ⇒ ChampionMasteryRequest
- #current_game ⇒ CurrentGameRequest
- #featured_games ⇒ FeaturedGamesRequest
-
#initialize(api_key, options = {}) ⇒ Lol::Client
constructor
Initializes a Lol::Client.
- #league ⇒ LeagueRequest
- #lol_status ⇒ LolStatusRequest
- #masteries ⇒ MasteriesRequest
- #match ⇒ MatchRequest
-
#rate_limited? ⇒ Boolean
True if requests are automatically rate limited.
-
#redis ⇒ Redis
The cache store (if available).
- #runes ⇒ RunesRequest
- #set_up_cache(redis_url, ttl) ⇒ Object
- #set_up_rate_limiter(number_of_requests, number_of_seconds) ⇒ Object
- #spectator ⇒ SpectatorRequest
- #static ⇒ StaticRequest
- #summoner ⇒ SummonerRequest
- #tournament ⇒ TournamentProviderRequest
Constructor Details
#initialize(api_key, options = {}) ⇒ Lol::Client
Initializes a Lol::Client
94 95 96 97 98 99 |
# File 'lib/lol/client.rb', line 94 def initialize api_key, = {} @api_key = api_key @region = .delete(:region) || "euw" set_up_cache(.delete(:redis), .delete(:ttl)) set_up_rate_limiter(.delete(:rate_limit_requests), .delete(:rate_limit_seconds)) 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 |
#rate_limiter ⇒ Object (readonly)
@!attribute rate_limiter
18 19 20 |
# File 'lib/lol/client.rb', line 18 def rate_limiter @rate_limiter end |
#region ⇒ String
Returns name of region.
6 7 8 |
# File 'lib/lol/client.rb', line 6 def region @region end |
#ttl ⇒ Integer (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
118 119 120 121 122 123 124 |
# File 'lib/lol/client.rb', line 118 def cache_store { redis: @redis, ttl: @ttl, cached: @cached, } end |
#cached? ⇒ Boolean
Returns true if requests are cached.
132 133 134 |
# File 'lib/lol/client.rb', line 132 def cached? @cached end |
#champion ⇒ ChampionRequest
21 22 23 |
# File 'lib/lol/client.rb', line 21 def champion @champion_request ||= ChampionRequest.new(api_key, region, cache_store, rate_limiter) end |
#champion_mastery ⇒ ChampionMasteryRequest
26 27 28 |
# File 'lib/lol/client.rb', line 26 def champion_mastery @champion_mastery_request ||= ChampionMasteryRequest.new(api_key, region, cache_store, rate_limiter) end |
#current_game ⇒ CurrentGameRequest
71 72 73 |
# File 'lib/lol/client.rb', line 71 def current_game @current_game ||= CurrentGameRequest.new(api_key, region, cache_store, rate_limiter) end |
#featured_games ⇒ FeaturedGamesRequest
76 77 78 |
# File 'lib/lol/client.rb', line 76 def featured_games @featured_games ||= FeaturedGamesRequest.new(api_key, region, cache_store, rate_limiter) end |
#league ⇒ LeagueRequest
36 37 38 |
# File 'lib/lol/client.rb', line 36 def league @league_request ||= LeagueRequest.new(api_key, region, cache_store, rate_limiter) end |
#lol_status ⇒ LolStatusRequest
66 67 68 |
# File 'lib/lol/client.rb', line 66 def lol_status @lol_status ||= LolStatusRequest.new(api_key, region, cache_store, rate_limiter) end |
#masteries ⇒ MasteriesRequest
46 47 48 |
# File 'lib/lol/client.rb', line 46 def masteries @masteries_request ||= MasteriesRequest.new(api_key, region, cache_store, rate_limiter) end |
#match ⇒ MatchRequest
31 32 33 |
# File 'lib/lol/client.rb', line 31 def match @match_request ||= MatchRequest.new(api_key, region, cache_store, rate_limiter) end |
#rate_limited? ⇒ Boolean
Returns true if requests are automatically rate limited.
127 128 129 |
# File 'lib/lol/client.rb', line 127 def rate_limited? @rate_limiter end |
#redis ⇒ Redis
Returns the cache store (if available).
137 138 139 |
# File 'lib/lol/client.rb', line 137 def redis @redis end |
#runes ⇒ RunesRequest
41 42 43 |
# File 'lib/lol/client.rb', line 41 def runes @runes_request ||= RunesRequest.new(api_key, region, cache_store, rate_limiter) end |
#set_up_cache(redis_url, ttl) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/lol/client.rb', line 101 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 |
#set_up_rate_limiter(number_of_requests, number_of_seconds) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/lol/client.rb', line 109 def set_up_rate_limiter(number_of_requests, number_of_seconds) return @rate_limited = false unless number_of_requests @rate_limited = true @rate_limiter = GluttonRatelimit::AveragedThrottle.new number_of_requests, number_of_seconds end |
#spectator ⇒ SpectatorRequest
51 52 53 |
# File 'lib/lol/client.rb', line 51 def spectator @spectator_request ||= SpectatorRequest.new(api_key, region, cache_store, rate_limiter) end |
#static ⇒ StaticRequest
61 62 63 |
# File 'lib/lol/client.rb', line 61 def static @static_request ||= StaticRequest.new(api_key, region, cache_store, rate_limiter) end |
#summoner ⇒ SummonerRequest
56 57 58 |
# File 'lib/lol/client.rb', line 56 def summoner @summoner_request ||= SummonerRequest.new(api_key, region, cache_store, rate_limiter) end |
#tournament ⇒ TournamentProviderRequest
81 82 83 |
# File 'lib/lol/client.rb', line 81 def tournament @tournament ||= TournamentRequest.new(api_key, region, cache_store, rate_limiter) end |