vero 0.5.0 → 0.5.1

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vero (0.5.0)
4
+ vero (0.5.1)
5
5
  girl_friday
6
6
  json
7
7
  rest-client
data/README.markdown CHANGED
@@ -92,6 +92,8 @@ Finally, you can track multiple properties stored in a Hash by doing the followi
92
92
  }
93
93
  end
94
94
  end
95
+
96
+ **Note:** You may choose to bypass extending the `User` model by calling the API directly. More information can be found below.
95
97
 
96
98
  ## Sending events
97
99
 
@@ -143,4 +145,25 @@ You may want to send additional data about an event:
143
145
  render 'new'
144
146
  end
145
147
  end
146
- end
148
+ end
149
+
150
+ ## Calling the API directly
151
+
152
+ 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
+
154
+ 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:
155
+
156
+ # Tracking an event
157
+ Vero::Api::Events.track!({:event_name => "test_event", :data => {:date => "2013-02-12 16:17"}, :identity => {:email => "james@getvero.com"}})
158
+
159
+ # Identifying a user
160
+ Vero::Api::Users.track!({:email => "james@getvero.com"})
161
+
162
+ # Editing a user
163
+ Vero::Api::Users.edit_user!({:email => "james@getvero.com", :changes => {:age => 25}})
164
+
165
+ # Editing a user tags
166
+ Vero::Api::Users.edit_user_tags!({:email => "james@getvero.com", :add => [], :remove => ["awesome"]})
167
+
168
+ # Unsubscribe a user
169
+ Vero::Api::Users.unsubscribe!({:email => "james@getvero.com"})
@@ -2,53 +2,55 @@ require 'json'
2
2
  require 'rest-client'
3
3
 
4
4
  module Vero
5
- module API
6
- class BaseAPI
7
- attr_accessor :domain, :options
8
-
9
- def self.perform(domain, options)
10
- caller = self.new(domain, options)
11
- caller.perform
12
- end
5
+ module Api
6
+ module Workers
7
+ class BaseAPI
8
+ attr_accessor :domain, :options
9
+
10
+ def self.perform(domain, options)
11
+ caller = self.new(domain, options)
12
+ caller.perform
13
+ end
13
14
 
14
- def initialize(domain, options)
15
- @domain = domain
16
- @options = options
17
- setup_logging
18
- end
15
+ def initialize(domain, options)
16
+ @domain = domain
17
+ @options = options
18
+ setup_logging
19
+ end
19
20
 
20
- def perform
21
- validate!
22
- request
23
- end
21
+ def perform
22
+ validate!
23
+ request
24
+ end
24
25
 
25
- protected
26
- def setup_logging
27
- return unless Vero::App.logger
26
+ protected
27
+ def setup_logging
28
+ return unless Vero::App.logger
28
29
 
29
- RestClient.log = Object.new.tap do |proxy|
30
- def proxy.<<(message)
31
- Vero::App.logger.info message
30
+ RestClient.log = Object.new.tap do |proxy|
31
+ def proxy.<<(message)
32
+ Vero::App.logger.info message
33
+ end
32
34
  end
33
35
  end
34
- end
35
36
 
36
- def url
37
- end
37
+ def url
38
+ end
38
39
 
39
- def validate!
40
- raise "#{self.class.name}#validate! should be overridden"
41
- end
40
+ def validate!
41
+ raise "#{self.class.name}#validate! should be overridden"
42
+ end
42
43
 
43
- def request
44
- end
44
+ def request
45
+ end
45
46
 
46
- def request_content_type
47
- {:content_type => :json, :accept => :json}
48
- end
47
+ def request_content_type
48
+ {:content_type => :json, :accept => :json}
49
+ end
49
50
 
50
- def request_params_as_json
51
- JSON.dump(@options)
51
+ def request_params_as_json
52
+ JSON.dump(@options)
53
+ end
52
54
  end
53
55
  end
54
56
  end
@@ -1,23 +1,25 @@
1
1
  module Vero
2
- module API
3
- module Events
4
- class TrackAPI < BaseAPI
5
- def url
6
- "#{@domain}/api/v2/events/track.json"
7
- end
8
-
9
- def request
10
- RestClient.post(self.url, self.request_params_as_json, self.request_content_type)
11
- end
2
+ module Api
3
+ module Workers
4
+ module Events
5
+ class TrackAPI < BaseAPI
6
+ def url
7
+ "#{@domain}/api/v2/events/track.json"
8
+ end
9
+
10
+ def request
11
+ RestClient.post(self.url, self.request_params_as_json, self.request_content_type)
12
+ end
12
13
 
13
- def validate!
14
- result = true
15
- result &&= options[:event_name].to_s.blank? == false
16
- result &&= (options[:data].nil? || options[:data].is_a?(Hash))
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))
17
18
 
18
- unless result
19
- hash = {:data => options[:data], :event_name => options[:event_name]}
20
- raise ArgumentError.new(JSON.dump(hash))
19
+ unless result
20
+ hash = {:data => options[:data], :event_name => options[:event_name]}
21
+ raise ArgumentError.new(JSON.dump(hash))
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -1,22 +1,24 @@
1
1
  module Vero
2
- module API
3
- module Users
4
- class EditAPI < BaseAPI
5
- def url
6
- "#{@domain}/api/v2/users/edit.json"
7
- end
2
+ module Api
3
+ module Workers
4
+ module Users
5
+ class EditAPI < BaseAPI
6
+ def url
7
+ "#{@domain}/api/v2/users/edit.json"
8
+ end
8
9
 
9
- def request
10
- RestClient.put(url, self.request_params_as_json, self.request_content_type)
11
- end
10
+ def request
11
+ RestClient.put(url, self.request_params_as_json, self.request_content_type)
12
+ end
12
13
 
13
- def validate!
14
- result = true
15
- result &&= options[:email].to_s.blank? == false
16
- result &&= options[:changes].is_a?(Hash)
14
+ def validate!
15
+ result = true
16
+ result &&= options[:email].to_s.blank? == false
17
+ result &&= options[:changes].is_a?(Hash)
17
18
 
18
- unless result
19
- raise ArgumentError.new(:email => options[:email], :changes => options[:changes])
19
+ unless result
20
+ raise ArgumentError.new(:email => options[:email], :changes => options[:changes])
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,22 +1,24 @@
1
1
  module Vero
2
- module API
3
- module Users
4
- class EditTagsAPI < BaseAPI
5
- def url
6
- "#{@domain}/api/v2/users/tags/edit.json"
7
- end
2
+ module Api
3
+ module Workers
4
+ module Users
5
+ class EditTagsAPI < BaseAPI
6
+ def url
7
+ "#{@domain}/api/v2/users/tags/edit.json"
8
+ end
8
9
 
9
- def request
10
- RestClient.put(url, self.request_params_as_json, self.request_content_type)
11
- end
10
+ def request
11
+ RestClient.put(url, self.request_params_as_json, self.request_content_type)
12
+ end
12
13
 
13
- def validate!
14
- result = true
15
- result &&= options[:email].to_s.blank? == false
16
- result &&= (options[:add].is_a?(Array) || options[:remove].is_a?(Array))
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))
17
18
 
18
- unless result
19
- raise ArgumentError.new(:email => options[:email], :add => options[:add], :remove => options[:remove])
19
+ unless result
20
+ raise ArgumentError.new(:email => options[:email], :add => options[:add], :remove => options[:remove])
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,22 +1,24 @@
1
1
  module Vero
2
- module API
3
- module Users
4
- class TrackAPI < BaseAPI
5
- def url
6
- "#{@domain}/api/v2/users/track.json"
7
- end
2
+ module Api
3
+ module Workers
4
+ module Users
5
+ class TrackAPI < BaseAPI
6
+ def url
7
+ "#{@domain}/api/v2/users/track.json"
8
+ end
8
9
 
9
- def request
10
- RestClient.post(url, self.request_params_as_json, self.request_content_type)
11
- end
10
+ def request
11
+ RestClient.post(url, self.request_params_as_json, self.request_content_type)
12
+ end
12
13
 
13
- def validate!
14
- result = true
15
- result &&= options[:email].to_s.blank? == false
16
- result &&= (options[:data].nil? || options[:data].is_a?(Hash))
14
+ def validate!
15
+ result = true
16
+ result &&= options[:email].to_s.blank? == false
17
+ result &&= (options[:data].nil? || options[:data].is_a?(Hash))
17
18
 
18
- unless result
19
- raise ArgumentError.new(:email => options[:email], :data => options[:data])
19
+ unless result
20
+ raise ArgumentError.new(:email => options[:email], :data => options[:data])
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -1,21 +1,23 @@
1
1
  module Vero
2
- module API
3
- module Users
4
- class UnsubscribeAPI < BaseAPI
5
- def url
6
- "#{@domain}/api/v2/users/unsubscribe.json"
7
- end
2
+ module Api
3
+ module Workers
4
+ module Users
5
+ class UnsubscribeAPI < BaseAPI
6
+ def url
7
+ "#{@domain}/api/v2/users/unsubscribe.json"
8
+ end
8
9
 
9
- def request
10
- RestClient.post(url, @options)
11
- end
10
+ def request
11
+ RestClient.post(url, @options)
12
+ end
12
13
 
13
- def validate!
14
- result = true
15
- result &&= options[:email].to_s.blank? == false
14
+ def validate!
15
+ result = true
16
+ result &&= options[:email].to_s.blank? == false
16
17
 
17
- unless result
18
- raise ArgumentError.new(:email => options[:email])
18
+ unless result
19
+ raise ArgumentError.new(:email => options[:email])
20
+ end
19
21
  end
20
22
  end
21
23
  end
data/lib/vero/api.rb ADDED
@@ -0,0 +1,93 @@
1
+ module Vero
2
+ module Api
3
+ class Base
4
+ attr_accessor :context
5
+
6
+ def initialize(context)
7
+ self.context = context
8
+ end
9
+
10
+ def config
11
+ self.context.config
12
+ end
13
+
14
+ protected
15
+ def validate_configured!
16
+ unless config.configured?
17
+ raise "You must configure the 'vero' gem. Visit https://github.com/semblancesystems/vero for more details."
18
+ end
19
+ end
20
+ end
21
+
22
+ class Events < Base
23
+ def self.track!(options, context = Vero::App.default_context)
24
+ new(context).track!(options)
25
+ end
26
+
27
+ def track!(options)
28
+ validate_configured!
29
+
30
+ options.merge!(config.request_params)
31
+ unless config.disabled
32
+ Vero::Sender.send Vero::Api::Workers::Events::TrackAPI, config.async, config.domain, options
33
+ end
34
+ end
35
+ end
36
+
37
+ class Users < Base
38
+ def self.track!(options, context = Vero::App.default_context)
39
+ new(context).track!(options)
40
+ end
41
+
42
+ def self.edit_user!(options, context = Vero::App.default_context)
43
+ new(context).edit_user!(options)
44
+ end
45
+
46
+ def self.edit_user_tags!(options, context = Vero::App.default_context)
47
+ new(context).edit_user_tags!(options)
48
+ end
49
+
50
+ def self.unsubscribe!(options, context = Vero::App.default_context)
51
+ new(context).unsubscribe!(options)
52
+ end
53
+
54
+ def track!(options)
55
+ validate_configured!
56
+
57
+ options.merge!(config.request_params)
58
+ unless config.disabled
59
+ Vero::Sender.send Vero::Api::Workers::Users::TrackAPI, config.async, config.domain, options
60
+ end
61
+ end
62
+
63
+ def edit_user!(options)
64
+ validate_configured!
65
+ options.merge!(config.request_params)
66
+
67
+ unless config.disabled
68
+ Vero::Sender.send Vero::Api::Workers::Users::EditAPI, config.async, config.domain, options
69
+ end
70
+ end
71
+
72
+ def edit_user_tags!(options)
73
+ validate_configured!
74
+
75
+ options.merge!(config.request_params)
76
+
77
+ unless config.disabled
78
+ Vero::Sender.send Vero::Api::Workers::Users::EditTagsAPI, config.async, config.domain, options
79
+ end
80
+ end
81
+
82
+ def unsubscribe!(options)
83
+ validate_configured!
84
+
85
+ options.merge!(config.request_params)
86
+
87
+ unless config.disabled
88
+ Vero::Sender.send Vero::Api::Workers::Users::UnsubscribeAPI, config.async, config.domain, options
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
data/lib/vero/context.rb CHANGED
@@ -45,70 +45,37 @@ module Vero
45
45
  ### API methods
46
46
 
47
47
  def track!(event_name, event_data)
48
- validate_configured!
48
+ options = {:data => event_data, :event_name => event_name, :identity => subject.to_vero}
49
49
 
50
- identity = subject.to_vero
51
- options = @config.request_params
52
- options.merge!(:data => event_data, :event_name => event_name, :identity => identity)
53
-
54
- unless @config.disabled
55
- Vero::Sender.send Vero::API::Events::TrackAPI, @config.async, @config.domain, options
56
- end
50
+ Vero::Api::Events.track!(options, self)
57
51
  end
58
52
 
59
53
  def identify!
60
- validate_configured!
61
-
62
- data = subject.to_vero
63
- options = @config.request_params
64
- options.merge!(:email => data[:email], :data => data)
54
+ data = subject.to_vero
55
+ options = {:email => data[:email], :data => data}
65
56
 
66
- unless @config.disabled
67
- Vero::Sender.send Vero::API::Users::TrackAPI, @config.async, @config.domain, options
68
- end
57
+ Vero::Api::Users.track!(options, self)
69
58
  end
70
59
 
71
60
  def update_user!(email = nil)
72
- validate_configured!
73
-
74
61
  changes = subject.to_vero
75
- options = @config.request_params
76
- options.merge!(:email => (email || changes[:email]), :changes => changes)
62
+ options = {:email => (email || changes[:email]), :changes => changes}
77
63
 
78
- unless @config.disabled
79
- Vero::Sender.send Vero::API::Users::EditAPI, @config.async, @config.domain, options
80
- end
64
+ Vero::Api::Users.edit_user!(options, self)
81
65
  end
82
66
 
83
67
  def update_user_tags!(add = [], remove = [])
84
- validate_configured!
68
+ identity = subject.to_vero
69
+ options = {:email => identity[:email], :add => add, :remove => remove}
85
70
 
86
- identity = subject.to_vero
87
- options = @config.request_params
88
- options.merge!(:email => identity[:email], :add => add, :remove => remove)
89
-
90
- unless @config.disabled
91
- Vero::Sender.send Vero::API::Users::EditTagsAPI, @config.async, @config.domain, options
92
- end
71
+ Vero::Api::Users.edit_user_tags!(options, self)
93
72
  end
94
73
 
95
74
  def unsubscribe!
96
- validate_configured!
97
-
98
- identity = subject.to_vero
99
- options = @config.request_params
100
- options.merge!(:email => identity[:email])
101
-
102
- unless @config.disabled
103
- Vero::Sender.send Vero::API::Users::UnsubscribeAPI, @config.async, @config.domain, options
104
- end
105
- end
75
+ identity = subject.to_vero
76
+ options = {:email => identity[:email]}
106
77
 
107
- private
108
- def validate_configured!
109
- unless @config.configured?
110
- raise "You must configure the 'vero' gem. Visit https://github.com/semblancesystems/vero for more details."
111
- end
78
+ Vero::Api::Users.unsubscribe!(options, self)
112
79
  end
113
80
  end
114
81
  end
data/lib/vero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vero
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
data/lib/vero.rb CHANGED
@@ -7,19 +7,24 @@ module Vero
7
7
  autoload :Context, 'vero/context'
8
8
  autoload :Trackable, 'vero/trackable'
9
9
 
10
- module API
11
- autoload :BaseAPI, 'vero/api/base_api'
10
+ module Api
11
+ module Workers
12
+ autoload :BaseAPI, 'vero/api/base_api'
12
13
 
13
- module Events
14
- autoload :TrackAPI, 'vero/api/events/track_api'
15
- end
14
+ module Events
15
+ autoload :TrackAPI, 'vero/api/events/track_api'
16
+ end
16
17
 
17
- module Users
18
- autoload :TrackAPI, 'vero/api/users/track_api'
19
- autoload :EditAPI, 'vero/api/users/edit_api'
20
- autoload :EditTagsAPI, 'vero/api/users/edit_tags_api'
21
- autoload :UnsubscribeAPI, 'vero/api/users/unsubscribe_api'
18
+ module Users
19
+ autoload :TrackAPI, 'vero/api/users/track_api'
20
+ autoload :EditAPI, 'vero/api/users/edit_api'
21
+ autoload :EditTagsAPI, 'vero/api/users/edit_tags_api'
22
+ autoload :UnsubscribeAPI, 'vero/api/users/unsubscribe_api'
23
+ end
22
24
  end
25
+
26
+ autoload :Events, 'vero/api'
27
+ autoload :Users, 'vero/api'
23
28
  end
24
29
 
25
30
  module Utility
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vero::API::Events::TrackAPI do
3
+ describe Vero::Api::Workers::Events::TrackAPI do
4
4
 
5
5
  context "request without properties" do
6
- subject { Vero::API::Events::TrackAPI.new('https://www.getvero.com', {}) }
7
- it "should inherit from Vero::API::BaseCaller" do
8
- subject.should be_a(Vero::API::BaseAPI)
6
+ subject { Vero::Api::Workers::Events::TrackAPI.new('https://www.getvero.com', {}) }
7
+ it "should inherit from Vero::Api::Workers::BaseCaller" do
8
+ subject.should be_a(Vero::Api::Workers::BaseAPI)
9
9
  end
10
10
 
11
11
  it "should map to current version of Vero API" do
@@ -14,7 +14,7 @@ describe Vero::API::Events::TrackAPI do
14
14
  end
15
15
 
16
16
  context "request with properties" do
17
- subject { Vero::API::Events::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
17
+ subject { Vero::Api::Workers::Events::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
18
18
  describe :validate! do
19
19
  it "should raise an error if test_event is a blank String" do
20
20
  options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => nil}
@@ -52,7 +52,7 @@ describe Vero::API::Events::TrackAPI do
52
52
 
53
53
  describe "integration test" do
54
54
  it "should not raise any errors" do
55
- obj = Vero::API::Events::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'})
55
+ obj = Vero::Api::Workers::Events::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'})
56
56
 
57
57
  RestClient.stub(:post).and_return(200)
58
58
  expect { obj.perform }.to_not raise_error
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vero::API::Users::EditAPI do
4
- subject { Vero::API::Users::EditAPI.new('https://www.getvero.com', {}) }
5
- it "should inherit from Vero::API::BaseCaller" do
6
- subject.should be_a(Vero::API::BaseAPI)
3
+ describe Vero::Api::Workers::Users::EditAPI do
4
+ subject { Vero::Api::Workers::Users::EditAPI.new('https://www.getvero.com', {}) }
5
+ it "should inherit from Vero::Api::Workers::BaseCaller" do
6
+ subject.should be_a(Vero::Api::Workers::BaseAPI)
7
7
  end
8
8
 
9
9
  it "should map to current version of Vero API" do
10
10
  subject.send(:url).should == "https://www.getvero.com/api/v2/users/edit.json"
11
11
  end
12
12
 
13
- subject { Vero::API::Users::EditAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
13
+ subject { Vero::Api::Workers::Users::EditAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
14
14
  describe :validate! do
15
15
  end
16
16
 
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vero::API::Users::EditTagsAPI do
4
- subject { Vero::API::Users::EditTagsAPI.new('https://www.getvero.com', {}) }
5
- it "should inherit from Vero::API::BaseCaller" do
6
- subject.should be_a(Vero::API::BaseAPI)
3
+ describe Vero::Api::Workers::Users::EditTagsAPI do
4
+ subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://www.getvero.com', {}) }
5
+ it "should inherit from Vero::Api::Workers::BaseCaller" do
6
+ subject.should be_a(Vero::Api::Workers::BaseAPI)
7
7
  end
8
8
 
9
9
  it "should map to current version of Vero API" do
10
10
  subject.send(:url).should == "https://www.getvero.com/api/v2/users/tags/edit.json"
11
11
  end
12
12
 
13
- subject { Vero::API::Users::EditTagsAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}) }
13
+ subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}) }
14
14
  describe :validate! do
15
15
  end
16
16
 
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vero::API::Users::TrackAPI do
4
- subject { Vero::API::Users::TrackAPI.new('https://www.getvero.com', {}) }
5
- it "should inherit from Vero::API::BaseCaller" do
6
- subject.should be_a(Vero::API::BaseAPI)
3
+ describe Vero::Api::Workers::Users::TrackAPI do
4
+ subject { Vero::Api::Workers::Users::TrackAPI.new('https://www.getvero.com', {}) }
5
+ it "should inherit from Vero::Api::Workers::BaseCaller" do
6
+ subject.should be_a(Vero::Api::Workers::BaseAPI)
7
7
  end
8
8
 
9
9
  it "should map to current version of Vero API" do
10
10
  subject.send(:url).should == "https://www.getvero.com/api/v2/users/track.json"
11
11
  end
12
12
 
13
- subject { Vero::API::Users::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}) }
13
+ subject { Vero::Api::Workers::Users::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}) }
14
14
  describe :validate! do
15
15
  it "should raise an error if email is a blank String" do
16
16
  options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => nil}
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Vero::API::Users::UnsubscribeAPI do
4
- subject { Vero::API::Users::UnsubscribeAPI.new('https://www.getvero.com', {}) }
5
- it "should inherit from Vero::API::BaseCaller" do
6
- subject.should be_a(Vero::API::BaseAPI)
3
+ describe Vero::Api::Workers::Users::UnsubscribeAPI do
4
+ subject { Vero::Api::Workers::Users::UnsubscribeAPI.new('https://www.getvero.com', {}) }
5
+ it "should inherit from Vero::Api::Workers::BaseCaller" do
6
+ subject.should be_a(Vero::Api::Workers::BaseAPI)
7
7
  end
8
8
 
9
9
  it "should map to current version of Vero API" do
10
10
  subject.send(:url).should == "https://www.getvero.com/api/v2/users/unsubscribe.json"
11
11
  end
12
12
 
13
- subject { Vero::API::Users::UnsubscribeAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
13
+ subject { Vero::Api::Workers::Users::UnsubscribeAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
14
14
  describe :validate! do
15
15
  end
16
16
 
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::Api::Events do
4
+ let (:subject) { Vero::Api::Events }
5
+
6
+ describe :track! do
7
+ it "should call the TrackAPI object via the configured sender" do
8
+ input = {:event_name => "test_event", :identity => {:email => "james@getvero.com"}, :data => {:test => "test"}}
9
+ expected = input.merge(:auth_token => "abc123", :development_mode => true)
10
+
11
+ mock_context = Vero::Context.new
12
+ mock_context.config.stub(:configured?).and_return(true)
13
+ mock_context.config.stub(:auth_token).and_return("abc123")
14
+
15
+ Vero::App.stub(:default_context).and_return(mock_context)
16
+
17
+ Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Events::TrackAPI, true, "https://www.getvero.com", expected)
18
+
19
+ subject.track!(input)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe Vero::Api::Users do
25
+ let (:subject) { Vero::Api::Users }
26
+
27
+ describe :track! do
28
+ it "should call the TrackAPI object via the configured sender" do
29
+ input = {:email => "james@getvero.com", :data => {:age => 25}}
30
+ expected = input.merge(:auth_token => "abc123", :development_mode => true)
31
+
32
+ mock_context = Vero::Context.new
33
+ mock_context.config.stub(:configured?).and_return(true)
34
+ mock_context.config.stub(:auth_token).and_return("abc123")
35
+
36
+ Vero::App.stub(:default_context).and_return(mock_context)
37
+
38
+ Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::TrackAPI, true, "https://www.getvero.com", expected)
39
+
40
+ subject.track!(input)
41
+ end
42
+ end
43
+
44
+ describe :edit_user! do
45
+ it "should call the TrackAPI object via the configured sender" do
46
+ input = {:email => "james@getvero.com", :changes => {:age => 25}}
47
+ expected = input.merge(:auth_token => "abc123", :development_mode => true)
48
+
49
+ mock_context = Vero::Context.new
50
+ mock_context.config.stub(:configured?).and_return(true)
51
+ mock_context.config.stub(:auth_token).and_return("abc123")
52
+
53
+ Vero::App.stub(:default_context).and_return(mock_context)
54
+
55
+ Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::EditAPI, true, "https://www.getvero.com", expected)
56
+
57
+ subject.edit_user!(input)
58
+ end
59
+ end
60
+
61
+ describe :edit_user_tags! do
62
+ it "should call the TrackAPI object via the configured sender" do
63
+ input = {:add => ["boom"], :remove => ["tish"]}
64
+ expected = input.merge(:auth_token => "abc123", :development_mode => true)
65
+
66
+ mock_context = Vero::Context.new
67
+ mock_context.config.stub(:configured?).and_return(true)
68
+ mock_context.config.stub(:auth_token).and_return("abc123")
69
+
70
+ Vero::App.stub(:default_context).and_return(mock_context)
71
+
72
+ Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::EditTagsAPI, true, "https://www.getvero.com", expected)
73
+
74
+ subject.edit_user_tags!(input)
75
+ end
76
+ end
77
+
78
+ describe :unsubscribe! do
79
+ it "should call the TrackAPI object via the configured sender" do
80
+ input = {:email => "james@getvero"}
81
+ expected = input.merge(:auth_token => "abc123", :development_mode => true)
82
+
83
+ mock_context = Vero::Context.new
84
+ mock_context.config.stub(:configured?).and_return(true)
85
+ mock_context.config.stub(:auth_token).and_return("abc123")
86
+
87
+ Vero::App.stub(:default_context).and_return(mock_context)
88
+
89
+ Vero::Sender.should_receive(:send).with(Vero::Api::Workers::Users::UnsubscribeAPI, true, "https://www.getvero.com", expected)
90
+
91
+ subject.unsubscribe!(input)
92
+ end
93
+ end
94
+ end
@@ -47,9 +47,9 @@ describe Vero::Trackable do
47
47
  before do
48
48
  @request_params = {
49
49
  :event_name => 'test_event',
50
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
51
50
  :identity => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
52
51
  :data => { :test => 1 },
52
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
53
53
  :development_mode => true
54
54
  }
55
55
  @url = "https://www.getvero.com/api/v1/track.json"
@@ -70,10 +70,10 @@ describe Vero::Trackable do
70
70
 
71
71
  RestClient.stub(:post).and_return(200)
72
72
 
73
- RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/events/track.json", {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :data=>{:test=>1}, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20, :_user_type=>"User"}}.to_json, @content_type_params)
73
+ RestClient.should_receive(:post).with("https://www.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)
74
74
  @user.track!(@request_params[:event_name], @request_params[:data]).should == 200
75
75
 
76
- RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/events/track.json", {:auth_token=>"YWJjZDEyMzQ6ZWZnaDU2Nzg=", :development_mode=>true, :data=>{}, :event_name=>"test_event", :identity=>{:email=>"durkster@gmail.com", :age=>20, :_user_type=>"User"}}.to_json, @content_type_params)
76
+ RestClient.should_receive(:post).with("https://www.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)
77
77
  @user.track!(@request_params[:event_name]).should == 200
78
78
  end
79
79
 
@@ -107,10 +107,10 @@ describe Vero::Trackable do
107
107
  describe :identify! do
108
108
  before do
109
109
  @request_params = {
110
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
111
- :development_mode => true,
112
110
  :email => 'durkster@gmail.com',
113
- :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
111
+ :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
112
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
113
+ :development_mode => true
114
114
  }
115
115
  @url = "https://www.getvero.com/api/v2/users/track.json"
116
116
  end
@@ -145,10 +145,10 @@ describe Vero::Trackable do
145
145
  describe :update_user! do
146
146
  before do
147
147
  @request_params = {
148
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
149
- :development_mode => true,
150
148
  :email => 'durkster@gmail.com',
151
- :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
149
+ :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
150
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
151
+ :development_mode => true
152
152
  }
153
153
  @url = "https://www.getvero.com/api/v2/users/edit.json"
154
154
  end
@@ -195,11 +195,11 @@ describe Vero::Trackable do
195
195
  describe :update_user_tags! do
196
196
  before do
197
197
  @request_params = {
198
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
199
- :development_mode => true,
200
198
  :email => 'durkster@gmail.com',
201
199
  :add => [],
202
- :remove => []
200
+ :remove => [],
201
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
202
+ :development_mode => true
203
203
  }
204
204
  @url = "https://www.getvero.com/api/v2/users/tags/edit.json"
205
205
  end
@@ -233,8 +233,8 @@ describe Vero::Trackable do
233
233
  describe :unsubscribe! do
234
234
  before do
235
235
  @request_params = {
236
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
237
236
  :email => 'durkster@gmail.com',
237
+ :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
238
238
  :development_mode => true
239
239
  }
240
240
  @url = "https://www.getvero.com/api/v2/users/unsubscribe.json"
@@ -312,6 +312,19 @@ describe Vero::Trackable do
312
312
 
313
313
  it "should take into account any defined extras" do
314
314
  user = UserWithExtras.new
315
+ user.properties = nil
316
+ user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithExtras"}
317
+
318
+ user.properties = "test"
319
+ user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithExtras"}
320
+
321
+ user.properties = {}
322
+ user.to_vero.should == {:email => 'durkster@gmail.com', :_user_type => "UserWithExtras"}
323
+
324
+ user.properties = {
325
+ :age => 20,
326
+ :gender => "female"
327
+ }
315
328
  user.to_vero.should == {:email => 'durkster@gmail.com', :age => 20, :gender => "female", :_user_type => "UserWithExtras"}
316
329
  end
317
330
  end
@@ -72,14 +72,9 @@ class UserWithExtras
72
72
  include Vero::Trackable
73
73
  trackable :email, {:extras => :properties}
74
74
 
75
+ attr_accessor :properties
76
+
75
77
  def email
76
78
  'durkster@gmail.com'
77
79
  end
78
-
79
- def properties
80
- {
81
- :age => 20,
82
- :gender => "female"
83
- }
84
- end
85
80
  end
metadata CHANGED
@@ -1,134 +1,130 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vero
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 1
10
+ version: 0.5.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - James Lamont
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-02-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-02-12 00:00:00 +11:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
33
25
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
38
33
  type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
39
37
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: delayed_job
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
54
47
  type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: delayed_job
55
51
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
57
53
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: delayed_job_active_record
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
70
61
  type: :development
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: delayed_job_active_record
71
65
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
66
+ requirement: &id004 !ruby/object:Gem::Requirement
73
67
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
79
78
  name: json
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :runtime
87
79
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: rest-client
96
- requirement: !ruby/object:Gem::Requirement
80
+ requirement: &id005 !ruby/object:Gem::Requirement
97
81
  none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
102
89
  type: :runtime
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: rest-client
103
93
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: girl_friday
112
- requirement: !ruby/object:Gem::Requirement
94
+ requirement: &id006 !ruby/object:Gem::Requirement
113
95
  none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
118
103
  type: :runtime
104
+ version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: girl_friday
119
107
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
108
+ requirement: &id007 !ruby/object:Gem::Requirement
121
109
  none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ type: :runtime
118
+ version_requirements: *id007
126
119
  description:
127
120
  email: support@getvero.com
128
121
  executables: []
122
+
129
123
  extensions: []
124
+
130
125
  extra_rdoc_files: []
131
- files:
126
+
127
+ files:
132
128
  - Gemfile
133
129
  - Gemfile.lock
134
130
  - lib/generators/vero_generator.rb
@@ -138,6 +134,7 @@ files:
138
134
  - lib/vero/api/users/edit_tags_api.rb
139
135
  - lib/vero/api/users/track_api.rb
140
136
  - lib/vero/api/users/unsubscribe_api.rb
137
+ - lib/vero/api.rb
141
138
  - lib/vero/app.rb
142
139
  - lib/vero/config.rb
143
140
  - lib/vero/context.rb
@@ -161,6 +158,7 @@ files:
161
158
  - spec/lib/api/users/edit_tags_api_spec.rb
162
159
  - spec/lib/api/users/track_api_spec.rb
163
160
  - spec/lib/api/users/unsubscribe_api_spec.rb
161
+ - spec/lib/api_spec.rb
164
162
  - spec/lib/app_spec.rb
165
163
  - spec/lib/config_spec.rb
166
164
  - spec/lib/context_spec.rb
@@ -171,36 +169,47 @@ files:
171
169
  - spec/support/user_support.rb
172
170
  - spec/support/vero_user_support.rb
173
171
  - vero.gemspec
172
+ has_rdoc: true
174
173
  homepage: http://www.getvero.com/
175
174
  licenses: []
175
+
176
176
  post_install_message:
177
177
  rdoc_options: []
178
- require_paths:
178
+
179
+ require_paths:
179
180
  - lib
180
- required_ruby_version: !ruby/object:Gem::Requirement
181
+ required_ruby_version: !ruby/object:Gem::Requirement
181
182
  none: false
182
- requirements:
183
- - - ! '>='
184
- - !ruby/object:Gem::Version
185
- version: '0'
186
- required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ hash: 3
187
+ segments:
188
+ - 0
189
+ version: "0"
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
191
  none: false
188
- requirements:
189
- - - ! '>='
190
- - !ruby/object:Gem::Version
191
- version: '0'
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ hash: 3
196
+ segments:
197
+ - 0
198
+ version: "0"
192
199
  requirements: []
200
+
193
201
  rubyforge_project:
194
- rubygems_version: 1.8.23
202
+ rubygems_version: 1.6.2
195
203
  signing_key:
196
204
  specification_version: 3
197
205
  summary: Ruby gem for Vero
198
- test_files:
206
+ test_files:
199
207
  - spec/lib/api/events/track_api_spec.rb
200
208
  - spec/lib/api/users/edit_api_spec.rb
201
209
  - spec/lib/api/users/edit_tags_api_spec.rb
202
210
  - spec/lib/api/users/track_api_spec.rb
203
211
  - spec/lib/api/users/unsubscribe_api_spec.rb
212
+ - spec/lib/api_spec.rb
204
213
  - spec/lib/app_spec.rb
205
214
  - spec/lib/config_spec.rb
206
215
  - spec/lib/context_spec.rb