Class: Lol::TournamentProviderRequest

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

Instance Attribute Summary

Attributes inherited from Request

#api_key, #cache_store, #region

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#api_query_string, #cached?, #clean_url, #initialize, #perform_request, #post_api_url, #store, #ttl

Constructor Details

This class inherits a constructor from Lol::Request

Class Method Details

.api_versionString

Returns the supported API Version

Returns:

  • (String)

    the supported api version



5
6
7
# File 'lib/lol/tournament_provider_request.rb', line 5

def self.api_version
  "v1"
end

Instance Method Details

#api_base_urlObject



9
10
11
# File 'lib/lol/tournament_provider_request.rb', line 9

def api_base_url
  "https://global.api.pvp.net"
end

#api_url(path, params = {}) ⇒ String

Returns a full url for an API call

Parameters:

  • path (String)

    API path to call

Returns:

  • (String)

    full fledged url



16
17
18
# File 'lib/lol/tournament_provider_request.rb', line 16

def api_url path, params = {}
  url = "#{api_base_url}/tournament/public/#{self.class.api_version}/#{path}"
end

#code(tournament_id, count = 1, options = {}) ⇒ Object

Returns a tournament code

Parameters:

  • tournament_id (Integer)

    Tournament ID

  • count (Integer) (defaults to: 1)

    Number of tournament codes to generate

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

    Tournament Code options hash

Options Hash (options):

  • :team_size (Integer)

    Team Size 1-5

  • :allowed_summoner_ids (Array)

    SummonerIds spec

  • :game_lobby_name (String)

    Not used for now

  • :spectator_type (String)

    NONE, LOBBYONLY, ALL

  • :password (String)

    Game Lobby password, mandatory

  • :pick_type (String)

    BLIND_PICK, DRAFT_MODE, ALL_RANDOM, TOURNAMENT_DRAFT

  • :map_type (String)

    SUMMONERS_RIFT, CRYSTAL_SCAR, HOWLING_ABYSS

  • :metadata (String)

    Optional metadata String



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lol/tournament_provider_request.rb', line 37

def code tournament_id, count = 1, options = {}
  team_size = options.delete(:team_size) || 5
  allowed_summoner_ids = options.delete(:allowed_summoner_ids)
  game_lobby_name = options.delete(:game_lobby_name) || "Lobby"
  spectator_type = options.delete(:spectator_type) || "ALL"
  password = options.delete(:password)
  pick_type = options.delete(:pick_type) || "TOURNAMENT_DRAFT"
  map_type = options.delete(:map_type) || "SUMMONERS_RIFT"
   = options.delete(:metadata)

  body = {
    teamSize: team_size,
    gameLobbyName: game_lobby_name,
    spectatorType: spectator_type,
    pickType: pick_type,
    mapType: map_type
  }

  body.merge!({allowedSummonerIds: allowed_summoner_ids}) if allowed_summoner_ids
  body.merge!({metadata: }) if 
  body.merge!({password: password}) if password

  params = URI.encode_www_form({tournamentId: tournament_id, count: count})
  JSON.parse(tournament_request "code?#{params}", body)
end

#provider(region, url) ⇒ Object



63
64
65
# File 'lib/lol/tournament_provider_request.rb', line 63

def provider region, url
  tournament_request "provider", {region: region, url: url}
end

#recent(summoner_id) ⇒ Array

Returns a list of the recent games played by a summoner

Parameters:

  • summoner_id (Fixnum)

    Summoner id

Returns:

  • (Array)

    an array of games



74
75
76
77
78
79
# File 'lib/lol/tournament_provider_request.rb', line 74

def recent summoner_id
  summoner_api_path = "game/by-summoner/#{summoner_id}/recent"
  perform_request(api_url(summoner_api_path))["games"].map do |game_data|
    Game.new game_data
  end
end

#tournament(name, provider) ⇒ Object



67
68
69
# File 'lib/lol/tournament_provider_request.rb', line 67

def tournament name, provider
  tournament_request "tournament", {name: name, providerId: provider}
end

#tournament_request(path, body) ⇒ Object



20
21
22
23
# File 'lib/lol/tournament_provider_request.rb', line 20

def tournament_request path, body
  pau = post_api_url path
  perform_request(pau[:url], :post, body, pau[:options]).body
end