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

Parameters:

  • api_key (String)
  • options (Hash) (defaults to: {})

Options Hash (options):

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

    The region on which the requests will be made



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

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

Instance Attribute Details

#api_keyString (readonly)

Returns the API key that has been used.

Returns:

  • (String)

    the API key that has been used



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

def api_key
  @api_key
end

#regionString

Returns name of region.

Returns:

  • (String)

    name of region



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

def region
  @region
end

#ttlFixnum (readonly)

Returns the ttl on cached requests.

Returns:

  • (Fixnum)

    the ttl on cached requests



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

Returns:

  • (Hash)


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.

Returns:

  • (Boolean)

    true if requests are cached



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

def cached?
  @cached
end

#championChampionRequest

Returns:



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

def champion
  @champion_request ||= ChampionRequest.new(api_key, region, cache_store)
end

#gameGameRequest

Returns:



22
23
24
# File 'lib/lol/client.rb', line 22

def game
  @game_request ||= GameRequest.new(api_key, region, cache_store)
end

#leagueLeagueRequest

Returns:



32
33
34
# File 'lib/lol/client.rb', line 32

def league
  @league_request ||= LeagueRequest.new(api_key, region, cache_store)
end

#redisRedis

Returns the cache store (if available).

Returns:

  • (Redis)

    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

#staticStaticRequest

Returns:



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

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

#statsStatsRequest

Returns:



27
28
29
# File 'lib/lol/client.rb', line 27

def stats
  @stats_request ||= StatsRequest.new(api_key, region, cache_store)
end

#summonerSummonerRequest

Returns:



42
43
44
# File 'lib/lol/client.rb', line 42

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

#teamTeamRequest

Returns:



37
38
39
# File 'lib/lol/client.rb', line 37

def team
  @team_request ||= TeamRequest.new(api_key, region, cache_store)
end