vero 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vero (0.5.1)
4
+ vero (0.5.2)
5
5
  girl_friday
6
6
  json
7
7
  rest-client
@@ -9,119 +9,122 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- actionmailer (3.2.8)
13
- actionpack (= 3.2.8)
14
- mail (~> 2.4.4)
15
- actionpack (3.2.8)
16
- activemodel (= 3.2.8)
17
- activesupport (= 3.2.8)
12
+ actionmailer (3.2.13)
13
+ actionpack (= 3.2.13)
14
+ mail (~> 2.5.3)
15
+ actionpack (3.2.13)
16
+ activemodel (= 3.2.13)
17
+ activesupport (= 3.2.13)
18
18
  builder (~> 3.0.0)
19
19
  erubis (~> 2.7.0)
20
20
  journey (~> 1.0.4)
21
- rack (~> 1.4.0)
21
+ rack (~> 1.4.5)
22
22
  rack-cache (~> 1.2)
23
23
  rack-test (~> 0.6.1)
24
- sprockets (~> 2.1.3)
25
- activemodel (3.2.8)
26
- activesupport (= 3.2.8)
24
+ sprockets (~> 2.2.1)
25
+ activemodel (3.2.13)
26
+ activesupport (= 3.2.13)
27
27
  builder (~> 3.0.0)
28
- activerecord (3.2.8)
29
- activemodel (= 3.2.8)
30
- activesupport (= 3.2.8)
28
+ activerecord (3.2.13)
29
+ activemodel (= 3.2.13)
30
+ activesupport (= 3.2.13)
31
31
  arel (~> 3.0.2)
32
32
  tzinfo (~> 0.3.29)
33
- activeresource (3.2.8)
34
- activemodel (= 3.2.8)
35
- activesupport (= 3.2.8)
36
- activesupport (3.2.8)
37
- i18n (~> 0.6)
33
+ activeresource (3.2.13)
34
+ activemodel (= 3.2.13)
35
+ activesupport (= 3.2.13)
36
+ activesupport (3.2.13)
37
+ i18n (= 0.6.1)
38
38
  multi_json (~> 1.0)
39
39
  arel (3.0.2)
40
- builder (3.0.3)
41
- connection_pool (0.9.3)
42
- delayed_job (3.0.4)
40
+ builder (3.0.4)
41
+ connection_pool (1.0.0)
42
+ delayed_job (3.0.5)
43
43
  activesupport (~> 3.0)
44
- delayed_job_active_record (0.3.3)
44
+ delayed_job_active_record (0.4.3)
45
45
  activerecord (>= 2.1.0, < 4)
46
46
  delayed_job (~> 3.0)
47
- diff-lcs (1.1.3)
47
+ diff-lcs (1.2.1)
48
48
  erubis (2.7.0)
49
- girl_friday (0.11.1)
50
- connection_pool (~> 0.9.0)
49
+ girl_friday (0.11.2)
50
+ connection_pool (~> 1.0)
51
51
  rubinius-actor
52
52
  hike (1.2.1)
53
53
  i18n (0.6.1)
54
54
  journey (1.0.4)
55
- json (1.7.6)
56
- mail (2.4.4)
55
+ json (1.7.7)
56
+ mail (2.5.3)
57
57
  i18n (>= 0.4.0)
58
58
  mime-types (~> 1.16)
59
59
  treetop (~> 1.4.8)
60
- mime-types (1.19)
61
- multi_json (1.3.6)
60
+ mime-types (1.21)
61
+ mono_logger (1.0.0)
62
+ multi_json (1.7.2)
62
63
  polyglot (0.3.3)
63
- rack (1.4.3)
64
+ rack (1.4.5)
64
65
  rack-cache (1.2)
65
66
  rack (>= 0.4)
66
- rack-protection (1.3.2)
67
+ rack-protection (1.5.0)
67
68
  rack
68
- rack-ssl (1.3.2)
69
+ rack-ssl (1.3.3)
69
70
  rack
70
71
  rack-test (0.6.2)
71
72
  rack (>= 1.0)
72
- rails (3.2.8)
73
- actionmailer (= 3.2.8)
74
- actionpack (= 3.2.8)
75
- activerecord (= 3.2.8)
76
- activeresource (= 3.2.8)
77
- activesupport (= 3.2.8)
73
+ rails (3.2.13)
74
+ actionmailer (= 3.2.13)
75
+ actionpack (= 3.2.13)
76
+ activerecord (= 3.2.13)
77
+ activeresource (= 3.2.13)
78
+ activesupport (= 3.2.13)
78
79
  bundler (~> 1.0)
79
- railties (= 3.2.8)
80
- railties (3.2.8)
81
- actionpack (= 3.2.8)
82
- activesupport (= 3.2.8)
80
+ railties (= 3.2.13)
81
+ railties (3.2.13)
82
+ actionpack (= 3.2.13)
83
+ activesupport (= 3.2.13)
83
84
  rack-ssl (~> 1.3.2)
84
85
  rake (>= 0.8.7)
85
86
  rdoc (~> 3.4)
86
87
  thor (>= 0.14.6, < 2.0)
87
88
  rake (10.0.3)
88
- rdoc (3.12)
89
+ rdoc (3.12.2)
89
90
  json (~> 1.4)
90
- redis (3.0.2)
91
+ redis (3.0.3)
91
92
  redis-namespace (1.2.1)
92
93
  redis (~> 3.0.0)
93
- resque (1.23.0)
94
+ resque (1.24.0)
95
+ mono_logger (~> 1.0)
94
96
  multi_json (~> 1.0)
95
- redis-namespace (~> 1.0)
97
+ redis-namespace (~> 1.2)
96
98
  sinatra (>= 0.9.2)
97
99
  vegas (~> 0.1.2)
98
100
  rest-client (1.6.7)
99
101
  mime-types (>= 1.16)
100
- rspec (2.11.0)
101
- rspec-core (~> 2.11.0)
102
- rspec-expectations (~> 2.11.0)
103
- rspec-mocks (~> 2.11.0)
104
- rspec-core (2.11.1)
105
- rspec-expectations (2.11.3)
106
- diff-lcs (~> 1.1.3)
107
- rspec-mocks (2.11.3)
102
+ rspec (2.13.0)
103
+ rspec-core (~> 2.13.0)
104
+ rspec-expectations (~> 2.13.0)
105
+ rspec-mocks (~> 2.13.0)
106
+ rspec-core (2.13.1)
107
+ rspec-expectations (2.13.0)
108
+ diff-lcs (>= 1.1.3, < 2.0)
109
+ rspec-mocks (2.13.0)
108
110
  rubinius-actor (0.0.2)
109
111
  rubinius-core-api
110
112
  rubinius-core-api (0.0.1)
111
- sinatra (1.3.4)
113
+ sinatra (1.3.6)
112
114
  rack (~> 1.4)
113
115
  rack-protection (~> 1.3)
114
116
  tilt (~> 1.3, >= 1.3.3)
115
- sprockets (2.1.3)
117
+ sprockets (2.2.2)
116
118
  hike (~> 1.2)
119
+ multi_json (~> 1.0)
117
120
  rack (~> 1.0)
118
121
  tilt (~> 1.1, != 1.3.0)
119
- thor (0.16.0)
120
- tilt (1.3.3)
122
+ thor (0.17.0)
123
+ tilt (1.3.6)
121
124
  treetop (1.4.12)
122
125
  polyglot
123
126
  polyglot (>= 0.3.1)
124
- tzinfo (0.3.33)
127
+ tzinfo (0.3.37)
125
128
  vegas (0.1.11)
126
129
  rack (>= 1.0.0)
127
130
 
@@ -131,7 +134,7 @@ PLATFORMS
131
134
  DEPENDENCIES
132
135
  delayed_job
133
136
  delayed_job_active_record
134
- rails
137
+ rails (> 3)
135
138
  resque
136
139
  rspec
137
140
  vero!
data/README.markdown CHANGED
@@ -148,23 +148,38 @@ You may want to send additional data about an event:
148
148
  end
149
149
  end
150
150
 
151
- ## Calling the API directly
151
+ ## Simple DSL
152
152
 
153
- To avoid having to extend the `User` model, we offer the option to call our API directly, as you would from the Javascript library.
153
+ To avoid having to extend the `User` model, we offer the option to call our API using a simple DSL (thanks @jherdman) as you would from the Javascript library.
154
154
 
155
155
  First, ensure you've correctly configured the gem following the instructions as outlined in Installation. Now you can call the API using the following methods:
156
156
 
157
- # Tracking an event
158
- Vero::Api::Events.track!({:event_name => "test_event", :data => {:date => "2013-02-12 16:17"}, :identity => {:email => "james@getvero.com"}})
159
-
160
- # Identifying a user
161
- Vero::Api::Users.track!({:email => "james@getvero.com"})
162
-
163
- # Editing a user
164
- Vero::Api::Users.edit_user!({:email => "james@getvero.com", :changes => {:age => 25}})
165
-
166
- # Editing a user tags
167
- Vero::Api::Users.edit_user_tags!({:email => "james@getvero.com", :add => [], :remove => ["awesome"]})
168
-
169
- # Unsubscribe a user
170
- Vero::Api::Users.unsubscribe!({:email => "james@getvero.com"})
157
+ class UsersController < ApplicationController
158
+ include Vero::DSL
159
+
160
+ def perform_action
161
+ # Tracking an event
162
+ vero.events.track!({
163
+ :event_name => "test_event",
164
+ :data => {:date => "2013-02-12 16:17"},
165
+ :identity => {:email => "james@getvero.com"}
166
+ })
167
+ end
168
+
169
+ def create
170
+ # Identifying a user
171
+ vero.users.track!({:email => "james@getvero.com", :data => {}})
172
+ end
173
+
174
+ def update
175
+ # Editing a user
176
+ vero.users.edit_user!({:email => "james@getvero.com", :changes => {:age => 25}})
177
+
178
+ # Editing a user's tags
179
+ vero.users.edit_user_tags!({:email => "james@getvero.com", :add => [], :remove => ["awesome"]})
180
+ end
181
+
182
+ def destroy
183
+ vero.users.unsubscribe!({:email => "james@getvero.com"})
184
+ end
185
+ end
data/lib/vero.rb CHANGED
@@ -6,6 +6,7 @@ module Vero
6
6
  autoload :App, 'vero/app'
7
7
  autoload :Context, 'vero/context'
8
8
  autoload :Trackable, 'vero/trackable'
9
+ autoload :DSL, 'vero/dsl'
9
10
 
10
11
  module Api
11
12
  module Workers
@@ -42,4 +43,4 @@ module Vero
42
43
  autoload :ResqueWorker, 'vero/senders/resque'
43
44
  end
44
45
 
45
- require 'vero/railtie' if defined?(Rails)
46
+ require 'vero/railtie' if defined?(Rails)
@@ -6,23 +6,17 @@ module Vero
6
6
  def url
7
7
  "#{@domain}/api/v2/events/track.json"
8
8
  end
9
-
9
+
10
10
  def request
11
11
  RestClient.post(self.url, self.request_params_as_json, self.request_content_type)
12
12
  end
13
13
 
14
14
  def validate!
15
- result = true
16
- result &&= options[:event_name].to_s.blank? == false
17
- result &&= (options[:data].nil? || options[:data].is_a?(Hash))
18
-
19
- unless result
20
- hash = {:data => options[:data], :event_name => options[:event_name]}
21
- raise ArgumentError.new(JSON.dump(hash))
22
- end
15
+ raise ArgumentError.new("Missing :event_name") if options[:event_name].to_s.blank?
16
+ raise ArgumentError.new(":data must be either nil or a Hash") unless (options[:data].nil? || options[:data].is_a?(Hash))
23
17
  end
24
18
  end
25
19
  end
26
20
  end
27
21
  end
28
- end
22
+ end
@@ -12,16 +12,11 @@ module Vero
12
12
  end
13
13
 
14
14
  def validate!
15
- result = true
16
- result &&= options[:email].to_s.blank? == false
17
- result &&= options[:changes].is_a?(Hash)
18
-
19
- unless result
20
- raise ArgumentError.new(:email => options[:email], :changes => options[:changes])
21
- end
15
+ raise ArgumentError.new("Missing :email") if options[:email].to_s.blank?
16
+ raise ArgumentError.new(":changes must be a Hash") unless options[:changes].is_a?(Hash)
22
17
  end
23
18
  end
24
19
  end
25
20
  end
26
21
  end
27
- end
22
+ end
@@ -12,16 +12,13 @@ module Vero
12
12
  end
13
13
 
14
14
  def validate!
15
- result = true
16
- result &&= options[:email].to_s.blank? == false
17
- result &&= (options[:add].is_a?(Array) || options[:remove].is_a?(Array))
18
-
19
- unless result
20
- raise ArgumentError.new(:email => options[:email], :add => options[:add], :remove => options[:remove])
21
- end
15
+ raise ArgumentError.new("Missing :email") if options[:email].to_s.blank?
16
+ raise ArgumentError.new(":add must an Array if present") unless options[:add].nil? || options[:add].is_a?(Array)
17
+ raise ArgumentError.new(":remove must an Array if present") unless options[:remove].nil? || options[:remove].is_a?(Array)
18
+ raise ArgumentError.new("Either :add or :remove must be present") if (options[:remove].nil? && options[:add].nil?)
22
19
  end
23
20
  end
24
21
  end
25
22
  end
26
23
  end
27
- end
24
+ end
@@ -12,16 +12,11 @@ module Vero
12
12
  end
13
13
 
14
14
  def validate!
15
- result = true
16
- result &&= options[:email].to_s.blank? == false
17
- result &&= (options[:data].nil? || options[:data].is_a?(Hash))
18
-
19
- unless result
20
- raise ArgumentError.new(:email => options[:email], :data => options[:data])
21
- end
15
+ raise ArgumentError.new("Missing :email") if options[:email].to_s.blank?
16
+ raise ArgumentError.new(":data must be either nil or a Hash") unless (options[:data].nil? || options[:data].is_a?(Hash))
22
17
  end
23
18
  end
24
19
  end
25
20
  end
26
21
  end
27
- end
22
+ end
@@ -12,15 +12,10 @@ module Vero
12
12
  end
13
13
 
14
14
  def validate!
15
- result = true
16
- result &&= options[:email].to_s.blank? == false
17
-
18
- unless result
19
- raise ArgumentError.new(:email => options[:email])
20
- end
15
+ raise ArgumentError.new("Missing :email") if options[:email].to_s.blank?
21
16
  end
22
17
  end
23
18
  end
24
19
  end
25
20
  end
26
- end
21
+ end
data/lib/vero/dsl.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Vero
2
+ ##
3
+ # A lightweight DSL for using the Vero API. You may find this desirable in
4
+ # your Rails controllers having decided not to mix the Vero gem directly into
5
+ # your models.
6
+ #
7
+ # Example usage:
8
+ #
9
+ # class UsersController < ApplicationController
10
+ # include Vero::DSL
11
+ #
12
+ # def update
13
+ # vero.users.track!({ ... })
14
+ # end
15
+ # end
16
+ module DSL
17
+ def vero
18
+ @proxy ||= Proxy.new
19
+ end
20
+
21
+ # :nodoc:
22
+ class Proxy
23
+ include Vero::Api
24
+
25
+ def users
26
+ Users
27
+ end
28
+
29
+ def events
30
+ Events
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/vero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vero
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -11,7 +11,45 @@ describe Vero::Api::Workers::Users::EditTagsAPI do
11
11
  end
12
12
 
13
13
  subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}) }
14
+
14
15
  describe :validate! do
16
+ it "should raise an error if email is a blank String" do
17
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => nil, :add => []}
18
+ subject.options = options
19
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
20
+
21
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :add => []}
22
+ subject.options = options
23
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should raise an error if add is not an Array or missing" do
27
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :add => "foo" }
28
+
29
+ subject.options = options
30
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
31
+ end
32
+
33
+ it "should raise an error if remove is not an Array or missing" do
34
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :remove => "foo" }
35
+
36
+ subject.options = options
37
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
38
+ end
39
+
40
+ it "should raise an error if botha add and remove are missing" do
41
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}
42
+
43
+ subject.options = options
44
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
45
+ end
46
+
47
+ it "should not raise an error if the correct arguments are passed" do
48
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com', :remove => [ "Hi" ] }
49
+
50
+ subject.options = options
51
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
52
+ end
15
53
  end
16
54
 
17
55
  describe :request do
@@ -28,4 +66,4 @@ describe Vero::Api::Workers::Users::EditTagsAPI do
28
66
  expect { subject.perform }.to_not raise_error
29
67
  end
30
68
  end
31
- end
69
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::DSL do
4
+ subject(:dsl) { Class.new.extend(Vero::DSL) }
5
+
6
+ describe '#vero' do
7
+ it 'is a proxy to the API' do
8
+ expect(dsl.vero).to be_an_instance_of(Vero::DSL::Proxy)
9
+ end
10
+ end
11
+ end
12
+
13
+ describe Vero::DSL::Proxy do
14
+ subject(:proxy) { described_class.new }
15
+
16
+ describe '#users' do
17
+ it 'is a pointer to Vero::Api::Users' do
18
+ expect(proxy.users).to eql(Vero::Api::Users)
19
+ end
20
+ end
21
+
22
+ describe '#events' do
23
+ it 'is a pointer to Vero::Api::Events' do
24
+ expect(proxy.events).to eql(Vero::Api::Events)
25
+ end
26
+ end
27
+ end
@@ -56,9 +56,9 @@ describe Vero::Trackable do
56
56
  end
57
57
 
58
58
  it "should not send a track request when the required parameters are invalid" do
59
- expect { @user.track!(nil) }.to raise_error(ArgumentError, "{\"data\":{},\"event_name\":null}")
60
- expect { @user.track!('') }.to raise_error(ArgumentError, "{\"data\":{},\"event_name\":\"\"}")
61
- expect { @user.track!('test', '') }.to raise_error(ArgumentError, "{\"data\":\"\",\"event_name\":\"test\"}")
59
+ expect { @user.track!(nil) }.to raise_error(ArgumentError)
60
+ expect { @user.track!('') }.to raise_error(ArgumentError)
61
+ expect { @user.track!('test', '') }.to raise_error(ArgumentError)
62
62
  end
63
63
 
64
64
  it "should send a `track!` request when async is set to false" do
@@ -359,4 +359,4 @@ describe Vero::Trackable do
359
359
  user.vero_track(request_params[:event_name], request_params[:data]).should == 200
360
360
  end
361
361
  end
362
- end
362
+ end
data/vero.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.authors = ['James Lamont']
14
14
 
15
15
  dependencies = [
16
- [:development, 'rails'],
16
+ [:development, 'rails', "> 3"],
17
17
  [:development, 'rspec'],
18
18
  [:development, 'delayed_job'],
19
19
  [:development, 'delayed_job_active_record'],
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.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ! '>'
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '3'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ! '>'
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '3'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +158,7 @@ files:
158
158
  - lib/vero/app.rb
159
159
  - lib/vero/config.rb
160
160
  - lib/vero/context.rb
161
+ - lib/vero/dsl.rb
161
162
  - lib/vero/railtie.rb
162
163
  - lib/vero/sender.rb
163
164
  - lib/vero/senders/base.rb
@@ -183,6 +184,7 @@ files:
183
184
  - spec/lib/app_spec.rb
184
185
  - spec/lib/config_spec.rb
185
186
  - spec/lib/context_spec.rb
187
+ - spec/lib/dsl_spec.rb
186
188
  - spec/lib/sender_spec.rb
187
189
  - spec/lib/trackable_spec.rb
188
190
  - spec/lib/view_helpers_spec.rb
@@ -224,6 +226,7 @@ test_files:
224
226
  - spec/lib/app_spec.rb
225
227
  - spec/lib/config_spec.rb
226
228
  - spec/lib/context_spec.rb
229
+ - spec/lib/dsl_spec.rb
227
230
  - spec/lib/sender_spec.rb
228
231
  - spec/lib/trackable_spec.rb
229
232
  - spec/lib/view_helpers_spec.rb