vero 0.5.4 → 0.5.6

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 CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vero (0.5.3)
4
+ vero (0.5.6)
5
5
  girl_friday
6
6
  json
7
7
  rest-client
8
8
 
9
9
  GEM
10
- remote: http://rubygems.org/
10
+ remote: https://rubygems.org/
11
11
  specs:
12
12
  actionmailer (3.2.13)
13
13
  actionpack (= 3.2.13)
data/README.markdown CHANGED
@@ -1,4 +1,5 @@
1
1
  # vero
2
+ [![Build Status](https://travis-ci.org/getvero/vero.png?branch=master)](https://travis-ci.org/getvero/vero)
2
3
 
3
4
  vero makes it easy to interact with Vero's REST API from your Ruby app. Vero is a user lifecycle platform that allows you to engage and re-engage your customer base via email, based on the actions they perform in your software.
4
5
 
@@ -23,6 +23,10 @@ module Vero
23
23
  request
24
24
  end
25
25
 
26
+ def options=(val)
27
+ @options = options_with_symbolized_keys(val)
28
+ end
29
+
26
30
  protected
27
31
  def setup_logging
28
32
  return unless Vero::App.logger
@@ -51,6 +55,13 @@ module Vero
51
55
  def request_params_as_json
52
56
  JSON.dump(@options)
53
57
  end
58
+
59
+ def options_with_symbolized_keys(val)
60
+ val.inject({}) do |h,(k,v)|
61
+ h[k.to_sym] = v
62
+ h
63
+ end
64
+ end
54
65
  end
55
66
  end
56
67
  end
data/lib/vero/config.rb CHANGED
@@ -32,7 +32,7 @@ module Vero
32
32
  if @domain.blank?
33
33
  'https://www.getvero.com'
34
34
  else
35
- @domain =~ /http[s]?\:\/\/.+/ ? @domain : "http://#{@domain}"
35
+ @domain =~ /http[s]?\:\/\/.+/ ? @domain : "http://#{@domain}"
36
36
  end
37
37
  end
38
38
 
@@ -49,6 +49,10 @@ module Vero
49
49
  auth_token?
50
50
  end
51
51
 
52
+ def disable_requests!
53
+ self.disabled = true
54
+ end
55
+
52
56
  def reset!
53
57
  self.disabled = false
54
58
  self.development_mode = false
@@ -0,0 +1,32 @@
1
+ module Vero
2
+ module APIContext
3
+ def track!(event_name, event_data, extras = {})
4
+ options = {:data => event_data, :event_name => event_name, :identity => subject.to_vero, :extras => extras}
5
+ Vero::Api::Events.track!(options, self)
6
+ end
7
+
8
+ def identify!
9
+ data = subject.to_vero
10
+ options = {:email => data[:email], :data => data}
11
+ Vero::Api::Users.track!(options, self)
12
+ end
13
+
14
+ def update_user!(email = nil)
15
+ changes = subject.to_vero
16
+ options = {:email => (email || changes[:email]), :changes => changes}
17
+ Vero::Api::Users.edit_user!(options, self)
18
+ end
19
+
20
+ def update_user_tags!(add = [], remove = [])
21
+ identity = subject.to_vero
22
+ options = {:email => identity[:email], :add => add, :remove => remove}
23
+ Vero::Api::Users.edit_user_tags!(options, self)
24
+ end
25
+
26
+ def unsubscribe!
27
+ identity = subject.to_vero
28
+ options = {:email => identity[:email]}
29
+ Vero::Api::Users.unsubscribe!(options, self)
30
+ end
31
+ end
32
+ end
data/lib/vero/context.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  module Vero
2
2
  class Context
3
+ include Vero::APIContext
3
4
  attr_accessor :config, :subject
4
5
 
5
6
  def initialize(object = {})
6
7
  case object
7
- when Hash
8
+ when Hash
8
9
  #stub
9
10
  when Vero::Context
10
11
  @config = object.config
@@ -35,47 +36,11 @@ module Vero
35
36
  end
36
37
 
37
38
  def disable_requests!
38
- @config.disabled = true
39
+ @config.disable_requests!
39
40
  end
40
41
 
41
42
  def configured?
42
43
  @config.configured?
43
44
  end
44
-
45
- ### API methods
46
-
47
- def track!(event_name, event_data)
48
- options = {:data => event_data, :event_name => event_name, :identity => subject.to_vero}
49
-
50
- Vero::Api::Events.track!(options, self)
51
- end
52
-
53
- def identify!
54
- data = subject.to_vero
55
- options = {:email => data[:email], :data => data}
56
-
57
- Vero::Api::Users.track!(options, self)
58
- end
59
-
60
- def update_user!(email = nil)
61
- changes = subject.to_vero
62
- options = {:email => (email || changes[:email]), :changes => changes}
63
-
64
- Vero::Api::Users.edit_user!(options, self)
65
- end
66
-
67
- def update_user_tags!(add = [], remove = [])
68
- identity = subject.to_vero
69
- options = {:email => identity[:email], :add => add, :remove => remove}
70
-
71
- Vero::Api::Users.edit_user_tags!(options, self)
72
- end
73
-
74
- def unsubscribe!
75
- identity = subject.to_vero
76
- options = {:email => identity[:email]}
77
-
78
- Vero::Api::Users.unsubscribe!(options, self)
79
- end
80
45
  end
81
46
  end
data/lib/vero/sender.rb CHANGED
@@ -7,31 +7,30 @@ module Vero
7
7
  super
8
8
  else
9
9
  klass_name = key.to_s.split("_").map(&:capitalize).join
10
- eval("Vero::Senders::#{klass_name}")
10
+ Vero::Senders.const_get(klass_name)
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
15
  class Sender
16
16
  def self.senders
17
- @senders ||= begin
18
- t = Vero::SenderHash.new
17
+ t = Vero::SenderHash.new
19
18
 
20
- t.merge!({
21
- true => Vero::Senders::Invalid,
22
- false => Vero::Senders::Base,
23
- :none => Vero::Senders::Base,
24
- :thread => Vero::Senders::Invalid
25
- })
19
+ t.merge!({
20
+ true => Vero::Senders::Invalid,
21
+ false => Vero::Senders::Base,
22
+ :none => Vero::Senders::Base,
23
+ :thread => Vero::Senders::Invalid
24
+ })
26
25
 
27
- if RUBY_VERSION =~ /1\.9\./
28
- t.merge!(
29
- true => Vero::Senders::Thread,
30
- :thread => Vero::Senders::Thread
31
- )
32
- end
33
- t
26
+ if RUBY_VERSION !~ /1\.8\./
27
+ t.merge!(
28
+ true => Vero::Senders::Thread,
29
+ :thread => Vero::Senders::Thread
30
+ )
34
31
  end
32
+
33
+ t
35
34
  end
36
35
 
37
36
  def self.send(api_class, sender_strategy, domain, options)
@@ -47,4 +46,4 @@ module Vero
47
46
  raise e
48
47
  end
49
48
  end
50
- end
49
+ end
data/lib/vero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vero
2
- VERSION = '0.5.4'
2
+ VERSION = '0.5.6'
3
3
  end
data/lib/vero.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require 'rest-client'
2
2
  require 'vero/utility/ext'
3
3
 
4
- module Vero
5
- autoload :Config, 'vero/config'
6
- autoload :App, 'vero/app'
7
- autoload :Context, 'vero/context'
8
- autoload :Trackable, 'vero/trackable'
9
- autoload :DSL, 'vero/dsl'
10
-
4
+ module Vero
5
+ autoload :Config, 'vero/config'
6
+ autoload :App, 'vero/app'
7
+ autoload :Context, 'vero/context'
8
+ autoload :APIContext, 'vero/context/api'
9
+ autoload :Trackable, 'vero/trackable'
10
+ autoload :DSL, 'vero/dsl'
11
+ autoload :Sender, 'vero/sender'
12
+ autoload :ResqueWorker, 'vero/senders/resque'
13
+
11
14
  module Api
12
15
  module Workers
13
16
  autoload :BaseAPI, 'vero/api/base_api'
@@ -27,20 +30,18 @@ module Vero
27
30
  autoload :Events, 'vero/api'
28
31
  autoload :Users, 'vero/api'
29
32
  end
30
-
31
- module Utility
32
- autoload :Logger, 'vero/utility/logger'
33
- end
34
33
 
35
34
  module Senders
36
- autoload :Base, 'vero/senders/base'
37
- autoload :DelayedJob, 'vero/senders/delayed_job'
38
- autoload :Resque, 'vero/senders/resque'
39
- autoload :Invalid, 'vero/senders/invalid'
40
- autoload :Thread, 'vero/senders/thread'
35
+ autoload :Base, 'vero/senders/base'
36
+ autoload :DelayedJob, 'vero/senders/delayed_job'
37
+ autoload :Resque, 'vero/senders/resque'
38
+ autoload :Invalid, 'vero/senders/invalid'
39
+ autoload :Thread, 'vero/senders/thread'
40
+ end
41
+
42
+ module Utility
43
+ autoload :Logger, 'vero/utility/logger'
41
44
  end
42
- autoload :Sender, 'vero/sender'
43
- autoload :ResqueWorker, 'vero/senders/resque'
44
45
  end
45
46
 
46
47
  require 'vero/railtie' if defined?(Rails)
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Vero::Api::Workers::BaseAPI do
4
+ let (:subject) { Vero::Api::Workers::BaseAPI.new("http://www.getvero.com", {}) }
5
+
6
+ describe :options_with_symbolized_keys do
7
+ it "should create a new options Hash with symbol keys (much like Hash#symbolize_keys in rails)" do
8
+ subject.options.should == {}
9
+
10
+ subject.options = {:abc => 123}
11
+ subject.options.should == {:abc => 123}
12
+
13
+ subject.options = {"abc" => 123}
14
+ subject.options.should == {:abc => 123}
15
+ end
16
+ end
17
+ end
@@ -39,6 +39,12 @@ describe Vero::Api::Workers::Events::TrackAPI do
39
39
  subject.options = options
40
40
  expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
41
41
  end
42
+
43
+ it "should not raise an error when the keys are Strings" do
44
+ options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "event_name" => 'test_event', "data" => {}}
45
+ subject.options = options
46
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
47
+ end
42
48
  end
43
49
 
44
50
  describe :request do
@@ -12,6 +12,11 @@ describe Vero::Api::Workers::Users::EditAPI do
12
12
 
13
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
+ it "should not raise an error when the keys are Strings" do
16
+ options = {"auth_token" => 'abcd', "email" => 'test@test.com', "changes" => { "email" => 'test@test.com' }}
17
+ subject.options = options
18
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
19
+ end
15
20
  end
16
21
 
17
22
  describe :request do
@@ -50,6 +50,12 @@ describe Vero::Api::Workers::Users::EditTagsAPI do
50
50
  subject.options = options
51
51
  expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
52
52
  end
53
+
54
+ it "should not raise an error when the keys are Strings" do
55
+ options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "email" => 'test@test.com', "remove" => [ "Hi" ] }
56
+ subject.options = options
57
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
58
+ end
53
59
  end
54
60
 
55
61
  describe :request do
@@ -35,6 +35,12 @@ describe Vero::Api::Workers::Users::TrackAPI do
35
35
  subject.options = options
36
36
  expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
37
37
  end
38
+
39
+ it "should not raise an error when the keys are Strings" do
40
+ options = {"auth_token" => 'abcd', "identity" => {"email" => 'test@test.com'}, "email" => 'test@test.com', "data" => {}}
41
+ subject.options = options
42
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
43
+ end
38
44
  end
39
45
 
40
46
  describe :request do
@@ -12,6 +12,11 @@ describe Vero::Api::Workers::Users::UnsubscribeAPI do
12
12
 
13
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
+ it "should not raise an error when the keys are Strings" do
16
+ options = {"auth_token" => 'abcd', "email" => 'test@test.com', "changes" => { "email" => 'test@test.com' }}
17
+ subject.options = options
18
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
19
+ end
15
20
  end
16
21
 
17
22
  describe :request do
@@ -2,34 +2,39 @@ require 'spec_helper'
2
2
 
3
3
  describe Vero::Sender do
4
4
  subject { Vero::Sender }
5
- describe "self.senders" do
5
+
6
+ describe ".senders" do
6
7
  it "should be a Hash" do
7
8
  subject.senders.should be_a(Hash)
8
9
  end
9
-
10
- unless RUBY_VERSION =~ /1\.9\./
11
- context "< Ruby 1.9" do
12
- it "should have a default set of senders (true, false, none, thread)" do
13
- subject.senders.should == {
14
- true => Vero::Senders::Invalid,
15
- false => Vero::Senders::Base,
16
- :none => Vero::Senders::Base,
17
- :thread => Vero::Senders::Invalid,
18
- }
19
- end
10
+
11
+ context 'when using Ruby 1.8' do
12
+ before do
13
+ stub_const('RUBY_VERSION', '1.8.7')
14
+ end
15
+
16
+ it "should have a default set of senders (true, false, none, thread)" do
17
+ subject.senders.should == {
18
+ true => Vero::Senders::Invalid,
19
+ false => Vero::Senders::Base,
20
+ :none => Vero::Senders::Base,
21
+ :thread => Vero::Senders::Invalid,
22
+ }
20
23
  end
21
24
  end
22
25
 
23
- if RUBY_VERSION =~ /1\.9\./
24
- context "~> Ruby 1.9" do
25
- it "should have a default set of senders (true, false, none, thread)" do
26
- subject.senders.should == {
27
- true => Vero::Senders::Thread,
28
- false => Vero::Senders::Base,
29
- :none => Vero::Senders::Base,
30
- :thread => Vero::Senders::Thread,
31
- }
32
- end
26
+ context 'when using Ruby with verion greater than 1.8.7' do
27
+ before do
28
+ stub_const('RUBY_VERSION', '1.9.3')
29
+ end
30
+
31
+ it "should have a default set of senders (true, false, none, thread)" do
32
+ subject.senders.should == {
33
+ true => Vero::Senders::Thread,
34
+ false => Vero::Senders::Base,
35
+ :none => Vero::Senders::Base,
36
+ :thread => Vero::Senders::Thread,
37
+ }
33
38
  end
34
39
  end
35
40
 
@@ -40,4 +45,4 @@ describe Vero::Sender do
40
45
  subject.senders[:none].should == Vero::Senders::Base
41
46
  end
42
47
  end
43
- end
48
+ end
@@ -49,8 +49,7 @@ describe Vero::Trackable do
49
49
  :event_name => 'test_event',
50
50
  :identity => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
51
51
  :data => { :test => 1 },
52
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
53
- :development_mode => true
52
+ :extras => {}
54
53
  }
55
54
  @url = "https://www.getvero.com/api/v1/track.json"
56
55
  end
@@ -70,47 +69,59 @@ describe Vero::Trackable do
70
69
 
71
70
  RestClient.stub(:post).and_return(200)
72
71
 
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)
72
+ # 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)
73
+
74
+ Vero::Api::Events.stub(:track!).and_return(200)
75
+ Vero::Api::Events.should_receive(:track!).with(@request_params, context)
74
76
  @user.track!(@request_params[:event_name], @request_params[:data]).should == 200
75
77
 
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)
78
+ # 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)
79
+
80
+ Vero::Api::Events.stub(:track!).and_return(200)
81
+ Vero::Api::Events.should_receive(:track!).with(@request_params.merge(:data => {}), context)
77
82
  @user.track!(@request_params[:event_name]).should == 200
78
83
  end
79
84
 
80
- it "should send using another thread when async is set to true" do
81
- context = Vero::Context.new(Vero::App.default_context)
82
- context.config.logging = true
83
- context.subject = @user
84
- context.config.async = true
85
+ context 'when set to be async' do
86
+ let(:my_context) { Vero::Context.new(Vero::App.default_context) }
85
87
 
86
- @user.stub(:with_vero_context).and_return(context)
88
+ before do
89
+ my_context.config.logging = true
90
+ my_context.subject = @user
91
+ my_context.config.async = true
87
92
 
88
- if RUBY_VERSION =~ /1\.9\./
89
- @user.track!(@request_params[:event_name], @request_params[:data]).should be_true
90
- @user.track!(@request_params[:event_name]).should be_true
91
- else
92
- expect { @user.track!(@request_params[:event_name], @request_params[:data]) }.to raise_error
93
- expect { @user.track!(@request_params[:event_name]) }.to raise_error
93
+ @user.stub(:with_vero_context).and_return(my_context)
94
94
  end
95
- end
96
95
 
97
- # it "should raise an error when async is set to false and the request times out" do
98
- # Rails.stub(:logger).and_return(Logger.new('info'))
99
- # context = Vero::App.default_context
100
- # context.config.async = false
101
- # context.config.domain = "200.200.200.200"
96
+ context 'using Ruby 1.8.7' do
97
+ before do
98
+ stub_const('RUBY_VERSION', '1.8.7')
99
+ end
102
100
 
103
- # expect { @user.track(@request_params[:event_name], @request_params[:data]) }.to raise_error
104
- # end
101
+ it 'raises an error' do
102
+ expect { @user.track!(@request_params[:event_name], @request_params[:data]) }.to raise_error
103
+ expect { @user.track!(@request_params[:event_name]) }.to raise_error
104
+ end
105
+ end
106
+
107
+ context 'not using Ruby 1.8.7' do
108
+ before do
109
+ stub_const('RUBY_VERSION', '1.9.3')
110
+ end
111
+
112
+ it 'sends' do
113
+ @user.track!(@request_params[:event_name], @request_params[:data]).should be_true
114
+ @user.track!(@request_params[:event_name]).should be_true
115
+ end
116
+ end
117
+ end
105
118
  end
106
119
 
107
120
  describe :identify! do
108
121
  before do
109
122
  @request_params = {
110
123
  :email => 'durkster@gmail.com',
111
- :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
112
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
113
- :development_mode => true
124
+ :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
114
125
  }
115
126
  @url = "https://www.getvero.com/api/v2/users/track.json"
116
127
  end
@@ -121,23 +132,41 @@ describe Vero::Trackable do
121
132
 
122
133
  @user.stub(:with_vero_context).and_return(context)
123
134
 
124
- RestClient.stub(:post).and_return(200)
125
- RestClient.should_receive(:post).with(@url, @request_params.to_json, @content_type_params)
126
-
135
+ # RestClient.stub(:post).and_return(200)
136
+ # RestClient.should_receive(:post).with(@url, @request_params.to_json, @content_type_params)
137
+
138
+ Vero::Api::Users.stub(:track!).and_return(200)
139
+ Vero::Api::Users.should_receive(:track!).with(@request_params, context)
140
+
127
141
  @user.identify!.should == 200
128
142
  end
129
143
 
130
- it "should send using another thread when async is set to true" do
131
- context = Vero::Context.new(Vero::App.default_context)
132
- context.subject = @user
133
- context.config.async = true
144
+ context 'when set to use async' do
145
+ let(:my_context) { Vero::Context.new(Vero::App.default_context) }
134
146
 
135
- @user.stub(:with_vero_context).and_return(context)
147
+ before do
148
+ my_context.subject = @user
149
+ my_context.config.async = true
150
+ end
151
+
152
+ context 'and using Ruby 1.8.7' do
153
+ before do
154
+ stub_const('RUBY_VERSION', '1.8.7')
155
+ end
156
+
157
+ it 'raises an error' do
158
+ expect { @user.identify! }.to raise_error
159
+ end
160
+ end
161
+
162
+ context 'and not using Ruby 1.8.7' do
163
+ before do
164
+ stub_const('RUBY_VERSION', '1.9.3')
165
+ end
136
166
 
137
- if RUBY_VERSION =~ /1\.9\./
138
- @user.identify!.should be_true
139
- else
140
- expect { @user.identify! }.to raise_error
167
+ it 'sends' do
168
+ @user.identify!.should be_true
169
+ end
141
170
  end
142
171
  end
143
172
  end
@@ -147,8 +176,6 @@ describe Vero::Trackable do
147
176
  @request_params = {
148
177
  :email => 'durkster@gmail.com',
149
178
  :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
150
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
151
- :development_mode => true
152
179
  }
153
180
  @url = "https://www.getvero.com/api/v2/users/edit.json"
154
181
  end
@@ -159,9 +186,12 @@ describe Vero::Trackable do
159
186
 
160
187
  @user.stub(:with_vero_context).and_return(context)
161
188
 
162
- RestClient.stub(:put).and_return(200)
163
- RestClient.should_receive(:put).with(@url, @request_params.merge(:email => "durkster1@gmail.com").to_json, @content_type_params)
164
-
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
+
165
195
  @user.with_vero_context.update_user!("durkster1@gmail.com").should == 200
166
196
  end
167
197
 
@@ -171,23 +201,43 @@ describe Vero::Trackable do
171
201
 
172
202
  @user.stub(:with_vero_context).and_return(context)
173
203
 
174
- RestClient.stub(:put).and_return(200)
175
- RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
176
-
204
+ # RestClient.stub(:put).and_return(200)
205
+ # RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
206
+
207
+ Vero::Api::Users.stub(:edit_user!).and_return(200)
208
+ Vero::Api::Users.should_receive(:edit_user!).with(@request_params, context)
209
+
177
210
  @user.with_vero_context.update_user!.should == 200
178
211
  end
179
212
 
180
- it "should send using another thread when async is set to true" do
181
- context = Vero::Context.new(Vero::App.default_context)
182
- context.subject = @user
183
- context.config.async = true
213
+ context 'when set to use async' do
214
+ let(:my_context) { Vero::Context.new(Vero::App.default_context) }
184
215
 
185
- @user.stub(:with_vero_context).and_return(context)
216
+ before do
217
+ my_context.subject = @user
218
+ my_context.config.async = true
219
+
220
+ @user.stub(:with_vero_context).and_return(my_context)
221
+ end
222
+
223
+ context 'and using Ruby 1.8.7' do
224
+ before do
225
+ stub_const('RUBY_VERSION', '1.8.7')
226
+ end
227
+
228
+ it 'raises an error' do
229
+ expect { @user.with_vero_context.update_user! }.to raise_error
230
+ end
231
+ end
186
232
 
187
- if RUBY_VERSION =~ /1\.9\./
188
- @user.with_vero_context.update_user!.should be_true
189
- else
190
- expect { @user.with_vero_context.update_user! }.to raise_error
233
+ context 'and not using Ruby 1.8.7' do
234
+ before do
235
+ stub_const('RUBY_VERSION', '1.9.3')
236
+ end
237
+
238
+ it 'sends' do
239
+ @user.with_vero_context.update_user!.should be_true
240
+ end
191
241
  end
192
242
  end
193
243
  end
@@ -197,9 +247,7 @@ describe Vero::Trackable do
197
247
  @request_params = {
198
248
  :email => 'durkster@gmail.com',
199
249
  :add => [],
200
- :remove => [],
201
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
202
- :development_mode => true
250
+ :remove => []
203
251
  }
204
252
  @url = "https://www.getvero.com/api/v2/users/tags/edit.json"
205
253
  end
@@ -211,9 +259,12 @@ describe Vero::Trackable do
211
259
 
212
260
  @user.stub(:with_vero_context).and_return(context)
213
261
 
214
- RestClient.stub(:put).and_return(200)
215
- RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
216
-
262
+ # RestClient.stub(:put).and_return(200)
263
+ # RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
264
+
265
+ Vero::Api::Users.stub(:edit_user_tags!).and_return(200)
266
+ Vero::Api::Users.should_receive(:edit_user_tags!).with(@request_params, context)
267
+
217
268
  @user.with_vero_context.update_user_tags!.should == 200
218
269
  end
219
270
 
@@ -233,9 +284,7 @@ describe Vero::Trackable do
233
284
  describe :unsubscribe! do
234
285
  before do
235
286
  @request_params = {
236
- :email => 'durkster@gmail.com',
237
- :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
238
- :development_mode => true
287
+ :email => 'durkster@gmail.com'
239
288
  }
240
289
  @url = "https://www.getvero.com/api/v2/users/unsubscribe.json"
241
290
  end
@@ -247,21 +296,43 @@ describe Vero::Trackable do
247
296
 
248
297
  @user.stub(:with_vero_context).and_return(context)
249
298
 
250
- RestClient.stub(:post).and_return(200)
251
- RestClient.should_receive(:post).with(@url, @request_params)
252
-
299
+ # RestClient.stub(:post).and_return(200)
300
+ # RestClient.should_receive(:post).with(@url, @request_params)
301
+
302
+ Vero::Api::Users.stub(:unsubscribe!).and_return(200)
303
+ Vero::Api::Users.should_receive(:unsubscribe!).with(@request_params, context)
304
+
253
305
  @user.with_vero_context.unsubscribe!.should == 200
254
306
  end
255
307
 
256
- if RUBY_VERSION =~ /1\.9\./
257
- it "should send using another thread when async is set to true" do
258
- context = Vero::Context.new(Vero::App.default_context)
259
- context.subject = @user
260
- context.config.async = true
308
+ context 'when using async' do
309
+ let(:my_context) { Vero::Context.new(Vero::App.default_context) }
261
310
 
262
- @user.stub(:with_vero_context).and_return(context)
311
+ before do
312
+ my_context.subject = @user
313
+ my_context.config.async = true
263
314
 
264
- @user.with_vero_context.unsubscribe!.should be_true
315
+ @user.stub(:with_vero_context).and_return(my_context)
316
+ end
317
+
318
+ context 'and using Ruby 1.8.7' do
319
+ before do
320
+ stub_const('RUBY_VERSION', '1.8.7')
321
+ end
322
+
323
+ it 'raises an error' do
324
+ expect { @user.with_vero_context.unsubscribe! }.to raise_error
325
+ end
326
+ end
327
+
328
+ context 'and using Ruby 1.9.3' do
329
+ before do
330
+ stub_const('RUBY_VERSION', '1.9.3')
331
+ end
332
+
333
+ it 'sends' do
334
+ @user.with_vero_context.unsubscribe!.should be_true
335
+ end
265
336
  end
266
337
  end
267
338
  end
@@ -336,7 +407,7 @@ describe Vero::Trackable do
336
407
  user.with_vero_context({:api_key => "boom", :secret => "tish"}).config.config_params.should == {:api_key=>"boom", :secret=>"tish"}
337
408
  end
338
409
  end
339
-
410
+
340
411
  it "should work when Vero::Trackable::Interface is not included" do
341
412
  user = UserWithoutInterface.new
342
413
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'vero'
4
+ require 'json'
4
5
 
5
6
  Dir[::File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
6
7
 
metadata CHANGED
@@ -1,150 +1,144 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vero
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.4
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 6
10
+ version: 0.5.6
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-03-27 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-04-16 00:00:00 +10: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: '3'
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: '3'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 3
32
+ version: "3"
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
41
- 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'
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
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
57
- 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'
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
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
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: resque
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
86
75
  type: :development
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: resque
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
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
95
92
  name: json
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
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: rest-client
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
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: rest-client
119
107
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: girl_friday
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
108
+ requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
134
117
  type: :runtime
118
+ version_requirements: *id007
119
+ - !ruby/object:Gem::Dependency
120
+ name: girl_friday
135
121
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
122
+ requirement: &id008 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ type: :runtime
132
+ version_requirements: *id008
142
133
  description:
143
134
  email: support@getvero.com
144
135
  executables: []
136
+
145
137
  extensions: []
138
+
146
139
  extra_rdoc_files: []
147
- files:
140
+
141
+ files:
148
142
  - Gemfile
149
143
  - Gemfile.lock
150
144
  - lib/generators/vero_generator.rb
@@ -157,6 +151,7 @@ files:
157
151
  - lib/vero/api.rb
158
152
  - lib/vero/app.rb
159
153
  - lib/vero/config.rb
154
+ - lib/vero/context/api.rb
160
155
  - lib/vero/context.rb
161
156
  - lib/vero/dsl.rb
162
157
  - lib/vero/railtie.rb
@@ -175,6 +170,7 @@ files:
175
170
  - lib/vero/view_helpers/javascript.rb
176
171
  - lib/vero.rb
177
172
  - README.markdown
173
+ - spec/lib/api/base_api_spec.rb
178
174
  - spec/lib/api/events/track_api_spec.rb
179
175
  - spec/lib/api/users/edit_api_spec.rb
180
176
  - spec/lib/api/users/edit_tags_api_spec.rb
@@ -192,31 +188,42 @@ files:
192
188
  - spec/support/user_support.rb
193
189
  - spec/support/vero_user_support.rb
194
190
  - vero.gemspec
191
+ has_rdoc: true
195
192
  homepage: http://www.getvero.com/
196
193
  licenses: []
194
+
197
195
  post_install_message:
198
196
  rdoc_options: []
199
- require_paths:
197
+
198
+ require_paths:
200
199
  - lib
201
- required_ruby_version: !ruby/object:Gem::Requirement
200
+ required_ruby_version: !ruby/object:Gem::Requirement
202
201
  none: false
203
- requirements:
204
- - - ! '>='
205
- - !ruby/object:Gem::Version
206
- version: '0'
207
- required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ hash: 3
206
+ segments:
207
+ - 0
208
+ version: "0"
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
210
  none: false
209
- requirements:
210
- - - ! '>='
211
- - !ruby/object:Gem::Version
212
- version: '0'
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ hash: 3
215
+ segments:
216
+ - 0
217
+ version: "0"
213
218
  requirements: []
219
+
214
220
  rubyforge_project:
215
- rubygems_version: 1.8.23
221
+ rubygems_version: 1.6.2
216
222
  signing_key:
217
223
  specification_version: 3
218
224
  summary: Ruby gem for Vero
219
- test_files:
225
+ test_files:
226
+ - spec/lib/api/base_api_spec.rb
220
227
  - spec/lib/api/events/track_api_spec.rb
221
228
  - spec/lib/api/users/edit_api_spec.rb
222
229
  - spec/lib/api/users/edit_tags_api_spec.rb