Class: Lol::TournamentProviderRequest
- Defined in:
- lib/lol/tournament_provider_request.rb
Instance Attribute Summary
Attributes inherited from Request
#api_key, #cache_store, #region
Class Method Summary collapse
-
.api_version ⇒ String
Returns the supported API Version.
Instance Method Summary collapse
- #api_base_url ⇒ Object
-
#api_url(path, params = {}) ⇒ String
Returns a full url for an API call.
-
#code(tournament_id, count = 1, options = {}) ⇒ Object
Returns a tournament code.
- #provider(region, url) ⇒ Object
-
#recent(summoner_id) ⇒ Array
Returns a list of the recent games played by a summoner.
- #tournament(name, provider) ⇒ Object
- #tournament_request(path, body) ⇒ Object
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_version ⇒ String
Returns 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_url ⇒ Object
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
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
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, = {} team_size = .delete(:team_size) || 5 allowed_summoner_ids = .delete(:allowed_summoner_ids) game_lobby_name = .delete(:game_lobby_name) || "Lobby" spectator_type = .delete(:spectator_type) || "ALL" password = .delete(:password) pick_type = .delete(:pick_type) || "TOURNAMENT_DRAFT" map_type = .delete(:map_type) || "SUMMONERS_RIFT" = .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
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 |