vero 0.5.12 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +9 -0
- data/Gemfile.lock +1 -1
- data/README.markdown +89 -52
- data/lib/vero/context/api.rb +15 -9
- data/lib/vero/dsl.rb +1 -1
- data/lib/vero/trackable/base.rb +2 -2
- data/lib/vero/version.rb +1 -1
- data/spec/lib/api/events/track_api_spec.rb +6 -6
- data/spec/lib/api/users/edit_api_spec.rb +1 -1
- data/spec/lib/api/users/edit_tags_api_spec.rb +7 -7
- data/spec/lib/api/users/reidentify_spec.rb +1 -1
- data/spec/lib/api/users/track_api_spec.rb +8 -8
- data/spec/lib/api/users/unsubscribe_api_spec.rb +1 -1
- data/spec/lib/trackable_spec.rb +44 -100
- data/spec/support/user_support.rb +14 -0
- metadata +3 -2
data/CHANGES.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## 0.6.0
|
2
|
+
|
3
|
+
- **All APIs using the `trackable` interface will now pass up an `:id`** (if
|
4
|
+
it has been made available). In the past the gem would assume that the user's id
|
5
|
+
would always be equal to their email address, but now the gem properly implements
|
6
|
+
the Vero API.
|
7
|
+
|
8
|
+
- **`update_user!` method no longer takes an optional new email address as a
|
9
|
+
parameter**. It is recommended that the email be made a trackable field.
|
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# vero
|
2
2
|
[](https://travis-ci.org/getvero/vero)
|
3
3
|
|
4
|
-
vero makes it easy to interact with Vero's
|
4
|
+
[vero](https://github.com/getvero/vero) makes it easy to interact with Vero's
|
5
|
+
REST API from your Ruby app. Vero is an email marketing platform that allows you
|
6
|
+
to engage and re-engage your customer base based on the actions they perform in
|
7
|
+
your software.
|
5
8
|
|
6
|
-
For more information about the platform, [click here](http://getvero.com)
|
9
|
+
For more information about the platform, [click here](http://getvero.com).
|
7
10
|
|
8
11
|
## Installation
|
9
12
|
|
@@ -15,51 +18,63 @@ Or install the gem:
|
|
15
18
|
|
16
19
|
gem install vero
|
17
20
|
|
18
|
-
Create
|
19
|
-
|
21
|
+
Create an initializer in your config/initializers folder called vero.rb with the
|
22
|
+
following:
|
23
|
+
|
20
24
|
# config/initializers/vero.rb
|
21
25
|
Vero::App.init do |config|
|
22
26
|
config.api_key = "Your API key goes here"
|
23
27
|
config.secret = "Your API secret goes here"
|
24
28
|
end
|
25
29
|
|
26
|
-
You will be able to find your API key and secret by logging into Vero
|
30
|
+
You will be able to find your API key and secret by logging into Vero
|
31
|
+
([sign up](http://getvero.com) if you haven't already) and clicking the
|
32
|
+
'Your Account' link at the top of the page then select 'API Keys'.
|
27
33
|
|
28
|
-
By default, events are sent asynchronously using a background thread.
|
34
|
+
By default, events are sent asynchronously using a background thread.
|
35
|
+
We recommend that you select one of the supported queue-based alternatives:
|
29
36
|
|
30
37
|
config.async = :none # Synchronously
|
31
38
|
config.async = :thread # Background thread (default)
|
32
39
|
config.async = :delayed_job # DelayedJob
|
33
|
-
config.async = :resque # Resque
|
40
|
+
config.async = :resque # Resque (recommended)
|
34
41
|
|
35
|
-
**Note:** Background threads are not supported by Ruby 1.8.7 or earlier.
|
42
|
+
**Note:** Background threads are not supported by Ruby 1.8.7 or earlier.
|
43
|
+
You must explicitly set `config.async` to either `:none`, `:delayed_job` or
|
44
|
+
`:resque`.
|
36
45
|
|
37
|
-
**Note:** If you're using
|
46
|
+
**Note:** If you're using Mongoid with DelayedJob, you must add
|
47
|
+
`gem "delayed_job_mongoid"` to your Gemfile.
|
38
48
|
|
39
|
-
Finally, vero will
|
49
|
+
Finally, vero will automatically choose whether to send requests to your
|
50
|
+
**development** or **live** environment if you are using Rails 3.x. You can
|
51
|
+
override this in your initializer:
|
40
52
|
|
41
53
|
config.development_mode = true # or false
|
42
54
|
|
43
55
|
## Setup tracking
|
44
56
|
|
45
|
-
You will need to define who should be tracked and what information about them
|
46
|
-
|
57
|
+
You will need to define who should be tracked and what information about them
|
58
|
+
you would like sent to Vero. In this example we'll track users:
|
59
|
+
|
47
60
|
# app/models/user.rb
|
48
61
|
class User < ActiveRecord::Base
|
49
|
-
include Vero::Trackable
|
50
|
-
trackable :
|
62
|
+
include Vero::Trackable
|
63
|
+
trackable :id, :email, :name
|
51
64
|
|
52
65
|
...
|
53
66
|
end
|
54
67
|
|
55
|
-
As you can see we're saying that a User is trackable and that we'd like to pass
|
68
|
+
As you can see we're saying that a User is trackable and that we'd like to pass
|
69
|
+
up their user id, email address, and name.
|
70
|
+
|
71
|
+
Each symbol passed to trackable should reference either an instance method or
|
72
|
+
field. Therefore it's perfectly legal to do something like:
|
56
73
|
|
57
|
-
Each symbol passed to trackable should reference either an instance method or an ActiveRecord field. Therefore it's perfectly legal to do something like:
|
58
|
-
|
59
74
|
# app/models/user.rb
|
60
75
|
class User < ActiveRecord::Base
|
61
|
-
include Vero::Trackable
|
62
|
-
trackable :email, :contest_count
|
76
|
+
include Vero::Trackable
|
77
|
+
trackable :id, :email, :contest_count
|
63
78
|
|
64
79
|
has_many :contests
|
65
80
|
|
@@ -68,22 +83,29 @@ Each symbol passed to trackable should reference either an instance method or an
|
|
68
83
|
end
|
69
84
|
end
|
70
85
|
|
71
|
-
There is one caveat
|
72
|
-
|
86
|
+
There is one caveat: you must pass an "id" to the API in order to perform
|
87
|
+
requests. In many cases the user "id" will simply be their email address. The
|
88
|
+
API will assume that if an "id" is not present that it should use "email" as
|
89
|
+
the "id".
|
90
|
+
|
91
|
+
If the user's email address is stored under a different field, you can do the
|
92
|
+
following:
|
93
|
+
|
73
94
|
# app/models/user.rb
|
74
95
|
class User < ActiveRecord::Base
|
75
|
-
include Vero::Trackable
|
76
|
-
trackable :email
|
96
|
+
include Vero::Trackable
|
97
|
+
trackable :id, :email
|
77
98
|
|
78
99
|
def email; self.primary_contact; end
|
79
100
|
end
|
80
101
|
|
81
|
-
Finally, you can track multiple properties stored in a Hash by doing the
|
102
|
+
Finally, you can track multiple properties stored in a Hash by doing the
|
103
|
+
following:
|
82
104
|
|
83
105
|
# app/models/user.rb
|
84
106
|
class User < ActiveRecord::Base
|
85
|
-
include Vero::Trackable
|
86
|
-
trackable :email, {:extras => :properties}
|
107
|
+
include Vero::Trackable
|
108
|
+
trackable :id, :email, {:extras => :properties}
|
87
109
|
|
88
110
|
def email; self.primary_contact; end
|
89
111
|
|
@@ -94,28 +116,29 @@ Finally, you can track multiple properties stored in a Hash by doing the followi
|
|
94
116
|
}
|
95
117
|
end
|
96
118
|
end
|
97
|
-
|
98
|
-
**Note:** You may choose to bypass extending the `User` model by calling the
|
119
|
+
|
120
|
+
**Note:** You may choose to bypass extending the `User` model by calling the
|
121
|
+
API via [simple DSL](https://github.com/getvero/vero#simple-dsl) found below.
|
99
122
|
|
100
123
|
## Sending events
|
101
124
|
|
102
125
|
Events can be sent by any model which has been previously marked as trackable.
|
103
126
|
|
104
127
|
To send an event:
|
105
|
-
|
128
|
+
|
106
129
|
# app/controllers/contests_controller.rb
|
107
130
|
class ContestsController < ActionController::Base
|
108
131
|
before_filter :authenticate_user!
|
109
132
|
...
|
110
133
|
|
111
|
-
|
134
|
+
|
112
135
|
def create
|
113
136
|
@contest = current_user.contests.build(params[:contest])
|
114
137
|
|
115
138
|
if @contest.save
|
116
139
|
# Tell Vero that a new contest has been created
|
117
|
-
current_user.track('new_contest_created')
|
118
|
-
|
140
|
+
current_user.track!('new_contest_created')
|
141
|
+
|
119
142
|
flash[:notice] = "New contest saved successfully!"
|
120
143
|
redirect_to contests_path
|
121
144
|
else
|
@@ -126,20 +149,20 @@ To send an event:
|
|
126
149
|
end
|
127
150
|
|
128
151
|
You may want to send additional data about an event:
|
129
|
-
|
152
|
+
|
130
153
|
# app/controllers/contests_controller.rb
|
131
154
|
class ContestsController < ActionController::Base
|
132
155
|
before_filter :authenticate_user!
|
133
156
|
...
|
134
157
|
|
135
|
-
|
158
|
+
|
136
159
|
def create
|
137
160
|
@contest = current_user.contests.build(params[:contest])
|
138
161
|
|
139
162
|
if @contest.save
|
140
163
|
# Tell Vero that a new contest has been created, and the id and name
|
141
|
-
current_user.track('new_contest_created', {:id => @contest.id, :name => @content.name})
|
142
|
-
|
164
|
+
current_user.track!('new_contest_created', {:id => @contest.id, :name => @content.name})
|
165
|
+
|
143
166
|
flash[:notice] = "New contest saved successfully!"
|
144
167
|
redirect_to contests_path
|
145
168
|
else
|
@@ -151,9 +174,11 @@ You may want to send additional data about an event:
|
|
151
174
|
|
152
175
|
## Simple DSL
|
153
176
|
|
154
|
-
To avoid having to extend the `User` model, we offer the option to call our API
|
177
|
+
To avoid having to extend the `User` model, we offer the option to call our API
|
178
|
+
using a simple DSL (thanks @jherdman) as you would from the Javascript library.
|
155
179
|
|
156
|
-
First, ensure you've correctly configured the gem following the instructions as
|
180
|
+
First, ensure you've correctly configured the gem following the instructions as
|
181
|
+
outlined in Installation. Now you can call the API using the following methods:
|
157
182
|
|
158
183
|
class UsersController < ApplicationController
|
159
184
|
include Vero::DSL
|
@@ -161,30 +186,30 @@ First, ensure you've correctly configured the gem following the instructions as
|
|
161
186
|
def perform_action
|
162
187
|
# Tracking an event
|
163
188
|
vero.events.track!({
|
164
|
-
:event_name => "test_event",
|
165
|
-
:data => {:date => "2013-02-12 16:17"},
|
166
|
-
:identity => {:email => "james@getvero.com"}
|
189
|
+
:event_name => "test_event",
|
190
|
+
:data => {:date => "2013-02-12 16:17"},
|
191
|
+
:identity => {:id => 123, :email => "james@getvero.com"}
|
167
192
|
})
|
168
193
|
end
|
169
194
|
|
170
195
|
def create
|
171
196
|
# Identifying a user
|
172
|
-
vero.users.track!({:
|
197
|
+
vero.users.track!({:id => 123, :data => {}})
|
173
198
|
end
|
174
199
|
|
175
200
|
def update
|
176
201
|
# Editing a user
|
177
|
-
vero.users.edit_user!({:
|
202
|
+
vero.users.edit_user!({:id => 123, :changes => {:age => 25}})
|
178
203
|
|
179
204
|
# Editing a user's tags
|
180
|
-
vero.users.edit_user_tags!({:
|
181
|
-
|
205
|
+
vero.users.edit_user_tags!({:id => 123, :add => ["awesome"], :remove => []})
|
206
|
+
|
182
207
|
# Changing a user's id
|
183
|
-
vero.users.reidentify!({:id =>
|
208
|
+
vero.users.reidentify!({:id => 123, :new_id => "honeybadger@getvero.com"})
|
184
209
|
end
|
185
210
|
|
186
211
|
def destroy
|
187
|
-
vero.users.unsubscribe!({:
|
212
|
+
vero.users.unsubscribe!({:id => 123})
|
188
213
|
end
|
189
214
|
end
|
190
215
|
|
@@ -194,8 +219,20 @@ This gem is distributed under the MIT License.
|
|
194
219
|
|
195
220
|
Copyright (C) 2013 Vero (Invc Me Inc.)
|
196
221
|
|
197
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
222
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
223
|
+
this software and associated documentation files (the "Software"), to deal in
|
224
|
+
the Software without restriction, including without limitation the rights to
|
225
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
226
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
227
|
+
so, subject to the following conditions:
|
228
|
+
|
229
|
+
The above copyright notice and this permission notice shall be included in all
|
230
|
+
copies or substantial portions of the Software.
|
231
|
+
|
232
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
233
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
234
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
235
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
236
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
237
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
238
|
+
SOFTWARE.
|
data/lib/vero/context/api.rb
CHANGED
@@ -6,27 +6,33 @@ module Vero
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def identify!
|
9
|
-
|
10
|
-
options = {:email =>
|
9
|
+
identity = subject.to_vero
|
10
|
+
options = {:id => identity[:id], :email => identity[:email], :data => identity}
|
11
11
|
Vero::Api::Users.track!(options, self)
|
12
12
|
end
|
13
13
|
|
14
|
-
def update_user!
|
15
|
-
|
16
|
-
options = {:
|
14
|
+
def update_user!
|
15
|
+
identity = subject.to_vero
|
16
|
+
options = {:id => identity[:id], :email => identity[:email], :changes => identity}
|
17
17
|
Vero::Api::Users.edit_user!(options, self)
|
18
18
|
end
|
19
19
|
|
20
20
|
def update_user_tags!(add = [], remove = [])
|
21
|
-
identity
|
22
|
-
options
|
21
|
+
identity = subject.to_vero
|
22
|
+
options = {:id => identity[:id], :email => identity[:email], :add => Array(add), :remove => Array(remove)}
|
23
23
|
Vero::Api::Users.edit_user_tags!(options, self)
|
24
24
|
end
|
25
25
|
|
26
26
|
def unsubscribe!
|
27
|
-
identity
|
28
|
-
options
|
27
|
+
identity = subject.to_vero
|
28
|
+
options = {:id => identity[:id], :email => identity[:email]}
|
29
29
|
Vero::Api::Users.unsubscribe!(options, self)
|
30
30
|
end
|
31
|
+
|
32
|
+
def reidentify!(previous_id)
|
33
|
+
identity = subject.to_vero
|
34
|
+
options = {:id => previous_id, :new_id => identity[:id]}
|
35
|
+
Vero::Api::Users.reidentify!(options, self)
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
data/lib/vero/dsl.rb
CHANGED
data/lib/vero/trackable/base.rb
CHANGED
@@ -38,7 +38,7 @@ module Vero
|
|
38
38
|
other.reject! { |i| !(i.is_a?(Hash) && i.has_key?(:extras)) }
|
39
39
|
other.each do |h|
|
40
40
|
symbol = h[:extras]
|
41
|
-
t = respond_to?(symbol) ? send(symbol) : nil
|
41
|
+
t = respond_to?(symbol, true) ? send(symbol) : nil
|
42
42
|
result.merge!(t) if t.is_a?(Hash)
|
43
43
|
end
|
44
44
|
end
|
@@ -59,4 +59,4 @@ module Vero
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
data/lib/vero/version.rb
CHANGED
@@ -19,31 +19,31 @@ describe Vero::Api::Workers::Events::TrackAPI do
|
|
19
19
|
it "should raise an error if event_name is a blank String" do
|
20
20
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => nil}
|
21
21
|
subject.options = options
|
22
|
-
expect { subject.send(:validate!) }.to raise_error
|
22
|
+
expect { subject.send(:validate!) }.to raise_error
|
23
23
|
|
24
24
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}
|
25
25
|
subject.options = options
|
26
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
26
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should raise an error if data is not either nil or a Hash" do
|
30
30
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => []}
|
31
31
|
subject.options = options
|
32
|
-
expect { subject.send(:validate!) }.to raise_error
|
32
|
+
expect { subject.send(:validate!) }.to raise_error
|
33
33
|
|
34
34
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => nil}
|
35
35
|
subject.options = options
|
36
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
36
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
37
37
|
|
38
38
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => {}}
|
39
39
|
subject.options = options
|
40
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
40
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should not raise an error when the keys are Strings" do
|
44
44
|
options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "event_name" => 'test_event', "data" => {}}
|
45
45
|
subject.options = options
|
46
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
46
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -15,7 +15,7 @@ describe Vero::Api::Workers::Users::EditAPI do
|
|
15
15
|
it "should not raise an error when the keys are Strings" do
|
16
16
|
options = {"auth_token" => 'abcd', "email" => 'test@test.com', "changes" => { "email" => 'test@test.com' }}
|
17
17
|
subject.options = options
|
18
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
18
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -16,45 +16,45 @@ describe Vero::Api::Workers::Users::EditTagsAPI do
|
|
16
16
|
it "should raise an error if email is a blank String" do
|
17
17
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => nil, :add => []}
|
18
18
|
subject.options = options
|
19
|
-
expect { subject.send(:validate!) }.to raise_error
|
19
|
+
expect { subject.send(:validate!) }.to raise_error
|
20
20
|
|
21
21
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :add => []}
|
22
22
|
subject.options = options
|
23
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
23
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should raise an error if add is not an Array or missing" do
|
27
27
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :add => "foo" }
|
28
28
|
|
29
29
|
subject.options = options
|
30
|
-
expect { subject.send(:validate!) }.to raise_error
|
30
|
+
expect { subject.send(:validate!) }.to raise_error
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should raise an error if remove is not an Array or missing" do
|
34
34
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :remove => "foo" }
|
35
35
|
|
36
36
|
subject.options = options
|
37
|
-
expect { subject.send(:validate!) }.to raise_error
|
37
|
+
expect { subject.send(:validate!) }.to raise_error
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should raise an error if botha add and remove are missing" do
|
41
41
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}
|
42
42
|
|
43
43
|
subject.options = options
|
44
|
-
expect { subject.send(:validate!) }.to raise_error
|
44
|
+
expect { subject.send(:validate!) }.to raise_error
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not raise an error if the correct arguments are passed" do
|
48
48
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :remove => [ "Hi" ] }
|
49
49
|
|
50
50
|
subject.options = options
|
51
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
51
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not raise an error when the keys are Strings" do
|
55
55
|
options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "email" => 'test@test.com', "remove" => [ "Hi" ] }
|
56
56
|
subject.options = options
|
57
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
57
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -15,7 +15,7 @@ describe Vero::Api::Workers::Users::ReidentifyAPI do
|
|
15
15
|
it "should not raise an error when the keys are Strings" do
|
16
16
|
options = {"auth_token" => 'abcd', "id" => 'test@test.com', "new_id" => 'test2@test.com'}
|
17
17
|
subject.options = options
|
18
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
18
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should raise an error if id is missing" do
|
@@ -15,39 +15,39 @@ describe Vero::Api::Workers::Users::TrackAPI do
|
|
15
15
|
it "should raise an error if email and id are are blank String" do
|
16
16
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => nil, :email => nil}
|
17
17
|
subject.options = options
|
18
|
-
expect { subject.send(:validate!) }.to raise_error
|
18
|
+
expect { subject.send(:validate!) }.to raise_error
|
19
19
|
|
20
20
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => nil, :email => 'test@test.com'}
|
21
21
|
subject.options = options
|
22
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
22
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
23
23
|
|
24
24
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => "", :email => nil}
|
25
25
|
subject.options = options
|
26
|
-
expect { subject.send(:validate!) }.to raise_error
|
26
|
+
expect { subject.send(:validate!) }.to raise_error
|
27
27
|
|
28
28
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :id => "user123", :email => nil}
|
29
29
|
subject.options = options
|
30
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
30
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should raise an error if data is not either nil or a Hash" do
|
34
34
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :data => []}
|
35
35
|
subject.options = options
|
36
|
-
expect { subject.send(:validate!) }.to raise_error
|
36
|
+
expect { subject.send(:validate!) }.to raise_error
|
37
37
|
|
38
38
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :data => nil}
|
39
39
|
subject.options = options
|
40
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
40
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
41
41
|
|
42
42
|
options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :data => {}}
|
43
43
|
subject.options = options
|
44
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
44
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should not raise an error when the keys are Strings" do
|
48
48
|
options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "email" => 'test@test.com', "data" => {}}
|
49
49
|
subject.options = options
|
50
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
50
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -15,7 +15,7 @@ describe Vero::Api::Workers::Users::UnsubscribeAPI do
|
|
15
15
|
it "should not raise an error when the keys are Strings" do
|
16
16
|
options = {"auth_token" => 'abcd', "email" => 'test@test.com', "changes" => { "email" => 'test@test.com' }}
|
17
17
|
subject.options = options
|
18
|
-
expect { subject.send(:validate!) }.to_not raise_error
|
18
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/spec/lib/trackable_spec.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
def vero_context(user, logging = true, async = false)
|
4
|
+
context = Vero::Context.new(Vero::App.default_context)
|
5
|
+
context.subject = user
|
6
|
+
context.config.logging = logging
|
7
|
+
context.config.async = async
|
8
|
+
|
9
|
+
context
|
10
|
+
end
|
11
|
+
|
3
12
|
describe Vero::Trackable do
|
4
13
|
before :each do
|
5
14
|
@request_params = {
|
@@ -16,26 +25,17 @@ describe Vero::Trackable do
|
|
16
25
|
end
|
17
26
|
|
18
27
|
context "the gem has not been configured" do
|
19
|
-
before
|
20
|
-
|
21
|
-
|
28
|
+
before { Vero::App.reset! }
|
29
|
+
it "should raise an error when API requests are made" do
|
30
|
+
expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error
|
22
31
|
|
23
|
-
|
24
|
-
|
25
|
-
expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error(RuntimeError, "You must configure the 'vero' gem. Visit https://github.com/semblancesystems/vero for more details.")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe :identity! do
|
30
|
-
it "should raise an error" do
|
31
|
-
@user.stub(:post_later).and_return('success')
|
32
|
-
expect { @user.identity! }.to raise_error
|
33
|
-
end
|
32
|
+
@user.stub(:post_later).and_return('success')
|
33
|
+
expect { @user.identity! }.to raise_error
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
context "the gem has been configured" do
|
38
|
-
before
|
38
|
+
before do
|
39
39
|
Vero::App.init do |c|
|
40
40
|
c.api_key = 'abcd1234'
|
41
41
|
c.secret = 'efgh5678'
|
@@ -55,48 +55,31 @@ describe Vero::Trackable do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should not send a track request when the required parameters are invalid" do
|
58
|
-
expect { @user.track!(nil) }.to raise_error
|
59
|
-
expect { @user.track!('') }.to raise_error
|
60
|
-
expect { @user.track!('test', '') }.to raise_error
|
58
|
+
expect { @user.track!(nil) }.to raise_error
|
59
|
+
expect { @user.track!('') }.to raise_error
|
60
|
+
expect { @user.track!('test', '') }.to raise_error
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should send a `track!` request when async is set to false" do
|
64
|
-
context =
|
65
|
-
context.subject = @user
|
66
|
-
context.config.logging = true
|
67
|
-
|
64
|
+
context = vero_context(@user)
|
68
65
|
@user.stub(:with_vero_context).and_return(context)
|
69
66
|
|
70
67
|
RestClient.stub(:post).and_return(200)
|
71
68
|
|
72
|
-
# RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/events/track.json", {:data=>{:test=>1}, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20, :_user_type=>"User"}, :auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true}.to_json, @content_type_params)
|
73
|
-
|
74
69
|
Vero::Api::Events.stub(:track!).and_return(200)
|
75
70
|
Vero::Api::Events.should_receive(:track!).with(@request_params, context)
|
76
71
|
@user.track!(@request_params[:event_name], @request_params[:data]).should == 200
|
77
72
|
|
78
|
-
# RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/events/track.json", {:data=>{}, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20, :_user_type=>"User"}, :auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true}.to_json, @content_type_params)
|
79
|
-
|
80
73
|
Vero::Api::Events.stub(:track!).and_return(200)
|
81
74
|
Vero::Api::Events.should_receive(:track!).with(@request_params.merge(:data => {}), context)
|
82
75
|
@user.track!(@request_params[:event_name]).should == 200
|
83
76
|
end
|
84
77
|
|
85
78
|
context 'when set to be async' do
|
86
|
-
|
87
|
-
|
88
|
-
before do
|
89
|
-
my_context.config.logging = true
|
90
|
-
my_context.subject = @user
|
91
|
-
my_context.config.async = true
|
92
|
-
|
93
|
-
@user.stub(:with_vero_context).and_return(my_context)
|
94
|
-
end
|
79
|
+
before { @user.stub(:with_vero_context).and_return vero_context(@user, true, true) }
|
95
80
|
|
96
81
|
context 'using Ruby 1.8.7' do
|
97
|
-
before
|
98
|
-
stub_const('RUBY_VERSION', '1.8.7')
|
99
|
-
end
|
82
|
+
before { stub_const('RUBY_VERSION', '1.8.7') }
|
100
83
|
|
101
84
|
it 'raises an error' do
|
102
85
|
expect { @user.track!(@request_params[:event_name], @request_params[:data]) }.to raise_error
|
@@ -105,9 +88,7 @@ describe Vero::Trackable do
|
|
105
88
|
end
|
106
89
|
|
107
90
|
context 'not using Ruby 1.8.7' do
|
108
|
-
before
|
109
|
-
stub_const('RUBY_VERSION', '1.9.3')
|
110
|
-
end
|
91
|
+
before { stub_const('RUBY_VERSION', '1.9.3') }
|
111
92
|
|
112
93
|
it 'sends' do
|
113
94
|
@user.track!(@request_params[:event_name], @request_params[:data]).should be_true
|
@@ -120,6 +101,7 @@ describe Vero::Trackable do
|
|
120
101
|
describe :identify! do
|
121
102
|
before do
|
122
103
|
@request_params = {
|
104
|
+
:id => nil,
|
123
105
|
:email => 'durkster@gmail.com',
|
124
106
|
:data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
|
125
107
|
}
|
@@ -127,14 +109,9 @@ describe Vero::Trackable do
|
|
127
109
|
end
|
128
110
|
|
129
111
|
it "should send an `identify` request when async is set to false" do
|
130
|
-
context =
|
131
|
-
context.subject = @user
|
132
|
-
|
112
|
+
context = vero_context(@user)
|
133
113
|
@user.stub(:with_vero_context).and_return(context)
|
134
114
|
|
135
|
-
# RestClient.stub(:post).and_return(200)
|
136
|
-
# RestClient.should_receive(:post).with(@url, @request_params.to_json, @content_type_params)
|
137
|
-
|
138
115
|
Vero::Api::Users.stub(:track!).and_return(200)
|
139
116
|
Vero::Api::Users.should_receive(:track!).with(@request_params, context)
|
140
117
|
|
@@ -142,17 +119,13 @@ describe Vero::Trackable do
|
|
142
119
|
end
|
143
120
|
|
144
121
|
context 'when set to use async' do
|
145
|
-
let(:my_context) { Vero::Context.new(Vero::App.default_context) }
|
146
|
-
|
147
122
|
before do
|
148
|
-
|
149
|
-
|
123
|
+
context = vero_context(@user, false, true)
|
124
|
+
@user.stub(:with_vero_context).and_return(context)
|
150
125
|
end
|
151
126
|
|
152
127
|
context 'and using Ruby 1.8.7' do
|
153
|
-
before
|
154
|
-
stub_const('RUBY_VERSION', '1.8.7')
|
155
|
-
end
|
128
|
+
before { stub_const('RUBY_VERSION', '1.8.7') }
|
156
129
|
|
157
130
|
it 'raises an error' do
|
158
131
|
expect { @user.identify! }.to raise_error
|
@@ -160,9 +133,7 @@ describe Vero::Trackable do
|
|
160
133
|
end
|
161
134
|
|
162
135
|
context 'and not using Ruby 1.8.7' do
|
163
|
-
before
|
164
|
-
stub_const('RUBY_VERSION', '1.9.3')
|
165
|
-
end
|
136
|
+
before { stub_const('RUBY_VERSION', '1.9.3') }
|
166
137
|
|
167
138
|
it 'sends' do
|
168
139
|
@user.identify!.should be_true
|
@@ -174,36 +145,19 @@ describe Vero::Trackable do
|
|
174
145
|
describe :update_user! do
|
175
146
|
before do
|
176
147
|
@request_params = {
|
148
|
+
:id => nil,
|
177
149
|
:email => 'durkster@gmail.com',
|
178
150
|
:changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
|
179
151
|
}
|
180
152
|
@url = "https://api.getvero.com/api/v2/users/edit.json"
|
181
153
|
end
|
182
154
|
|
183
|
-
it "should be able to choose an email address" do
|
184
|
-
context = Vero::Context.new(Vero::App.default_context)
|
185
|
-
context.subject = @user
|
186
|
-
|
187
|
-
@user.stub(:with_vero_context).and_return(context)
|
188
|
-
|
189
|
-
# RestClient.stub(:put).and_return(200)
|
190
|
-
# RestClient.should_receive(:put).with(@url, @request_params.merge(:email => "durkster1@gmail.com").to_json, @content_type_params)
|
191
|
-
|
192
|
-
Vero::Api::Users.stub(:edit_user!).and_return(200)
|
193
|
-
Vero::Api::Users.should_receive(:edit_user!).with(@request_params.merge(:email => "durkster1@gmail.com"), context)
|
194
|
-
|
195
|
-
@user.with_vero_context.update_user!("durkster1@gmail.com").should == 200
|
196
|
-
end
|
197
|
-
|
198
155
|
it "should send an `update_user` request when async is set to false" do
|
199
156
|
context = Vero::Context.new(Vero::App.default_context)
|
200
157
|
context.subject = @user
|
201
158
|
|
202
159
|
@user.stub(:with_vero_context).and_return(context)
|
203
160
|
|
204
|
-
# RestClient.stub(:put).and_return(200)
|
205
|
-
# RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
|
206
|
-
|
207
161
|
Vero::Api::Users.stub(:edit_user!).and_return(200)
|
208
162
|
Vero::Api::Users.should_receive(:edit_user!).with(@request_params, context)
|
209
163
|
|
@@ -221,9 +175,7 @@ describe Vero::Trackable do
|
|
221
175
|
end
|
222
176
|
|
223
177
|
context 'and using Ruby 1.8.7' do
|
224
|
-
before
|
225
|
-
stub_const('RUBY_VERSION', '1.8.7')
|
226
|
-
end
|
178
|
+
before { stub_const('RUBY_VERSION', '1.8.7') }
|
227
179
|
|
228
180
|
it 'raises an error' do
|
229
181
|
expect { @user.with_vero_context.update_user! }.to raise_error
|
@@ -231,9 +183,7 @@ describe Vero::Trackable do
|
|
231
183
|
end
|
232
184
|
|
233
185
|
context 'and not using Ruby 1.8.7' do
|
234
|
-
before
|
235
|
-
stub_const('RUBY_VERSION', '1.9.3')
|
236
|
-
end
|
186
|
+
before { stub_const('RUBY_VERSION', '1.9.3') }
|
237
187
|
|
238
188
|
it 'sends' do
|
239
189
|
@user.with_vero_context.update_user!.should be_true
|
@@ -245,6 +195,7 @@ describe Vero::Trackable do
|
|
245
195
|
describe :update_user_tags! do
|
246
196
|
before do
|
247
197
|
@request_params = {
|
198
|
+
:id => nil,
|
248
199
|
:email => 'durkster@gmail.com',
|
249
200
|
:add => [],
|
250
201
|
:remove => []
|
@@ -259,9 +210,6 @@ describe Vero::Trackable do
|
|
259
210
|
|
260
211
|
@user.stub(:with_vero_context).and_return(context)
|
261
212
|
|
262
|
-
# RestClient.stub(:put).and_return(200)
|
263
|
-
# RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
|
264
|
-
|
265
213
|
Vero::Api::Users.stub(:edit_user_tags!).and_return(200)
|
266
214
|
Vero::Api::Users.should_receive(:edit_user_tags!).with(@request_params, context)
|
267
215
|
|
@@ -284,6 +232,7 @@ describe Vero::Trackable do
|
|
284
232
|
describe :unsubscribe! do
|
285
233
|
before do
|
286
234
|
@request_params = {
|
235
|
+
:id => nil,
|
287
236
|
:email => 'durkster@gmail.com'
|
288
237
|
}
|
289
238
|
@url = "https://api.getvero.com/api/v2/users/unsubscribe.json"
|
@@ -296,9 +245,6 @@ describe Vero::Trackable do
|
|
296
245
|
|
297
246
|
@user.stub(:with_vero_context).and_return(context)
|
298
247
|
|
299
|
-
# RestClient.stub(:post).and_return(200)
|
300
|
-
# RestClient.should_receive(:post).with(@url, @request_params)
|
301
|
-
|
302
248
|
Vero::Api::Users.stub(:unsubscribe!).and_return(200)
|
303
249
|
Vero::Api::Users.should_receive(:unsubscribe!).with(@request_params, context)
|
304
250
|
|
@@ -316,9 +262,7 @@ describe Vero::Trackable do
|
|
316
262
|
end
|
317
263
|
|
318
264
|
context 'and using Ruby 1.8.7' do
|
319
|
-
before
|
320
|
-
stub_const('RUBY_VERSION', '1.8.7')
|
321
|
-
end
|
265
|
+
before { stub_const('RUBY_VERSION', '1.8.7') }
|
322
266
|
|
323
267
|
it 'raises an error' do
|
324
268
|
expect { @user.with_vero_context.unsubscribe! }.to raise_error
|
@@ -326,9 +270,7 @@ describe Vero::Trackable do
|
|
326
270
|
end
|
327
271
|
|
328
272
|
context 'and using Ruby 1.9.3' do
|
329
|
-
before
|
330
|
-
stub_const('RUBY_VERSION', '1.9.3')
|
331
|
-
end
|
273
|
+
before { stub_const('RUBY_VERSION', '1.9.3') }
|
332
274
|
|
333
275
|
it 'sends' do
|
334
276
|
@user.with_vero_context.unsubscribe!.should be_true
|
@@ -338,32 +280,31 @@ describe Vero::Trackable do
|
|
338
280
|
end
|
339
281
|
|
340
282
|
describe :trackable do
|
341
|
-
|
342
|
-
User.reset_trackable_map!
|
343
|
-
User.trackable :email, :age
|
344
|
-
end
|
283
|
+
before { User.reset_trackable_map! }
|
345
284
|
|
346
285
|
it "should build an array of trackable params" do
|
347
|
-
User.reset_trackable_map!
|
348
286
|
User.trackable :email, :age
|
349
287
|
User.trackable_map.should == [:email, :age]
|
350
288
|
end
|
351
289
|
|
352
290
|
it "should append new trackable items to an existing trackable map" do
|
353
|
-
User.reset_trackable_map!
|
354
291
|
User.trackable :email, :age
|
355
292
|
User.trackable :hair_colour
|
356
293
|
User.trackable_map.should == [:email, :age, :hair_colour]
|
357
294
|
end
|
358
295
|
|
359
296
|
it "should append an extra's hash to the trackable map" do
|
360
|
-
User.reset_trackable_map!
|
361
297
|
User.trackable :email, {:extras => :properties}
|
362
298
|
User.trackable_map.should == [:email, {:extras => :properties}]
|
363
299
|
end
|
364
300
|
end
|
365
301
|
|
366
302
|
describe :to_vero do
|
303
|
+
before :all do
|
304
|
+
User.reset_trackable_map!
|
305
|
+
User.trackable :email, :age
|
306
|
+
end
|
307
|
+
|
367
308
|
it "should return a hash of all values mapped by trackable" do
|
368
309
|
user = User.new
|
369
310
|
user.to_vero.should == {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
|
@@ -397,6 +338,9 @@ describe Vero::Trackable do
|
|
397
338
|
:gender => "female"
|
398
339
|
}
|
399
340
|
user.to_vero.should == {:email => 'durkster@gmail.com', :age => 20, :gender => "female", :_user_type => "UserWithExtras"}
|
341
|
+
|
342
|
+
user = UserWithPrivateExtras.new
|
343
|
+
user.to_vero.should == {:email => 'durkster@gmail.com', :age => 26, :_user_type => "UserWithPrivateExtras"}
|
400
344
|
end
|
401
345
|
end
|
402
346
|
|
@@ -77,4 +77,18 @@ class UserWithExtras
|
|
77
77
|
def email
|
78
78
|
'durkster@gmail.com'
|
79
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class UserWithPrivateExtras
|
83
|
+
include Vero::Trackable
|
84
|
+
trackable :email, {:extras => :properties}
|
85
|
+
|
86
|
+
def email
|
87
|
+
'durkster@gmail.com'
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def properties
|
92
|
+
{:age => 26}
|
93
|
+
end
|
80
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -145,6 +145,7 @@ executables: []
|
|
145
145
|
extensions: []
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
148
|
+
- CHANGES.md
|
148
149
|
- Gemfile
|
149
150
|
- Gemfile.lock
|
150
151
|
- lib/generators/vero_generator.rb
|