Class: RiotLolApi::Client

Inherits:
Object
  • Object
show all
Includes:
HelperClass, Request::Champion, Request::ChampionMastery, Request::Game, Request::Item, Request::Mastery, Request::Rune, Request::Spell, Request::Summoner
Defined in:
lib/riot_lol_api/clients.rb

Constant Summary collapse

BASE_URL_API =
'api.pvp.net/api/lol/'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request::ChampionMastery

#championmastery_by_summoner_by_champion

Methods included from Request::Game

#current_game, #featured_games, #match

Methods included from Request::Spell

#get_all_summoner_spells, #get_summoner_spell_by_id

Methods included from Request::Rune

#get_all_runes, #get_rune_by_id

Methods included from Request::Mastery

#get_all_masteries, #get_mastery_by_id

Methods included from Request::Item

#get_all_items, #get_item_by_id

Methods included from Request::Champion

#get_all_champions, #get_champion_by_id

Methods included from Request::Summoner

#get_summoner_by_id, #get_summoner_by_name, #get_summoners_by_id

Methods included from HelperClass

included, #list_methods

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



28
29
30
31
32
33
34
35
# File 'lib/riot_lol_api/clients.rb', line 28

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
  @platform = platform unless region.nil?
  realm unless region.nil?
end

Class Attribute Details

.realmObject

Returns the value of attribute realm.



38
39
40
# File 'lib/riot_lol_api/clients.rb', line 38

def realm
  @realm
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



26
27
28
# File 'lib/riot_lol_api/clients.rb', line 26

def api_key
  @api_key
end

#platformObject

Returns the value of attribute platform.



26
27
28
# File 'lib/riot_lol_api/clients.rb', line 26

def platform
  @platform
end

#regionObject

Returns the value of attribute region.



26
27
28
# File 'lib/riot_lol_api/clients.rb', line 26

def region
  @region
end

Instance Method Details

#get(url:, domaine:, data: {}, overide_base_uri: BASE_URL_API) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/riot_lol_api/clients.rb', line 54

def get(url:, domaine:, data: {}, overide_base_uri: BASE_URL_API)
  return fail('need api key') if @api_key.nil?
  data.merge!(api_key: @api_key)
  domaine_url = "#{domaine}.#{overide_base_uri}"
  response = HTTParty.get("https://#{domaine_url}#{url}", query: data)
  return JSON.parse(response.body) if response.code == 200
  nil
end

#realmObject



41
42
43
44
# File 'lib/riot_lol_api/clients.rb', line 41

def realm
  response = get(url: "static-data/#{region}/v1.2/realm", domaine: 'global')
  self.class.realm = response unless response.nil?
end

#versionsObject



50
51
52
# File 'lib/riot_lol_api/clients.rb', line 50

def versions
  get(url: "static-data/#{@region}/v1.2/versions", domaine: 'global')
end