playlyfe_client 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 193418f3fbbd9cb946f415e2c90e8277a134153e
4
- data.tar.gz: 4774b952eca4d59831f33755454f5512f2cd7ff9
3
+ metadata.gz: 170a7ef3d15bd9bb481d9e1ba25913fec61f3f3a
4
+ data.tar.gz: ed8b757df181b7e8379e12c4ff6830df4ee0be88
5
5
  SHA512:
6
- metadata.gz: 33b415033499ea4b757a90e4942e8c6e3dffa613e9c615b5ef7bc93cda7916d9902c937538d5ae16650b24e535739fc95be9236fd90b97b1724300a87ae11159
7
- data.tar.gz: c7299c3e9c1c1a61c82fb873b9d4b87b0da568b435b4e9a4858492375f1be4aff0177fd0caec357918d1f73ff25ee8616f53ee81bb0c71f01b0538115fd6fccc
6
+ metadata.gz: 525d488f25edd8ecf245c541acaa90dca294cdca4064ebd70fef8e118ccdda60572e80f6b9c0ed3b8b7a571c99295b5fb43728ea71e0978293668938a672e569
7
+ data.tar.gz: 91ba1e4b33d306f0a5732bc18e89d23baea470ddf307e5d2a8788f7336f9884d7db759f4a19b99e24aab1fe8700b5484c26e03a8def8d156163e9b6bd9096295
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- playlyfe_client (1.0.6)
4
+ playlyfe_client (1.1.0)
5
5
  json
6
6
  jwt
7
7
  rest-client
@@ -13,7 +13,7 @@ GEM
13
13
  builder (3.2.2)
14
14
  byebug (9.0.5)
15
15
  coderay (1.1.1)
16
- domain_name (0.5.20160310)
16
+ domain_name (0.5.20160615)
17
17
  unf (>= 0.0.5, < 1.0.0)
18
18
  http-cookie (1.0.2)
19
19
  domain_name (~> 0.5)
@@ -61,4 +61,4 @@ DEPENDENCIES
61
61
  rest-client
62
62
 
63
63
  BUNDLED WITH
64
- 1.10.6
64
+ 1.12.5
data/README.md CHANGED
@@ -48,8 +48,8 @@ Or install it yourself as:
48
48
 
49
49
  ## Usage
50
50
 
51
- You have to setup a client at PlaylyfeClient which can access API (only paid plans) form your backend.
52
- Client shoul have 'Client Credential Flow' , all checks at config page should be on YES and should have all scopes with RW access.
51
+ You have to setup a client at PlaylyfeClient which can access API (only paid plans) from your backend.
52
+ Client should have 'Client Credential Flow' , all checks at config page should be on YES and should have all scopes with RW access.
53
53
 
54
54
  Then in your code initialize connection:
55
55
 
@@ -139,7 +139,7 @@ module PlaylyfeClient
139
139
  if response.body == 'null'
140
140
  return nil
141
141
  else
142
- return JSON.parse(response.body)
142
+ return JSON.parse(response.body)#, symbolize_names: true)
143
143
  end
144
144
  end
145
145
  rescue => e
@@ -11,6 +11,7 @@ module PlaylyfeClient
11
11
  class MetricError < PlaylyfeClient::Error; end
12
12
  class PlaylyfeClient::ActionRateLimitExceededError < PlaylyfeClient::ActionError; end
13
13
  class PlaylyfeClient::PlayerExistsError < PlaylyfeClient::PlayerError; end
14
+ class PlaylyfeClient::CollectionFindOneIsNotSupportedError < PlaylyfeClient::Error; end
14
15
 
15
16
  class Error < StandardError
16
17
  attr_accessor :name, :message
@@ -24,6 +24,10 @@ module PlaylyfeClient
24
24
  []
25
25
  end
26
26
 
27
+ def events
28
+ []
29
+ end
30
+
27
31
  private
28
32
 
29
33
  def initialize(conn)
@@ -68,7 +68,7 @@ module PlaylyfeClient
68
68
  []
69
69
  end
70
70
 
71
- def activities(start_time=nil,end_time=nil)
71
+ def events(start_time=nil,end_time=nil)
72
72
  []
73
73
  end
74
74
 
@@ -17,6 +17,10 @@ module PlaylyfeClient
17
17
  []
18
18
  end
19
19
 
20
+ def events
21
+ []
22
+ end
23
+
20
24
  private
21
25
 
22
26
  def initialize(game)
@@ -0,0 +1,37 @@
1
+ require_relative "../collection.rb"
2
+ require_relative "../event.rb"
3
+ #require_relative "../event/process/*.rb"
4
+ #require_relative "../event/team/*.rb"
5
+
6
+ module PlaylyfeClient
7
+ module V2
8
+ class EventCollection < PlaylyfeClient::V2::Collection
9
+
10
+ def find(str)
11
+ e=PlaylyfeClient::CollectionFindOneIsNotSupportedError.new
12
+ e.name="Find item is not supported"
13
+ e.message="This collections has no unique key, so no use for collection.find."
14
+ raise e
15
+ end
16
+
17
+ private
18
+
19
+ def initialize(game, event_array=[], player_team_or_process=nil)
20
+ @game= game
21
+ @items=[]
22
+ event_array= game.connection.get_game_events_array if event_array == []
23
+ fill_items(event_array,player_team_or_process)
24
+ end
25
+
26
+ def fill_items(hash_array, player_team_or_process)
27
+ hash_array.each do |event_hash|
28
+ # binding.pry
29
+ @items << PlaylyfeClient::V2::Event.build(event_hash, @game, player_team_or_process)
30
+ end
31
+ end
32
+
33
+
34
+ end
35
+ end
36
+ end
37
+
@@ -1,4 +1,3 @@
1
-
2
1
  require_relative "../connection.rb"
3
2
 
4
3
  module PlaylyfeClient
@@ -82,14 +81,11 @@ module PlaylyfeClient
82
81
  get("/runtime/definitions/metrics", {player_id: player_id})
83
82
  end
84
83
 
85
- def get_full_activity_feed_array(player_id, start_time=nil, end_time=nil)
86
- start_str=start_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if start_time.kind_of?(Time)
87
- end_str=end_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if start_time.kind_of?(Time)
88
-
84
+ def get_player_events_array(player_id, start_time=nil, end_time=nil)
89
85
  #/admin/players/player2/activity?start=2016-05-01T00:00:00Z&end=2016-05-21T00:00:00Z
90
86
  if start_time
91
87
  #get specified period of time
92
- get("/admin/players/#{player_id}/activity",{"start" => start_str, "end" => end_str})
88
+ get("/admin/players/#{player_id}/activity",{"start" => start_str(start_time), "end" => end_str(end_time)})
93
89
  else
94
90
  #get last 24 hours
95
91
  get("/admin/players/#{player_id}/activity")
@@ -102,8 +98,38 @@ module PlaylyfeClient
102
98
 
103
99
  def delete_player(player_id)
104
100
  delete("/admin/players/#{player_id}")
101
+ end
102
+
103
+ def get_game_events_array(start_time=nil, end_time=nil)
104
+ if start_time
105
+ #get specified period of time
106
+ get("/admin/activity",{"start" => start_str(start_time), "end" => end_str(end_time)})
107
+ else
108
+ #get last 24 hours
109
+ get("/admin/activity")
110
+ end
105
111
  end
106
112
 
113
+ def get_team_events_array(team_id, start_time=nil, end_time=nil)
114
+ if start_time
115
+ #get specified period of time
116
+ get("/admin/teams/#{team_id}/activity",{"start" => start_str(start_time), "end" => end_str(end_time)})
117
+ else
118
+ #get last 24 hours
119
+ get("/admin/teams/#{team_id}/activity")
120
+ end
121
+ end
122
+
123
+ private
124
+
125
+ def start_str(start_time)
126
+ start_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if start_time.kind_of?(Time)
127
+ end
128
+
129
+ def end_str(end_time)
130
+ end_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if end_time.kind_of?(Time)
131
+ end
132
+
107
133
  end
108
134
  end
109
135
  end
@@ -0,0 +1,101 @@
1
+ module PlaylyfeClient
2
+ module V2
3
+ module PlayerEvent
4
+ class Base < PlaylyfeClient::V2::Event
5
+ attr_reader :actor_id, :actor_alias #who trigger event (player or admin)
6
+ attr_reader :player_id, :player_alias #who receive results of event (player)
7
+ attr_reader :rule , :process, :action #what triggers event
8
+ attr_reader :count #The count with which the action was played.
9
+ attr_reader :changes
10
+
11
+ def player
12
+ game.players.find(player_id)
13
+ end
14
+
15
+ private
16
+
17
+ def initialize(ev_hash,game,player=nil)
18
+ super(ev_hash,game)
19
+
20
+
21
+ if @ev_hash.has_key?("actor")
22
+ @actor_id=@ev_hash["actor"]["id"]
23
+ @actor_alias=@ev_hash["actor"]["alias"]
24
+ else
25
+ if player.nil?
26
+ raise "cannot create actor from hash #{@ev_hash} and player #{player}"
27
+ else
28
+ @actor_id=player.id
29
+ @actor_alias=player.alias
30
+ end
31
+ end
32
+
33
+ @rule= @ev_hash["rule"]["id"] unless @ev_hash["rule"].nil?
34
+ @process= @ev_hash["process"]["id"] unless @ev_hash["process"].nil?
35
+ @action= @ev_hash["action"]["id"] unless @ev_hash["action"].nil?
36
+ @count= @ev_hash["count"] || 0
37
+
38
+ @player_id=@actor_id
39
+ @player_alias=@actor_alias
40
+ if @ev_hash.has_key?("player")
41
+ @player_id=@ev_hash["player"]["id"]
42
+ @player_alias=@ev_hash["player"]["alias"]
43
+ end
44
+
45
+ set_changes
46
+
47
+ end
48
+
49
+ def set_changes
50
+ @changes=[]
51
+ return @changes if @ev_hash["changes"].nil?
52
+
53
+ for ch in @ev_hash["changes"]
54
+
55
+ if ch["delta"].has_key?("old")
56
+ chng={delta: [ ch["delta"]["old"], ch["delta"]["new"] ]}
57
+ else
58
+ k=ch["delta"].keys.first
59
+ chng={delta: [ ch["delta"][k]["old"], ch["delta"][k]["new"], k ]}
60
+ end
61
+ chng[:metric]=game.metrics.find(ch["metric"]["id"])
62
+
63
+ @changes << chng
64
+ end
65
+ end
66
+
67
+
68
+ end
69
+
70
+ class LevelChangedEvent < PlaylyfeClient::V2::PlayerEvent::Base; end
71
+ class AchievementEvent < PlaylyfeClient::V2::PlayerEvent::Base; end
72
+ class ActionPlayedEvent < PlaylyfeClient::V2::PlayerEvent::Base; end
73
+ class CustomRuleAppliedEvent < PlaylyfeClient::V2::PlayerEvent::Base; end
74
+ class ScoreUpdatedByAdminEvent < PlaylyfeClient::V2::PlayerEvent::Base; end
75
+
76
+ class Base
77
+
78
+ def self.build(ev_hash, game, player=nil)
79
+ case ev_hash["event"]
80
+ when "level"
81
+ klass= LevelChangedEvent
82
+ when "action"
83
+ klass= ActionPlayedEvent
84
+ when "achievement"
85
+ klass= AchievementEvent
86
+ when "custom_rule"
87
+ klass= CustomRuleAppliedEvent
88
+ when "score"
89
+ klass= ScoreUpdatedByAdminEvent
90
+ else
91
+ return nil
92
+ end
93
+
94
+ return klass.new(ev_hash, game, player)
95
+ end
96
+
97
+ end
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,88 @@
1
+ module PlaylyfeClient
2
+ module V2
3
+ module ProcessEvent
4
+ class Base < PlaylyfeClient::V2::Event
5
+
6
+ private
7
+
8
+ def initialize(ev_hash,game,process_or_player=nil)
9
+ super(ev_hash,game)
10
+
11
+ end
12
+
13
+ end
14
+
15
+ class ProcessCreatedEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
16
+ class RequestToJoinEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
17
+ class JoinAcceptedEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "player"; end; end
18
+ class JoinRejectedEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
19
+ class InviteSendEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "invitee"; end; end
20
+ class InviteAcceptedEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "inviter"; end; end
21
+ class InviteRejectedEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "inviter"; end; end
22
+ class JoinedEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
23
+ class RolesChangedEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; (event == "role:assign" ? "player" : nil ); end; end
24
+ class RequestForChangeOfRolesEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
25
+ class ChangeOfRolesAcceptedEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "player"; end; end
26
+ class ChangeOfRolesRejectedEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
27
+ class KickedOutEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "player"; end; end
28
+ class LeavedEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
29
+ class ProcessDeletedEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
30
+ class ProcessOwnershipTransferredEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "new_owner"; end; end
31
+ class ProgressEvent < PlaylyfeClient::V2::ProcessEvent::Base; def target_key; "new_owner"; end; end
32
+ class ResolutionEvent < PlaylyfeClient::V2::ProcessEvent::Base; end
33
+
34
+ class Base
35
+
36
+ def self.build(ev_hash, game, process=nil)
37
+ case ev_hash["event"]
38
+ when "create"
39
+ klass= ProcessCreatedEvent
40
+ when "delete"
41
+ klass= ProcessDeletedEvent
42
+ when "join"
43
+ klass= JoinedEvent
44
+ when "join:request"
45
+ klass= RequestToJoinEvent
46
+ when "leave"
47
+ klass= LeavedEvent
48
+ when "role:change","role:assign"
49
+ klass= RolesChangedEvent
50
+ when "role:request"
51
+ klass= RequestForChangeOfRolesEvent
52
+ when "join:request:accept"
53
+ klass= JoinAcceptedEvent
54
+ when "role:request:accept"
55
+ klass= ChangeOfRolesAcceptedEvent
56
+ when "join:request:reject"
57
+ klass= JoinRejectedEvent
58
+ when "invite"
59
+ klass= InviteSendEvent
60
+ when "invite:accept"
61
+ klass= InviteAcceptedEvent
62
+ when "invite:reject"
63
+ klass= InviteRejectedEvent
64
+ when "kick"
65
+ klass= KickedOutEvent
66
+ when "transfer"
67
+ klass= ProcessOwnershipTransferredEvent
68
+ when "progress"
69
+ klass=ProgressEvent
70
+ when "resolution"
71
+ klass=ResolutionEvent
72
+ else
73
+ return nil
74
+ end
75
+
76
+ return klass.new(ev_hash, game, player)
77
+ end
78
+
79
+ def two_player_event?
80
+ [JoinAcceptedEvent,ChangeOfRolesAcceptedEvent,InviteSendEvent,InviteAcceptedEvent,InviteRejectedEvent, KickedOutEvent,RolesChangedEvent,TeamOwnershipTransferredEvent].include?(self.class)
81
+ end
82
+
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+
@@ -0,0 +1,196 @@
1
+ module PlaylyfeClient
2
+ module V2
3
+ module TeamEvent
4
+ class Base < PlaylyfeClient::V2::Event
5
+ attr_reader :from_player_id, :from_player_alias #who trigger event (player or admin)
6
+ attr_reader :target_player_id, :target_player_alias #who recieve effects of event
7
+ attr_reader :team_id, :team_name
8
+ attr_reader :roles, :changes
9
+
10
+ def from_player
11
+ @from_player ||=game.players.find(from_player_id)
12
+ end
13
+ alias_method :actor, :from_player
14
+ alias_method :actor_id, :from_player_id
15
+ alias_method :actor_alias, :from_player_alias
16
+
17
+ def target_player
18
+ @tagert_player=game.players.find(target_player_id)
19
+ end
20
+ alias_method :inviter, :target_player
21
+ alias_method :invitee, :target_player
22
+ alias_method :new_owner, :target_player
23
+ alias_method :player, :target_player
24
+
25
+ alias_method :inviter_id, :target_player_id
26
+ alias_method :invitee_id, :target_player_id
27
+ alias_method :new_owner_id, :target_player_id
28
+ alias_method :player_id, :target_player_id
29
+
30
+ alias_method :inviter_alias, :target_player_alias
31
+ alias_method :invitee_alias, :target_player_alias
32
+ alias_method :new_owner_alias, :target_player_alias
33
+ alias_method :player_alias, :target_player_alias
34
+
35
+ def team
36
+ @team ||=game.teams.find(team_id)
37
+ end
38
+
39
+ private
40
+
41
+ def initialize(ev_hash,game,team_or_player=nil)
42
+ super(ev_hash,game)
43
+
44
+ set_from_player(team_or_player)
45
+ set_target_player(team_or_player)
46
+ set_team(team_or_player)
47
+ set_roles
48
+ set_changes
49
+
50
+ end
51
+
52
+ def set_from_player(team_or_player)
53
+ if @ev_hash["actor"].nil?
54
+ if team_or_player.kind_of?(PlaylyfeClient::Player)
55
+ @from_player_id=team_or_player.id
56
+ @from_player_alias=team_or_player.alias
57
+ else
58
+ raise "cannot create actor/from_player from hash #{@ev_hash} and player #{team_or_player}"
59
+ end
60
+ else
61
+ @from_player_id=@ev_hash["actor"]["id"]
62
+ @from_player_alias=@ev_hash["actor"]["alias"]
63
+ end
64
+ end
65
+
66
+
67
+ def target_key
68
+ nil
69
+ end
70
+
71
+ def set_target_player(team_or_player)
72
+ return if target_key.nil?
73
+
74
+ if @ev_hash[target_key].nil?
75
+ if two_player_event?
76
+ if team_or_player.kind_of?(PlaylyfeClient::Player)
77
+ @target_player_id=team_or_player.id
78
+ @target_player_alias=team_or_player.alias
79
+ else
80
+ raise "cannot create #{target_key} from hash #{@ev_hash} and player #{team_or_player}"
81
+ end
82
+ end
83
+ else
84
+ @target_player_id=@ev_hash[target_key]["id"]
85
+ @target_player_alias=@ev_hash[target_key]["alias"]
86
+ end
87
+ end
88
+
89
+ def set_team(team_or_player)
90
+ if @ev_hash["team"].nil?
91
+ if team_or_player.kind_of?(PlaylyfeClient::Team)
92
+ @team_id=team_or_player.id
93
+ @team_name=team_or_player.name
94
+ else
95
+ raise "cannot create team from hash #{@ev_hash} and team #{team_or_player}"
96
+ end
97
+ else
98
+ @team_id=@ev_hash["team"]["id"]
99
+ @team_name=@ev_hash["team"]["name"]
100
+ end
101
+ end
102
+
103
+ def set_changes
104
+ @changes=[]
105
+ roles=[]
106
+ return @changes if @ev_hash["changes"].nil?
107
+
108
+ @ev_hash["changes"].keys.each do |role|
109
+ chng={delta: [ @ev_hash["changes"][role]["old"], @ev_hash["changes"][role]["new"], role ]}
110
+ @changes << chng
111
+ roles << role if @ev_hash["changes"][role]["new"] == true
112
+ end
113
+ @roles = (@roles+roles).uniq
114
+ @changes
115
+ end
116
+
117
+
118
+ def set_roles
119
+ @roles=[]
120
+ return @roles if @ev_hash["roles"].nil?
121
+
122
+ for k in @ev_hash["roles"].keys
123
+ @roles << k if @ev_hash["roles"][k]
124
+ end
125
+ @roles
126
+ end
127
+ end
128
+
129
+ class TeamCreatedEvent < PlaylyfeClient::V2::TeamEvent::Base; end
130
+ class RequestToJoinEvent < PlaylyfeClient::V2::TeamEvent::Base; end
131
+ class JoinAcceptedEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "player"; end; end
132
+ class JoinRejectedEvent < PlaylyfeClient::V2::TeamEvent::Base; end
133
+ class InviteSendEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "invitee"; end; end
134
+ class InviteAcceptedEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "inviter"; end; end
135
+ class InviteRejectedEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "inviter"; end; end
136
+ class JoinedEvent < PlaylyfeClient::V2::TeamEvent::Base; end
137
+ class RolesChangedEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; (event == "role:assign" ? "player" : nil ); end; end
138
+ class RequestForChangeOfRolesEvent < PlaylyfeClient::V2::TeamEvent::Base; end
139
+ class ChangeOfRolesAcceptedEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "player"; end; end
140
+ class ChangeOfRolesRejectedEvent < PlaylyfeClient::V2::TeamEvent::Base; end
141
+ class KickedOutEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "player"; end; end
142
+ class LeavedEvent < PlaylyfeClient::V2::TeamEvent::Base; end
143
+ class TeamDeletedEvent < PlaylyfeClient::V2::TeamEvent::Base; end
144
+ class TeamOwnershipTransferredEvent < PlaylyfeClient::V2::TeamEvent::Base; def target_key; "new_owner"; end; end
145
+
146
+ class Base
147
+
148
+ def self.build(ev_hash, game, player=nil)
149
+ case ev_hash["event"]
150
+ when "create"
151
+ klass= TeamCreatedEvent
152
+ when "delete"
153
+ klass= TeamDeletedEvent
154
+ when "join"
155
+ klass= JoinedEvent
156
+ when "join:request"
157
+ klass= RequestToJoinEvent
158
+ when "leave"
159
+ klass= LeavedEvent
160
+ when "role:change","role:assign"
161
+ klass= RolesChangedEvent
162
+ when "role:request"
163
+ klass= RequestForChangeOfRolesEvent
164
+ when "join:request:accept"
165
+ klass= JoinAcceptedEvent
166
+ when "role:request:accept"
167
+ klass= ChangeOfRolesAcceptedEvent
168
+ when "join:request:reject"
169
+ klass= JoinRejectedEvent
170
+ when "invite"
171
+ klass= InviteSendEvent
172
+ when "invite:accept"
173
+ klass= InviteAcceptedEvent
174
+ when "invite:reject"
175
+ klass= InviteRejectedEvent
176
+ when "kick"
177
+ klass= KickedOutEvent
178
+ when "transfer"
179
+ klass= TeamOwnershipTransferredEvent
180
+ else
181
+ return nil
182
+ end
183
+
184
+ return klass.new(ev_hash, game, player)
185
+ end
186
+
187
+ def two_player_event?
188
+ [JoinAcceptedEvent,ChangeOfRolesAcceptedEvent,InviteSendEvent,InviteAcceptedEvent,InviteRejectedEvent, KickedOutEvent,RolesChangedEvent,TeamOwnershipTransferredEvent].include?(self.class)
189
+ end
190
+
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+
@@ -0,0 +1,42 @@
1
+ module PlaylyfeClient
2
+ module V2
3
+ class Event
4
+ attr_reader :event, :timestamp, :game
5
+
6
+ def created_at
7
+ @timestamp
8
+ end
9
+
10
+ private
11
+
12
+ def initialize(ev_hash,game)
13
+ @event=ev_hash[:event] || ev_hash["event"]
14
+ ts=ev_hash[:timestamp] || ev_hash["timestamp"]
15
+ @timestamp= (ts.kind_of?(Time) ? ts : Time.parse(ts) )
16
+ @game=game
17
+ @ev_hash=ev_hash
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+ require_relative "./event/player_event.rb"
25
+ require_relative "./event/team_event.rb"
26
+ require_relative "./event/process_event.rb"
27
+
28
+
29
+ module PlaylyfeClient
30
+ module V2
31
+ class Event
32
+
33
+ def self.build(ev_hash, game, team_player_or_process=nil)
34
+ event= PlaylyfeClient::V2::PlayerEvent::Base.build(ev_hash,game,team_player_or_process)
35
+ event= PlaylyfeClient::V2::TeamEvent::Base.build(ev_hash,game,team_player_or_process) if event.nil?
36
+ event= PlaylyfeClient::V2::ProcessEvent::Base.build(ev_hash,game,team_player_or_process) if event.nil?
37
+ return event #could be nil!
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -4,6 +4,7 @@ require_relative "./collection/team_collection.rb"
4
4
  require_relative "./collection/leaderboard_collection.rb"
5
5
  require_relative "./collection/action_collection.rb"
6
6
  require_relative "./collection/metric_collection.rb"
7
+ require_relative "./collection/event_collection.rb"
7
8
 
8
9
  require_relative "../game.rb"
9
10
 
@@ -49,6 +50,10 @@ module PlaylyfeClient
49
50
  puts(data)
50
51
  end
51
52
 
53
+ def events
54
+ @events ||= PlaylyfeClient::V2::EventCollection.new(self)
55
+ end
56
+
52
57
  private
53
58
 
54
59
  def initialize(conn)
@@ -56,23 +56,8 @@ module PlaylyfeClient
56
56
  game.leaderboards.for_players
57
57
  end
58
58
 
59
- def activities(start_time=nil,end_time=nil)
60
- unless defined?(@activities)
61
- #loading all activities for player (not restricted to some time period, ALL of them!)
62
- @activities = build_activities_from(game.connection.get_full_activity_feed_array(self.id,self.game.created_at,Time.now.utc))
63
- end
64
-
65
- activities=@activities
66
-
67
- if start_time
68
- activities=activities.select {|act| act["timestamp"] > start_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") }
69
- end
70
-
71
- if end_time
72
- activities=activities.select {|act| act["timestamp"] < end_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") }
73
- end
74
-
75
- return activities
59
+ def events(start_time=nil,end_time=nil)
60
+ @events ||= PlaylyfeClient::V2::EventCollection.new(game, game.connection.get_player_events_array(self.id,start_time, end_time), self)
76
61
  end
77
62
 
78
63
  private
@@ -128,12 +113,6 @@ module PlaylyfeClient
128
113
  (value.each.collect {|item| {name: item["name"], count: item["count"].to_i} } )
129
114
  end
130
115
 
131
- def build_activities_from(array_of_hashes)
132
- #https://dev.playlyfe.com/docs/events.html
133
- #TODO: DO a Events :: now, just simple hashes
134
- array_of_hashes
135
- end
136
-
137
116
  end
138
117
  end
139
118
  end
@@ -13,6 +13,10 @@ module PlaylyfeClient
13
13
  def leaderboards
14
14
  @game.leaderboards.for_teams
15
15
  end
16
+
17
+ def events(start_time=nil,end_time=nil)
18
+ @events ||= PlaylyfeClient::V2::EventCollection.new(game, game.connection.get_team_events_array(self.id,start_time, end_time), self)
19
+ end
16
20
 
17
21
  private
18
22
 
@@ -1,3 +1,3 @@
1
1
  module PlaylyfeClient
2
- VERSION = "1.0.6"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playlyfe_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-14 00:00:00.000000000 Z
11
+ date: 2016-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -147,11 +147,16 @@ files:
147
147
  - lib/playlyfe_client/v2/action.rb
148
148
  - lib/playlyfe_client/v2/collection.rb
149
149
  - lib/playlyfe_client/v2/collection/action_collection.rb
150
+ - lib/playlyfe_client/v2/collection/event_collection.rb
150
151
  - lib/playlyfe_client/v2/collection/leaderboard_collection.rb
151
152
  - lib/playlyfe_client/v2/collection/metric_collection.rb
152
153
  - lib/playlyfe_client/v2/collection/player_collection.rb
153
154
  - lib/playlyfe_client/v2/collection/team_collection.rb
154
155
  - lib/playlyfe_client/v2/connection.rb
156
+ - lib/playlyfe_client/v2/event.rb
157
+ - lib/playlyfe_client/v2/event/player_event.rb
158
+ - lib/playlyfe_client/v2/event/process_event.rb
159
+ - lib/playlyfe_client/v2/event/team_event.rb
155
160
  - lib/playlyfe_client/v2/game.rb
156
161
  - lib/playlyfe_client/v2/leaderboard.rb
157
162
  - lib/playlyfe_client/v2/leaderboard/players_leaderboard.rb