class GameLockerAPI

Constants

VERSION
VirtualResponse

Attributes

base_url[R]
headers[R]
region[R]

Public Class Methods

new(api_key, region = "na") click to toggle source
# File lib/gamelocker_api.rb, line 13
def initialize(api_key, region = "na")
  @api_key = api_key
  @region  = region
  @base_url= "https://api.dc01.gamelockerapp.com/shards/"
  @headers = {}
end

Public Instance Methods

match(match_uuid = nil) click to toggle source
# File lib/gamelocker_api.rb, line 32
def match(match_uuid = nil)
  match_uuid ? request("matches/#{match_uuid}") : request("matches")
end
matches(match_params = {}) click to toggle source
# File lib/gamelocker_api.rb, line 36
def matches(match_params = {})
  request("matches", match_params)
end
player(uuid) click to toggle source

Probably does not work

# File lib/gamelocker_api.rb, line 21
def player(uuid)
  request("players/#{uuid}", {})
end
players(players_list = []) click to toggle source
# File lib/gamelocker_api.rb, line 25
def players(players_list = [])
  raise "Max of only 6 players" if players_list.count > 6
  string = players_list.join(", ")
  hash   = {"filter[playerNames]": string}
  request("players", hash)
end
telemetry(telemetry_url) click to toggle source
# File lib/gamelocker_api.rb, line 40
def telemetry(telemetry_url)
  Telemetry.new(telemetry_url)
end

Private Instance Methods

parser(response, end_point, healthy = true) click to toggle source
# File lib/gamelocker_api.rb, line 73
def parser(response, end_point, healthy = true)
  return {response: response, data: GameLockerAPI::AbstractParser.guess(end_point, Oj.load(response.body))} if healthy
  return {response: response, data: "{}"} unless healthy
end
request(end_point, params = nil) click to toggle source

def samples(samples_params = {})

request("samples", samples_params)

end

# File lib/gamelocker_api.rb, line 49
def request(end_point, params = nil)
  api_headers = {
    "X-TITLE-ID": "semc-vainglory",
    "Authorization": @api_key,
    "Accept": "application/vnd.api+json",
  }

  response = nil
  begin
    if params
      response = RestClient.get(@base_url+@region+"/"+end_point+"?"+URI.encode_www_form(params), api_headers)
    else
      response = RestClient.get(@base_url+@region+"/"+end_point, api_headers)
    end
    @headers = response.headers
    parser(response, end_point)

  rescue RestClient::ExceptionWithResponse => e
    response = VirtualResponse.new(e.response, e.response)
    @headers = e.response.headers
    parser(response, end_point, false)
  end
end