Class: RitoApi::Client

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

Overview

Setting up a client to make request to league of legends api.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, region, cache = false, ttl = 1) ⇒ Client

Initializes the client.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rito_api/client.rb', line 9

def initialize(api_key, region, cache = false, ttl = 1) # Initializes the client.
    @api_key = api_key
    @region = region
    @ttl = ttl 
    unless cache
        @cache_store = nil
    else
        @cache_store = Moneta.new(:Redis, expires: @ttl)  # ttl = time till the cache expires [Defaults to 1 as 0 means never expire.]
        # @cache_store.clear
    end
end

Instance Attribute Details

#regionObject

Returns the value of attribute region.



7
8
9
# File 'lib/rito_api/client.rb', line 7

def region
  @region
end

Instance Method Details

#basicObject



31
32
33
# File 'lib/rito_api/client.rb', line 31

def basic
    RitoApi::Requests::Basic.new(@api_key, @region, @cache_store)
end

#challengerObject

Creates a new instance of challenger class. Used to make request relating to summoner. Check requests/challenger.rb for methods.



39
40
41
# File 'lib/rito_api/client.rb', line 39

def challenger # Creates a new instance of challenger class. Used to make request relating to summoner. Check requests/challenger.rb for methods.
    RitoApi::Requests::Challenger.new(@api_key, @region, @cache_store)
end

#championObject

Creates a new instance of champion class. Used to make request relating to champion. Check requests/champion.rb for methods.



43
44
45
# File 'lib/rito_api/client.rb', line 43

def champion # Creates a new instance of champion class. Used to make request relating to champion. Check requests/champion.rb for methods.
    RitoApi::Requests::Champion.new(@api_key, @region, @cache_store)
end

#change_region(region) ⇒ Object

Changes region after the client is already initialized.



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

def change_region(region) # Changes region after the client is already initialized.
    @region = region
end

#closeObject

Closes the client.



21
22
23
24
25
# File 'lib/rito_api/client.rb', line 21

def close # Closes the client.
    unless @cache_store.nil?
        @cache_store.clear
    end
end

#itemObject



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

def item
    RitoApi::Requests::Item.new(@api_key, @region, @cache_store)
end

#matchObject



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

def match
    RitoApi::Requests::Match.new(@api_key, @region, @cache_store)
end

#summonerObject

Creates a new instance of summoner class. Used to make request relating to summoner. Check requests/summoner.rb for methods.



35
36
37
# File 'lib/rito_api/client.rb', line 35

def summoner # Creates a new instance of summoner class. Used to make request relating to summoner. Check requests/summoner.rb for methods.
    RitoApi::Requests::Summoner.new(@api_key, @region, @cache_store)
end