Class: Lol::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lol/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, options = {}) ⇒ Lol::Client

Initializes a Lol::Client

Options Hash (options):

  • :region (String) — default: "EUW"

    The region on which the requests will be made

  • :redis (String)

    the redis url to use for caching

  • :ttl (Integer) — default: 900

    the cache ttl

  • :rate_limit_requests (Fixnum)

    number of requests

  • :rate_limit_seconds (Fixnum)

    number of seconds to limit the rate in


94
95
96
97
98
99
# File 'lib/lol/client.rb', line 94

def initialize api_key, options = {}
  @api_key = api_key
  @region = options.delete(:region) || "euw"
  set_up_cache(options.delete(:redis), options.delete(:ttl))
  set_up_rate_limiter(options.delete(:rate_limit_requests), options.delete(:rate_limit_seconds))
end

Instance Attribute Details

#api_keyString (readonly)


10
11
12
# File 'lib/lol/client.rb', line 10

def api_key
  @api_key
end

#rate_limiterObject (readonly)

@!attribute rate_limiter


18
19
20
# File 'lib/lol/client.rb', line 18

def rate_limiter
  @rate_limiter
end

#regionString


6
7
8
# File 'lib/lol/client.rb', line 6

def region
  @region
end

#ttlInteger (readonly)


14
15
16
# File 'lib/lol/client.rb', line 14

def ttl
  @ttl
end

Instance Method Details

#cache_storeHash

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


132
133
134
# File 'lib/lol/client.rb', line 132

def cached?
  @cached
end

#championChampionRequest


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_masteryChampionMasteryRequest


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_gameCurrentGameRequest


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

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

#leagueLeagueRequest


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_statusLolStatusRequest


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

#masteriesMasteriesRequest


46
47
48
# File 'lib/lol/client.rb', line 46

def masteries
  @masteries_request ||= MasteriesRequest.new(api_key, region, cache_store, rate_limiter)
end

#matchMatchRequest


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


127
128
129
# File 'lib/lol/client.rb', line 127

def rate_limited?
  @rate_limiter
end

#redisRedis


137
138
139
# File 'lib/lol/client.rb', line 137

def redis
  @redis
end

#runesRunesRequest


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

#spectatorSpectatorRequest


51
52
53
# File 'lib/lol/client.rb', line 51

def spectator
  @spectator_request ||= SpectatorRequest.new(api_key, region, cache_store, rate_limiter)
end

#staticStaticRequest


61
62
63
# File 'lib/lol/client.rb', line 61

def static
  @static_request ||= StaticRequest.new(api_key, region, cache_store, rate_limiter)
end

#summonerSummonerRequest


56
57
58
# File 'lib/lol/client.rb', line 56

def summoner
  @summoner_request ||= SummonerRequest.new(api_key, region, cache_store, rate_limiter)
end

#tournamentTournamentProviderRequest


81
82
83
# File 'lib/lol/client.rb', line 81

def tournament
  @tournament ||= TournamentRequest.new(api_key, region, cache_store, rate_limiter)
end