Class: Sightstone::GameModule

Inherits:
SightstoneBaseModule show all
Defined in:
lib/sightstone/modules/game_module.rb

Overview

module to access the game api

Instance Method Summary collapse

Constructor Details

#initialize(sightstone) ⇒ GameModule

Returns a new instance of GameModule.



8
9
10
# File 'lib/sightstone/modules/game_module.rb', line 8

def initialize(sightstone)
  @sightstone = sightstone
end

Instance Method Details

#recent(summoner, optional = {}) ⇒ MatchHistory

returns the match history of a summoner

Parameters:

  • summoner (Summoner, Fixnum)

    summoner object or id of a summoner

  • optional (Hash) (defaults to: {})

    optional arguments: :region => replaces default region

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sightstone/modules/game_module.rb', line 16

def recent(summoner, optional={})
  region = optional[:region] || @sightstone.region
 id = if summoner.is_a? Summoner
   summoner.id
 else
   summoner
 end
 uri = "https://prod.api.pvp.net/api/lol/#{region}/v1.3/game/by-summoner/#{id}/recent"
 
  response = _get_api_response(uri)
  _parse_response(response) { |resp|
    data = JSON.parse(resp)
    history =  MatchHistory.new(data)
    if block_given?
      yield history
    else
      return history
    end
  }
end