class Smite::Client

Attributes

auth_key[R]
created[R]
dev_id[R]
lang[R]
session_id[R]

Public Class Methods

new(dev_id, auth_key, lang = 1) click to toggle source
# File lib/smite/client.rb, line 7
def initialize(dev_id, auth_key, lang = 1)
  @dev_id     = dev_id
  @auth_key   = auth_key
  @lang       = [1,2,3,7,9,10,11,12,13].include?(lang) ? lang : 1
  @created    = Time.new(0)
  create_session
end

Public Instance Methods

achievements(player_id) click to toggle source
# File lib/smite/client.rb, line 75
def achievements(player_id)
  api_call('getplayerachievements', [player_id])
end
create_session() click to toggle source
# File lib/smite/client.rb, line 107
def create_session
  return @session_id if valid_session?

  response      = api_call('createsession', [], false)
  unless response && response['ret_msg'] == 'Approved'
    return @session_id = nil
  end

  @session_id   = response['session_id']
  @created      = Time.now
  @session_id
end
data_used() click to toggle source
# File lib/smite/client.rb, line 103
def data_used
  api_call('getdataused')
end
esports_pro_league_details() click to toggle source
# File lib/smite/client.rb, line 15
def esports_pro_league_details
  api_call('getesportsproleaguedetails')
end
friends(player_name) click to toggle source
# File lib/smite/client.rb, line 79
def friends(player_name)
  api_call('getfriends', [player_name])
end
god_ranks(player_name) click to toggle source
# File lib/smite/client.rb, line 83
def god_ranks(player_name)
  api_call('getgodranks', [player_name])
end
gods() click to toggle source
# File lib/smite/client.rb, line 67
def gods
  api_call('getgods', [lang])
end
items() click to toggle source
# File lib/smite/client.rb, line 71
def items
  api_call('getitems', [lang])
end
league_leaderboard(queue, tier, season) click to toggle source
# File lib/smite/client.rb, line 35
def league_leaderboard(queue, tier, season)
  api_call('getleagueleaderboard', [queue, tier, season])
end
league_seasons(queue) click to toggle source
# File lib/smite/client.rb, line 31
def league_seasons(queue)
  api_call('getleagueseasons', [queue])
end
match_details(match_id) click to toggle source
# File lib/smite/client.rb, line 63
def match_details(match_id)
  api_call('getmatchdetails', [match_id])
end
match_history(player_name) click to toggle source
# File lib/smite/client.rb, line 91
def match_history(player_name)
  api_call('getmatchhistory', [player_name])
end
match_ids_by_queue(queue, date, hour) click to toggle source
# File lib/smite/client.rb, line 27
def match_ids_by_queue(queue, date, hour)
  api_call('getmatchidsbyqueue', [queue, date, hour])
end
match_player_details(match_id) click to toggle source
# File lib/smite/client.rb, line 23
def match_player_details(match_id)
  api_call('getmatchplayerdetails', [match_id])
end
motd() click to toggle source
# File lib/smite/client.rb, line 39
def motd
  api_call('getmotd')
end
ping() click to toggle source
# File lib/smite/client.rb, line 124
def ping
  self.class.get('/pingjson')
end
player(player_name) click to toggle source
# File lib/smite/client.rb, line 87
def player(player_name)
  api_call('getplayer', [player_name])
end
player_status(player_name) click to toggle source
# File lib/smite/client.rb, line 43
def player_status(player_name)
  api_call('getplayerstatus', [player_name])
end
queue_stats(player_name, queue) click to toggle source
# File lib/smite/client.rb, line 47
def queue_stats(player_name, queue)
  api_call('getqueuestats', [player_name, queue])
end
search_teams(team_name) click to toggle source
# File lib/smite/client.rb, line 95
def search_teams(team_name)
  api_call('searchteams', [team_name])
end
team_details(clan_id) click to toggle source
# File lib/smite/client.rb, line 51
def team_details(clan_id)
  api_call('getteamdetails', [clan_id])
end
team_players(clan_id) click to toggle source
# File lib/smite/client.rb, line 55
def team_players(clan_id)
  api_call('getteamplayers', [clan_id])
end
test_session() click to toggle source
# File lib/smite/client.rb, line 99
def test_session
  api_call('testsession')
end
top_matches() click to toggle source
# File lib/smite/client.rb, line 59
def top_matches
  api_call('gettopmatches')
end
valid_session?() click to toggle source
# File lib/smite/client.rb, line 120
def valid_session?
  (created + (15 * 60)) > Time.now
end

Private Instance Methods

api_call(method, params = [], session = true) click to toggle source
# File lib/smite/client.rb, line 130
def api_call(method, params = [], session = true)
  create_session if !valid_session? && session

  request = request_str(method, params, session)
  self.class.get(request)
end
base_str(method) click to toggle source
# File lib/smite/client.rb, line 154
def base_str(method)
  signature = signature(method)
  "/#{method}json/#{dev_id}/#{signature}"
end
param_str(params) click to toggle source
# File lib/smite/client.rb, line 159
def param_str(params)
  "/#{params.join('/')}"
end
request_str(method, params, session) click to toggle source
# File lib/smite/client.rb, line 146
def request_str(method, params, session)
  base  = base_str(method)
  parm  = param_str(params)
  sess  = session_str(session)

  "#{base}#{sess}#{parm}".chomp('/')
end
session_str(session) click to toggle source
# File lib/smite/client.rb, line 163
def session_str(session)
  "/#{session_id}#{session ? '/' : ''}#{timestamp}"
end
signature(method) click to toggle source
# File lib/smite/client.rb, line 137
def signature(method)
  Digest::MD5.hexdigest("#{dev_id}#{method}#{auth_key}#{timestamp}")
end
timestamp() click to toggle source

current utc timestamp (formatted yyyyMMddHHmmss)

# File lib/smite/client.rb, line 142
def timestamp
  Time.now.utc.strftime('%Y%m%d%H%M%S')
end