Class: PlaylyfeClient::V2::Connection

Inherits:
Connection
  • Object
show all
Defined in:
lib/playlyfe_client/v2/connection.rb

Instance Attribute Summary

Attributes inherited from Connection

#sdk_version

Instance Method Summary collapse

Methods inherited from Connection

#api, #api_version, #check_token, createJWT, #delete, #exchange_code, #get, #get_access_token, #get_login_url, #get_logout_url, #get_raw, #hash_to_query, #initialize, #patch, #post, #put

Constructor Details

This class inherits a constructor from PlaylyfeClient::Connection

Instance Method Details

#delete_player(player_id) ⇒ Object



117
118
119
# 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_idObject

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



28
29
30
31
32
33
34
# 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) ⇒ Object



36
37
38
# File 'lib/playlyfe_client/v2/connection.rb', line 36

def dummy_player_id=(id)
  @dummy_player_id= id
end

#gameObject



7
8
9
# 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) ⇒ Object



88
89
90
# 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_hashObject



40
41
42
# 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) ⇒ Object



84
85
86
# 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) ⇒ Object



80
81
82
# 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) ⇒ Object



96
97
98
# 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) ⇒ Object



68
69
70
# 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_hashObject



48
49
50
# 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) ⇒ Object



72
73
74
# 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_hashObject



60
61
62
# 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) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
# 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_hashObject



44
45
46
# 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) ⇒ Object



56
57
58
# 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) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# 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_arrayObject



52
53
54
# 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) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# 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_arrayObject



64
65
66
# 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) ⇒ Object



76
77
78
# 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) ⇒ Object



113
114
115
# 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 = {}) ⇒ Object



92
93
94
# 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!Object



11
12
13
# File 'lib/playlyfe_client/v2/connection.rb', line 11

def reset_game!
  @game=nil
end

#skip_errors_with(skipping_result, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# 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