preact 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/preact/client.rb +1 -1
- data/lib/preact/version.rb +1 -1
- data/lib/preact.rb +5 -7
- data/readme.md +23 -0
- metadata +1 -1
data/lib/preact/client.rb
CHANGED
data/lib/preact/version.rb
CHANGED
data/lib/preact.rb
CHANGED
@@ -42,8 +42,6 @@ module Preact
|
|
42
42
|
# Configure logger. Default to use Rails
|
43
43
|
self.logger ||= configuration.logger || (defined?(::Rails) ? ::Rails.logger : Logger.new(STDOUT))
|
44
44
|
|
45
|
-
raise StandardError.new "Must specify project code and secret when configuring the Preact api client" unless configuration.valid?
|
46
|
-
|
47
45
|
if defined? ::Rails
|
48
46
|
# load the rails extensions
|
49
47
|
require 'preact/rails'
|
@@ -56,12 +54,12 @@ module Preact
|
|
56
54
|
# if we're using Warden (Devise), load those extensions
|
57
55
|
require 'preact/warden'
|
58
56
|
end
|
59
|
-
|
57
|
+
|
60
58
|
end
|
61
59
|
|
62
60
|
def log_event(user, event, account = nil)
|
63
61
|
# Don't send requests when disabled
|
64
|
-
if configuration.nil? || configuration.disabled?
|
62
|
+
if configuration.nil? || configuration.disabled? || !configuration.valid?
|
65
63
|
logger.info "[Preact] Logging is disabled, not logging event"
|
66
64
|
return nil
|
67
65
|
elsif user.nil?
|
@@ -97,7 +95,7 @@ module Preact
|
|
97
95
|
|
98
96
|
def log_account_event(event, account)
|
99
97
|
# Don't send requests when disabled
|
100
|
-
if configuration.nil? || configuration.disabled?
|
98
|
+
if configuration.nil? || configuration.disabled? || !configuration.valid?
|
101
99
|
logger.info "[Preact] Logging is disabled, not logging event"
|
102
100
|
return nil
|
103
101
|
elsif account.nil?
|
@@ -129,7 +127,7 @@ module Preact
|
|
129
127
|
|
130
128
|
def update_person(user)
|
131
129
|
# Don't send requests when disabled
|
132
|
-
if configuration.nil? || configuration.disabled?
|
130
|
+
if configuration.nil? || configuration.disabled? || !configuration.valid?
|
133
131
|
logger.info "[Preact] Logging is disabled, not logging event"
|
134
132
|
return nil
|
135
133
|
elsif user.nil?
|
@@ -144,7 +142,7 @@ module Preact
|
|
144
142
|
|
145
143
|
def update_account(account)
|
146
144
|
# Don't send requests when disabled
|
147
|
-
if configuration.nil? || configuration.disabled?
|
145
|
+
if configuration.nil? || configuration.disabled? || !configuration.valid?
|
148
146
|
logger.info "[Preact] Logging is disabled, not updating account"
|
149
147
|
return nil
|
150
148
|
elsif account.nil?
|
data/readme.md
CHANGED
@@ -92,6 +92,27 @@ class DocumentsController < ApplicationController
|
|
92
92
|
end
|
93
93
|
```
|
94
94
|
|
95
|
+
#### B2B Event Logging
|
96
|
+
|
97
|
+
If you are logging Accounts in a B2B context, you may find it useful to override the preact_log helper at the ApplicationController level.
|
98
|
+
|
99
|
+
Typically, you'll have a variable or method which provides the current context that the `@current_user` is acting under. For us, it's called `@current_project`.
|
100
|
+
|
101
|
+
Adding this override will make sure that everywhere you call preact_log, it will automatically include the account context when logging events.
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
class ApplicationController
|
105
|
+
|
106
|
+
def preact_log(event, account=nil)
|
107
|
+
account ||= @current_project
|
108
|
+
super(event, account)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
Note: If you make this change in your ApplicationControler, make sure you add it to any other base controllers you have that don't inherit from ApplicationController (e.g. your API base controller, etc)
|
115
|
+
|
95
116
|
Usage
|
96
117
|
---
|
97
118
|
|
@@ -169,6 +190,8 @@ Preact.log_event(@current_user, 'restored_answer_data')
|
|
169
190
|
Preact.log_event(@current_user, { :name => 'updated-profile', :extras => {:twitter => "@gooley"} })
|
170
191
|
```
|
171
192
|
|
193
|
+
#### B2B Account mapping method
|
194
|
+
|
172
195
|
Likewise, if you are a Preact B2B user, you can define the `to_preact` method on the model that defines your Account grouping. For instance, if you attach your Users into "Projects" you would add the `to_preact` method into your Project model.
|
173
196
|
|
174
197
|
```ruby
|