class PlaylyfeClient::V2::Connection

Public Instance Methods

delete_player(player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 117
def delete_player(player_id)
  skip_errors_with(nil) { delete("/admin/players/#{player_id}") }
end
dummy_player_id() click to toggle source

for calls to “runtime” there MUST be a player_id, even for Metrics or Leaderboards. So we pick first one.

# File lib/playlyfe_client/v2/connection.rb, line 28
def dummy_player_id
  unless defined?(@dummy_player_id)
    fph= get_full_players_hash["data"]
    @dummy_player_id=fph.empty? ? 0 : fph.first["id"]
  end
  @dummy_player_id
end
dummy_player_id=(id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 36
def dummy_player_id=(id)
  @dummy_player_id= id
end
game() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 7
def game
  @game ||= PlaylyfeClient::V2::Game.find_by_connection(self)
end
get_full_all_actions_array(player_id=dummy_player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 88
def get_full_all_actions_array(player_id=dummy_player_id)
  skip_errors_with([]) { get("/runtime/actions", {player_id: player_id}) }
end
get_full_game_hash() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 40
def get_full_game_hash
  skip_errors_with({"name" => "unknown", "game" => {"id" => 0 ,"title" => "no response"}}) { self.get('/admin') }
end
get_full_leaderboard_hash(leaderboard_id, cycle="alltime", player_id=dummy_player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 84
def get_full_leaderboard_hash(leaderboard_id, cycle="alltime", player_id=dummy_player_id)
  skip_errors_with({"data" => [], "total" => 0}) { get("/runtime/leaderboards/#{leaderboard_id}", {cycle: cycle, player_id: player_id, limit: 1_000_000 }) }
end
get_full_leaderboards_array(player_id=dummy_player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 80
def get_full_leaderboards_array(player_id=dummy_player_id)
  skip_errors_with([]) { get("/runtime/leaderboards", {player_id: player_id}) }
end
get_full_metrics_array(player_id=dummy_player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 96
def get_full_metrics_array(player_id=dummy_player_id)
  skip_errors_with([]) { get("/runtime/definitions/metrics", {player_id: player_id}) }
end
get_full_player_profile_hash(player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 68
def get_full_player_profile_hash(player_id)
  skip_errors_with({"id" => "0", "alias" => "no response", "scores" => [],  "teams" => []}) { get("/admin/players/#{player_id}") }
end
get_full_players_hash() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 48
def get_full_players_hash
  skip_errors_with({"data" => [], "total" => 0}) { get("/admin/players", { limit: 1_000_000 } ) }
end
get_full_team_members_hash(team_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 72
def get_full_team_members_hash(team_id)
  skip_errors_with({"data" => [], "total" => 0}) { get("/admin/teams/#{team_id}/members") }
end
get_full_teams_hash() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 60
def get_full_teams_hash
  skip_errors_with({"data" => [], "total" => 0}) { get("/admin/teams", { limit: 1_000_000 }) }
end
get_game_events_array(start_time=nil, end_time=nil) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 121
def get_game_events_array(start_time=nil, end_time=nil)
  skip_errors_with([]) do 
    if start_time
      #get specified period of time
      get("/admin/activity",{"start" => start_str(start_time), "end" => end_str(end_time)})
    else
      #get last 24 hours
      get("/admin/activity")
    end 
  end  
end
get_game_hash() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 44
def get_game_hash
  get_full_game_hash["game"]  
end
get_game_image_data(player_id=dummy_player_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 56
def get_game_image_data(player_id=dummy_player_id)
  skip_errors_with(nil) { get_raw("/runtime/assets/game", {size: style.to_s, player_id: player_id}) }
end
get_player_events_array(player_id, start_time=nil, end_time=nil) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 100
def get_player_events_array(player_id, start_time=nil, end_time=nil)
  #/admin/players/player2/activity?start=2016-05-01T00:00:00Z&end=2016-05-21T00:00:00Z
  skip_errors_with([]) do 
    if start_time
      #get specified period of time
      get("/admin/players/#{player_id}/activity",{"start" => start_str(start_time), "end" => end_str(end_time)})
    else
      #get last 24 hours
      get("/admin/players/#{player_id}/activity")
    end  
  end
end
get_player_hash_array() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 52
def get_player_hash_array
  get_full_players_hash["data"]
end
get_team_events_array(team_id, start_time=nil, end_time=nil) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 133
def get_team_events_array(team_id, start_time=nil, end_time=nil)
  skip_errors_with([]) do 
    if start_time
      #get specified period of time
      get("/admin/teams/#{team_id}/activity",{"start" => start_str(start_time), "end" => end_str(end_time)})
    else
      #get last 24 hours
      get("/admin/teams/#{team_id}/activity")
    end 
  end  
end
get_team_hash_array() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 64
def get_team_hash_array
  get_full_teams_hash["data"]
end
get_team_members_hash_array(team_id) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 76
def get_team_members_hash_array(team_id)
  get_full_team_members_hash(team_id)["data"]
end
post_create_player(player_h) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 113
def post_create_player(player_h)
  skip_errors_with({"id" => "0", "alias" => "no response", "scores" => [],  "teams" => []}) { post("/admin/players", {}, player_h) }
end
post_play_action(action_id, player_id, body ={}) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 92
def post_play_action(action_id, player_id, body ={})
  skip_errors_with({"actions" => [], "events" => []}) { post("/runtime/actions/#{action_id}/play", {player_id: player_id}, body) }
end
reset_game!() click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 11
def reset_game!
  @game=nil
end
skip_errors_with(skipping_result) { || ... } click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 15
def skip_errors_with(skipping_result, &block)
  begin
    yield
  rescue PlaylyfeClient::ApiCallsLimitExceededError => e
    if @skip_api_calls_limit_exceeded_error
      skipping_result
    else
      raise e  
    end  
  end  
end

Private Instance Methods

end_str(end_time) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 151
def end_str(end_time)
  end_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if end_time.kind_of?(Time)
end
start_str(start_time) click to toggle source
# File lib/playlyfe_client/v2/connection.rb, line 147
def start_str(start_time)
  start_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if start_time.kind_of?(Time)
end