Skip to content

Commit

Permalink
Merge bf0118a into 501e484
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaracco committed Feb 9, 2015
2 parents 501e484 + bf0118a commit 5537766
Show file tree
Hide file tree
Showing 7 changed files with 1,200 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/lol/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def lol_status
@lol_status ||= LolStatusRequest.new(region, cache_store)
end

def current_game
@current_game ||= CurrentGameRequest.new(api_key, region, cache_store)
end

# Initializes a Lol::Client
# @param api_key [String]
# @param options [Hash]
Expand Down
16 changes: 16 additions & 0 deletions lib/lol/current_game_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Lol
class CurrentGameRequest < Request
def self.api_version
'v1.0'
end

def api_url path, params = {}
"#{api_base_url}/observer-mode/rest/consumer/#{path}?#{api_query_string params}"
end

def spectator_game_info platform_id, summoner_id
url = api_url "getSpectatorGameInfo/#{region.upcase}#{platform_id}/#{summoner_id}"
DynamicModel.new perform_request(url)
end
end
end
12 changes: 10 additions & 2 deletions lib/lol/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ def self.api_version
# @param path [String] API path to call
# @return [String] full fledged url
def api_url path, params = {}
query_string = URI.encode_www_form params.merge api_key: api_key
File.join "https://#{region}.api.pvp.net/api/lol/#{region}/#{self.class.api_version}/", "#{path}?#{query_string}"
url = "#{api_base_url}/api/lol/#{region}/#{self.class.api_version}/#{path}"
"#{url}?#{api_query_string params}"
end

def api_base_url
"https://#{region}.api.pvp.net"
end

def api_query_string params = {}
URI.encode_www_form params.merge api_key: api_key
end

# Returns just a path from a full api url
Expand Down

0 comments on commit 5537766

Please sign in to comment.