preact 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/preact.rb +34 -0
- data/lib/preact/objects/account_event.rb +12 -0
- data/lib/preact/objects/action_event.rb +0 -30
- data/lib/preact/objects/action_link.rb +14 -0
- data/lib/preact/objects/event.rb +14 -1
- data/lib/preact/version.rb +1 -1
- metadata +3 -1
data/lib/preact.rb
CHANGED
@@ -5,6 +5,8 @@ require 'preact/objects/api_object'
|
|
5
5
|
require 'preact/objects/person'
|
6
6
|
require 'preact/objects/event'
|
7
7
|
require 'preact/objects/action_event'
|
8
|
+
require 'preact/objects/action_link'
|
9
|
+
require 'preact/objects/account_event'
|
8
10
|
require 'preact/objects/message'
|
9
11
|
require 'preact/objects/account'
|
10
12
|
|
@@ -73,6 +75,38 @@ module Preact
|
|
73
75
|
|
74
76
|
send_log(person.as_json, preact_event.as_json)
|
75
77
|
end
|
78
|
+
|
79
|
+
def log_account_event(event, account)
|
80
|
+
# Don't send requests when disabled
|
81
|
+
if configuration.disabled?
|
82
|
+
logger.info "[Preact] Logging is disabled, not logging event"
|
83
|
+
return nil
|
84
|
+
elsif account.nil?
|
85
|
+
logger.error "[Preact] No account specified, not logging event"
|
86
|
+
return nil
|
87
|
+
elsif event.nil?
|
88
|
+
logger.error "[Preact] No event specified, not logging event"
|
89
|
+
return nil
|
90
|
+
end
|
91
|
+
|
92
|
+
if event.is_a?(String)
|
93
|
+
preact_event = AccountEvent.new({
|
94
|
+
:name => event,
|
95
|
+
:timestamp => Time.now.to_f
|
96
|
+
})
|
97
|
+
elsif event.is_a?(Hash)
|
98
|
+
preact_event = AccountEvent.new(event)
|
99
|
+
elsif event.is_a?(AccountEvent)
|
100
|
+
preact_event = event
|
101
|
+
else
|
102
|
+
raise StandardError.new "Unknown event class, must pass a string event name, event hash or AccountEvent object"
|
103
|
+
end
|
104
|
+
|
105
|
+
# attach the account info to the event
|
106
|
+
preact_event.account = configuration.convert_to_account(account).as_json
|
107
|
+
|
108
|
+
send_log(nil, preact_event.as_json)
|
109
|
+
end
|
76
110
|
|
77
111
|
def update_person(user)
|
78
112
|
# Don't send requests when disabled
|
@@ -1,35 +1,5 @@
|
|
1
1
|
module Preact
|
2
2
|
class ActionEvent < Event
|
3
3
|
|
4
|
-
attr_accessor :note, :links, :external_identifier, :extras
|
5
|
-
|
6
|
-
def add_link(name, href)
|
7
|
-
self.links ||= []
|
8
|
-
self.links << ActionLink.new({ :name => name, :href => href })
|
9
|
-
end
|
10
|
-
|
11
|
-
def as_json(options={})
|
12
|
-
super(options).merge({
|
13
|
-
:klass => "actionevent",
|
14
|
-
:note => self.note,
|
15
|
-
:external_identifier => self.external_identifier,
|
16
|
-
:extras => self.extras,
|
17
|
-
:links => self.links.nil? ? nil : self.links.as_json
|
18
|
-
})
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
class ActionLink < ApiObject
|
24
|
-
|
25
|
-
attr_accessor :name, :href
|
26
|
-
|
27
|
-
def as_json
|
28
|
-
{
|
29
|
-
:name => self.name,
|
30
|
-
:href => self.href
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
4
|
end
|
35
5
|
end
|
data/lib/preact/objects/event.rb
CHANGED
@@ -2,12 +2,25 @@ class Preact::Event < Preact::ApiObject
|
|
2
2
|
|
3
3
|
attr_accessor :name, :timestamp, :account
|
4
4
|
|
5
|
+
attr_accessor :note, :links, :external_identifier, :extras
|
6
|
+
|
7
|
+
def add_link(name, href)
|
8
|
+
self.links ||= []
|
9
|
+
self.links << ActionLink.new({ :name => name, :href => href })
|
10
|
+
end
|
11
|
+
|
5
12
|
def as_json(options={})
|
6
13
|
{
|
14
|
+
:klass => "actionevent",
|
7
15
|
:name => self.name,
|
8
16
|
:timestamp => self.timestamp,
|
9
17
|
:account => self.account,
|
10
|
-
:source => Preact.configuration.user_agent # version of this logging library
|
18
|
+
:source => Preact.configuration.user_agent, # version of this logging library
|
19
|
+
|
20
|
+
:note => self.note,
|
21
|
+
:external_identifier => self.external_identifier,
|
22
|
+
:extras => self.extras,
|
23
|
+
:links => self.links.nil? ? nil : self.links.as_json
|
11
24
|
}
|
12
25
|
end
|
13
26
|
|
data/lib/preact/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: preact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -119,7 +119,9 @@ files:
|
|
119
119
|
- lib/preact/client.rb
|
120
120
|
- lib/preact/configuration.rb
|
121
121
|
- lib/preact/objects/account.rb
|
122
|
+
- lib/preact/objects/account_event.rb
|
122
123
|
- lib/preact/objects/action_event.rb
|
124
|
+
- lib/preact/objects/action_link.rb
|
123
125
|
- lib/preact/objects/api_object.rb
|
124
126
|
- lib/preact/objects/event.rb
|
125
127
|
- lib/preact/objects/message.rb
|