class Paladins::Client

Attributes

api_url[RW]
auth_key[RW]
dev_id[RW]
response_format[RW]

Public Class Methods

new(configuration) click to toggle source
# File lib/paladins/client.rb, line 14
def initialize(configuration)
  @api_url     = configuration.api_url
  @dev_id      = configuration.dev_id
  @auth_key    = configuration.auth_key
  @response_format = configuration.response_format
end

Public Instance Methods

create_session() click to toggle source
# File lib/paladins/client.rb, line 26
def create_session
  # /createsession[ResponseFormat]/{developerId}/{signature}/{timestamp}
  response = Faraday.get(url(method: 'createsession', session: false))
  @@session[:updated_at] = Time.now
  @@session[:id] = JSON.parse(response.body).dig('session_id')
end
get_champion_ranks(player_name) click to toggle source
# File lib/paladins/client.rb, line 68
def get_champion_ranks(player_name)
  # /getchampionranks[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{player}
  response = Faraday.get(url(method: 'getchampionranks', session: true) + "/#{player_name}")
  attributes = JSON.parse(response.body)
end
get_hirez_server_status() click to toggle source
# File lib/paladins/client.rb, line 62
def get_hirez_server_status
  # /gethirezserverstatus[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}
  response = Faraday.get(url(method: 'gethirezserverstatus', session: true))
  attributes = JSON.parse(response.body)
end
get_match_player_details(match_id) click to toggle source
# File lib/paladins/client.rb, line 86
def get_match_player_details(match_id)
  # /getmatchplayerdetails[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{match_id}
  response = Faraday.get(url(method: 'getmatchplayerdetails', session: true) + "/#{match_id}")
  attributes = JSON.parse(response.body)
end
get_or_create_session() click to toggle source
# File lib/paladins/client.rb, line 52
def get_or_create_session
  ( @@session[:id].nil? || session_expired? ) ? create_session : @@session[:id]
end
get_player(player_name) click to toggle source
# File lib/paladins/client.rb, line 74
def get_player(player_name)
  # /getplayer[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{player}
  response = Faraday.get(url(method: 'getplayer', session: true) + "/#{player_name}")
  attributes = JSON.parse(response.body)
end
get_player_status(player_name) click to toggle source
# File lib/paladins/client.rb, line 80
def get_player_status(player_name)
  # /getplayerstatus[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{player}
  response = Faraday.get(url(method: 'getplayerstatus', session: true) + "/#{player_name}")
  attributes = JSON.parse(response.body)
end
get_signature(method_name, time_now) click to toggle source
# File lib/paladins/client.rb, line 21
def get_signature(method_name, time_now)
  raise ArgumentError.new('Missing dev_id or auth_key') if ( @dev_id.to_s.empty? || @auth_key.to_s.empty? )
  Digest::MD5.hexdigest(@dev_id + method_name + @auth_key + time_now);
end
ping() click to toggle source
# File lib/paladins/client.rb, line 56
def ping
  # /ping[ResponseFormat]
  response = Faraday.get("#{@api_url}/pingJson")
  attributes = JSON.parse(response.body)
end
session_expired?() click to toggle source
# File lib/paladins/client.rb, line 40
def session_expired?
  # synchronize secure taht only one thread at a time can access @@session
  self.synchronize do
    if Time.now - @@session[:updated_at] > 60*12
      @@session[:updated_at] = Time.now
      true
    else
      false
    end
  end
end
test_session() click to toggle source
# File lib/paladins/client.rb, line 33
def test_session
  # /testsession[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}
  time_now = Paladins::Utils.time_now
  response = Faraday.get("#{@api_url}/testsessionJson/#{@dev_id}/#{get_signature('testsession', time_now)}/#{@@session[:id]}/#{time_now}")
  attributes = JSON.parse(response.body)
end
url(method:, session: false) click to toggle source
# File lib/paladins/client.rb, line 92
def url(method:, session: false)
  time_now = Paladins::Utils.time_now
  url = "#{@api_url}/#{method}#{@response_format}/#{@dev_id}/#{get_signature(method, time_now)}"
  url += "/#{get_or_create_session}" if session
  url += "/#{time_now}"

  url
end