vero 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.9.0
2
+
3
+ - *Added support for Sidekiq**. You can now use Sidekiq to deliver API requests to Vero. To do so, just specify `config.async = :sidekiq` in your config.rb file.
4
+
1
5
  ## 0.8.0
2
6
 
3
7
  - **"development_mode" flag has been deprecated.** It is recommended to use a multiple projects (with different API credentials). Please contact support@getvero.com for assistance in upgrading your account.
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vero (0.8.1)
4
+ vero (0.8.2)
5
5
  json
6
6
  rest-client
7
- sucker_punch (~> 1.5)
7
+ sucker_punch (= 1.5.1)
8
8
 
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- actionmailer (3.2.21)
13
- actionpack (= 3.2.21)
12
+ actionmailer (3.2.22)
13
+ actionpack (= 3.2.22)
14
14
  mail (~> 2.5.4)
15
- actionpack (3.2.21)
16
- activemodel (= 3.2.21)
17
- activesupport (= 3.2.21)
15
+ actionpack (3.2.22)
16
+ activemodel (= 3.2.22)
17
+ activesupport (= 3.2.22)
18
18
  builder (~> 3.0.0)
19
19
  erubis (~> 2.7.0)
20
20
  journey (~> 1.0.4)
@@ -22,26 +22,27 @@ GEM
22
22
  rack-cache (~> 1.2)
23
23
  rack-test (~> 0.6.1)
24
24
  sprockets (~> 2.2.1)
25
- activemodel (3.2.21)
26
- activesupport (= 3.2.21)
25
+ activemodel (3.2.22)
26
+ activesupport (= 3.2.22)
27
27
  builder (~> 3.0.0)
28
- activerecord (3.2.21)
29
- activemodel (= 3.2.21)
30
- activesupport (= 3.2.21)
28
+ activerecord (3.2.22)
29
+ activemodel (= 3.2.22)
30
+ activesupport (= 3.2.22)
31
31
  arel (~> 3.0.2)
32
32
  tzinfo (~> 0.3.29)
33
- activeresource (3.2.21)
34
- activemodel (= 3.2.21)
35
- activesupport (= 3.2.21)
36
- activesupport (3.2.21)
33
+ activeresource (3.2.22)
34
+ activemodel (= 3.2.22)
35
+ activesupport (= 3.2.22)
36
+ activesupport (3.2.22)
37
37
  i18n (~> 0.6, >= 0.6.4)
38
38
  multi_json (~> 1.0)
39
39
  arel (3.0.3)
40
40
  builder (3.0.4)
41
41
  celluloid (0.16.0)
42
42
  timers (~> 4.0.0)
43
- delayed_job (4.0.6)
44
- activesupport (>= 3.0, < 5.0)
43
+ connection_pool (2.2.0)
44
+ delayed_job (3.0.5)
45
+ activesupport (~> 3.0)
45
46
  delayed_job_active_record (4.0.3)
46
47
  activerecord (>= 3.0, < 5.0)
47
48
  delayed_job (>= 3.0, < 4.1)
@@ -51,21 +52,22 @@ GEM
51
52
  erubis (2.7.0)
52
53
  hike (1.2.3)
53
54
  hitimes (1.2.2)
55
+ hitimes (1.2.2-java)
54
56
  http-cookie (1.0.2)
55
57
  domain_name (~> 0.5)
56
58
  i18n (0.7.0)
57
59
  journey (1.0.4)
58
- json (1.8.2)
59
- json (1.8.2-java)
60
+ json (1.8.3)
61
+ json (1.8.3-java)
60
62
  mail (2.5.4)
61
63
  mime-types (~> 1.16)
62
64
  treetop (~> 1.4.8)
63
65
  mime-types (1.25.1)
64
66
  mono_logger (1.1.0)
65
- multi_json (1.11.0)
67
+ multi_json (1.11.2)
66
68
  netrc (0.10.3)
67
69
  polyglot (0.3.5)
68
- rack (1.4.5)
70
+ rack (1.4.7)
69
71
  rack-cache (1.2)
70
72
  rack (>= 0.4)
71
73
  rack-protection (1.5.3)
@@ -74,17 +76,17 @@ GEM
74
76
  rack
75
77
  rack-test (0.6.3)
76
78
  rack (>= 1.0)
77
- rails (3.2.21)
78
- actionmailer (= 3.2.21)
79
- actionpack (= 3.2.21)
80
- activerecord (= 3.2.21)
81
- activeresource (= 3.2.21)
82
- activesupport (= 3.2.21)
79
+ rails (3.2.22)
80
+ actionmailer (= 3.2.22)
81
+ actionpack (= 3.2.22)
82
+ activerecord (= 3.2.22)
83
+ activeresource (= 3.2.22)
84
+ activesupport (= 3.2.22)
83
85
  bundler (~> 1.0)
84
- railties (= 3.2.21)
85
- railties (3.2.21)
86
- actionpack (= 3.2.21)
87
- activesupport (= 3.2.21)
86
+ railties (= 3.2.22)
87
+ railties (3.2.22)
88
+ actionpack (= 3.2.22)
89
+ activesupport (= 3.2.22)
88
90
  rack-ssl (~> 1.3.2)
89
91
  rake (>= 0.8.7)
90
92
  rdoc (~> 3.4)
@@ -105,19 +107,25 @@ GEM
105
107
  http-cookie (>= 1.0.2, < 2.0)
106
108
  mime-types (>= 1.16, < 3.0)
107
109
  netrc (~> 0.7)
108
- rspec (3.2.0)
109
- rspec-core (~> 3.2.0)
110
- rspec-expectations (~> 3.2.0)
111
- rspec-mocks (~> 3.2.0)
112
- rspec-core (3.2.3)
113
- rspec-support (~> 3.2.0)
114
- rspec-expectations (3.2.1)
110
+ rspec (3.3.0)
111
+ rspec-core (~> 3.3.0)
112
+ rspec-expectations (~> 3.3.0)
113
+ rspec-mocks (~> 3.3.0)
114
+ rspec-core (3.3.2)
115
+ rspec-support (~> 3.3.0)
116
+ rspec-expectations (3.3.1)
115
117
  diff-lcs (>= 1.2.0, < 2.0)
116
- rspec-support (~> 3.2.0)
117
- rspec-mocks (3.2.1)
118
+ rspec-support (~> 3.3.0)
119
+ rspec-mocks (3.3.2)
118
120
  diff-lcs (>= 1.2.0, < 2.0)
119
- rspec-support (~> 3.2.0)
120
- rspec-support (3.2.2)
121
+ rspec-support (~> 3.3.0)
122
+ rspec-support (3.3.0)
123
+ sidekiq (2.17.7)
124
+ celluloid (>= 0.15.2)
125
+ connection_pool (>= 1.0.0)
126
+ json
127
+ redis (>= 3.0.6)
128
+ redis-namespace (>= 1.3.1)
121
129
  sinatra (1.4.6)
122
130
  rack (~> 1.4)
123
131
  rack-protection (~> 1.4)
@@ -127,11 +135,11 @@ GEM
127
135
  multi_json (~> 1.0)
128
136
  rack (~> 1.0)
129
137
  tilt (~> 1.1, != 1.3.0)
130
- sucker_punch (1.5.0)
131
- celluloid (~> 0.16.0)
138
+ sucker_punch (1.5.1)
139
+ celluloid (= 0.16.0)
132
140
  thor (0.19.1)
133
141
  tilt (1.4.1)
134
- timers (4.0.1)
142
+ timers (4.0.4)
135
143
  hitimes
136
144
  treetop (1.4.15)
137
145
  polyglot
@@ -139,6 +147,7 @@ GEM
139
147
  tzinfo (0.3.44)
140
148
  unf (0.1.4)
141
149
  unf_ext
150
+ unf (0.1.4-java)
142
151
  unf_ext (0.0.7.1)
143
152
  vegas (0.1.11)
144
153
  rack (>= 1.0.0)
@@ -148,9 +157,10 @@ PLATFORMS
148
157
  ruby
149
158
 
150
159
  DEPENDENCIES
151
- delayed_job
160
+ delayed_job (~> 3.0.0)
152
161
  delayed_job_active_record
153
162
  rails (~> 3.0)
154
163
  resque
155
164
  rspec
165
+ sidekiq (~> 2.0)
156
166
  vero!
@@ -27,8 +27,8 @@ following:
27
27
  config.api_key = "Your Production API key goes here"
28
28
  config.secret = "Your Production API secret goes here"
29
29
  else
30
- config.api_key = "Your Test API key goes here"
31
- config.secret = "Your Test API secret goes here"
30
+ config.api_key = "Your Development API key goes here"
31
+ config.secret = "Your Development API secret goes here"
32
32
  end
33
33
  end
34
34
 
@@ -36,31 +36,19 @@ You will be able to find your API key and secret by logging into Vero
36
36
  ([sign up](http://getvero.com) if you haven't already) and clicking the
37
37
  'Your Account' link at the top of the page then select 'API Keys'.
38
38
 
39
- Previously all Vero accounts supported two environments: *test* and *live*.
40
- This feature has been deprecated in favour of one account with multiple
41
- projects.
42
-
43
- The gem will continue to support development_mode but will require
44
- you to explicitly set it in the initialiser. We recommend migrating your
45
- account as soon as possible. If you have any questions, please contact
46
- support@getvero.com.
47
-
48
- Vero::App.init do |config|
49
- config.development_mode = !Rails.env.production? # or use true
50
- end
51
-
52
39
  By default, events are sent asynchronously using a background thread.
53
40
  We recommend that you select one of the supported queue-based alternatives:
54
41
 
55
42
  config.async = :none # Synchronously
56
43
  config.async = :thread # Background thread (default)
57
44
  config.async = :delayed_job # DelayedJob
45
+ config.async = :sidekiq # Sidekiq
58
46
  config.async = :resque # Resque (recommended)
59
47
 
60
48
  **Note:** If you're using Mongoid with DelayedJob, you must add
61
49
  `gem "delayed_job_mongoid"` to your Gemfile.
62
50
 
63
- Finally, if you wish to disable vero requests when running your automated tests,
51
+ Finally, if you wish to disable Vero requests when running your automated tests,
64
52
  add the following line to your initializer:
65
53
 
66
54
  config.disabled = Rails.env.test?
@@ -221,6 +209,9 @@ outlined in Installation. Now you can call the API using the following methods:
221
209
 
222
210
  # Changing a user's id
223
211
  vero.users.reidentify!({:id => 123, :new_id => "honeybadger@getvero.com"})
212
+
213
+ # Resubscribing a user
214
+ vero.users.resubscribe!({:id => 123})
224
215
  end
225
216
 
226
217
  def destroy
@@ -10,6 +10,7 @@ module Vero
10
10
  autoload :DSL, 'vero/dsl'
11
11
  autoload :Sender, 'vero/sender'
12
12
  autoload :ResqueWorker, 'vero/senders/resque'
13
+ autoload :SidekiqWorker, 'vero/senders/sidekiq'
13
14
 
14
15
  module Api
15
16
  module Workers
@@ -24,6 +25,7 @@ module Vero
24
25
  autoload :EditAPI, 'vero/api/users/edit_api'
25
26
  autoload :EditTagsAPI, 'vero/api/users/edit_tags_api'
26
27
  autoload :UnsubscribeAPI, 'vero/api/users/unsubscribe_api'
28
+ autoload :ResubscribeAPI, 'vero/api/users/resubscribe_api'
27
29
  autoload :ReidentifyAPI, 'vero/api/users/reidentify_api'
28
30
  end
29
31
  end
@@ -36,6 +38,7 @@ module Vero
36
38
  autoload :Base, 'vero/senders/base'
37
39
  autoload :DelayedJob, 'vero/senders/delayed_job'
38
40
  autoload :Resque, 'vero/senders/resque'
41
+ autoload :Sidekiq, 'vero/senders/sidekiq'
39
42
  autoload :Invalid, 'vero/senders/invalid'
40
43
  autoload :Thread, 'vero/senders/thread'
41
44
  end
@@ -12,12 +12,10 @@ module Vero
12
12
  end
13
13
 
14
14
  def run_api(api_klass, options)
15
+ return if config.disabled
15
16
  validate_configured!
16
17
  options.merge!(config.request_params)
17
-
18
- unless config.disabled
19
- Vero::Sender.send(api_klass, config.async, config.domain, options)
20
- end
18
+ Vero::Sender.send(api_klass, config.async, config.domain, options)
21
19
  end
22
20
 
23
21
  protected
@@ -59,6 +57,10 @@ module Vero
59
57
  new(context).unsubscribe!(options)
60
58
  end
61
59
 
60
+ def self.resubscribe!(options, context = Vero::App.default_context)
61
+ new(context).resubscribe!(options)
62
+ end
63
+
62
64
  def track!(options)
63
65
  run_api(Vero::Api::Workers::Users::TrackAPI, options)
64
66
  end
@@ -75,6 +77,10 @@ module Vero
75
77
  run_api(Vero::Api::Workers::Users::UnsubscribeAPI, options)
76
78
  end
77
79
 
80
+ def resubscribe!(options)
81
+ run_api(Vero::Api::Workers::Users::ResubscribeAPI, options)
82
+ end
83
+
78
84
  def reidentify!(options)
79
85
  run_api(Vero::Api::Workers::Users::ReidentifyAPI, options)
80
86
  end
@@ -14,7 +14,7 @@ module Vero
14
14
 
15
15
  def initialize(domain, options)
16
16
  @domain = domain
17
- @options = options
17
+ self.options = options
18
18
  setup_logging
19
19
  end
20
20
 
@@ -0,0 +1,21 @@
1
+ module Vero
2
+ module Api
3
+ module Workers
4
+ module Users
5
+ class ResubscribeAPI < BaseAPI
6
+ def url
7
+ "#{@domain}/api/v2/users/resubscribe.json"
8
+ end
9
+
10
+ def request
11
+ RestClient.post(url, @options)
12
+ end
13
+
14
+ def validate!
15
+ raise ArgumentError.new("Missing :id or :email") if options[:id].to_s.blank? && options[:email].to_s.blank?
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -39,6 +39,7 @@ module Vero
39
39
  else
40
40
  self.senders[false]
41
41
  end
42
+
42
43
  (sender_class.new).call(api_class, domain, options)
43
44
  rescue => e
44
45
  options_s = JSON.dump(options)
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+ require 'sidekiq'
3
+
4
+ module Vero
5
+ class SidekiqWorker
6
+ include ::Sidekiq::Worker
7
+
8
+ def perform(api_class, domain, options)
9
+ api_class.constantize.new(domain, options).perform
10
+ Vero::App.log(self, "method: #{api_class}, options: #{options.to_json}, response: sidekiq job queued")
11
+ end
12
+ end
13
+
14
+ module Senders
15
+ class Sidekiq
16
+ def call(api_class, domain, options)
17
+ response = ::Vero::SidekiqWorker.perform_async(api_class.to_s, domain, options)
18
+ Vero::App.log(self, "method: #{api_class.name}, options: #{options.to_json}, response: sidekiq job queued")
19
+ response
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Vero
2
- VERSION = '0.8.1'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -5,13 +5,13 @@ describe Vero::Api::Workers::BaseAPI do
5
5
 
6
6
  describe :options_with_symbolized_keys do
7
7
  it "should create a new options Hash with symbol keys (much like Hash#symbolize_keys in rails)" do
8
- subject.options.should == {}
8
+ expect(subject.options).to eq({})
9
9
 
10
10
  subject.options = {:abc => 123}
11
- subject.options.should == {:abc => 123}
11
+ expect(subject.options).to eq({:abc => 123})
12
12
 
13
13
  subject.options = {"abc" => 123}
14
- subject.options.should == {:abc => 123}
14
+ expect(subject.options).to eq({:abc => 123})
15
15
  end
16
16
  end
17
17
  end
@@ -1,25 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vero::Api::Workers::Events::TrackAPI do
4
+ subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
4
5
 
5
- context "request without properties" do
6
- subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {}) }
7
- it "should inherit from Vero::Api::Workers::BaseCaller" do
8
- subject.should be_a(Vero::Api::Workers::BaseAPI)
9
- end
10
-
11
- it "should map to current version of Vero API" do
12
- subject.send(:url).should == "https://api.getvero.com/api/v2/events/track.json"
13
- end
6
+ it_behaves_like "a Vero wrapper" do
7
+ let(:end_point) { "/api/v2/events/track.json" }
14
8
  end
15
9
 
16
10
  context "request with properties" do
17
- subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
18
11
  describe :validate! do
19
12
  it "should raise an error if event_name is a blank String" do
20
13
  options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => nil}
21
14
  subject.options = options
22
- expect { subject.send(:validate!) }.to raise_error
15
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
23
16
 
24
17
  options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}
25
18
  subject.options = options
@@ -29,7 +22,7 @@ describe Vero::Api::Workers::Events::TrackAPI do
29
22
  it "should raise an error if data is not either nil or a Hash" do
30
23
  options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => []}
31
24
  subject.options = options
32
- expect { subject.send(:validate!) }.to raise_error
25
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
33
26
 
34
27
  options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => nil}
35
28
  subject.options = options
@@ -45,12 +38,17 @@ describe Vero::Api::Workers::Events::TrackAPI do
45
38
  subject.options = options
46
39
  expect { subject.send(:validate!) }.to_not raise_error
47
40
  end
41
+
42
+ it 'should not raise an error when keys are Strings for initialization' do
43
+ options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "event_name" => 'test_event', "data" => {}}
44
+ expect { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', options).send(:validate!) }.to_not raise_error
45
+ end
48
46
  end
49
47
 
50
48
  describe :request do
51
49
  it "should send a JSON request to the Vero API" do
52
- RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/events/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}.to_json, {:content_type => :json, :accept => :json})
53
- RestClient.stub(:post).and_return(200)
50
+ expect(RestClient).to receive(:post).with("https://api.getvero.com/api/v2/events/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}.to_json, {:content_type => :json, :accept => :json})
51
+ allow(RestClient).to receive(:post).and_return(200)
54
52
  subject.send(:request)
55
53
  end
56
54
  end
@@ -60,7 +58,7 @@ describe Vero::Api::Workers::Events::TrackAPI do
60
58
  it "should not raise any errors" do
61
59
  obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'})
62
60
 
63
- RestClient.stub(:post).and_return(200)
61
+ allow(RestClient).to receive(:post).and_return(200)
64
62
  expect { obj.perform }.to_not raise_error
65
63
  end
66
64
  end