vero 0.4.3 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vero (0.4.2)
5
- delayed_job
6
- delayed_job_active_record
4
+ vero (0.4.5)
7
5
  girl_friday
8
6
  rest-client
9
7
 
@@ -114,6 +112,8 @@ PLATFORMS
114
112
  ruby
115
113
 
116
114
  DEPENDENCIES
115
+ delayed_job
116
+ delayed_job_active_record
117
117
  rails
118
118
  rspec
119
119
  vero!
@@ -43,6 +43,14 @@ module Vero
43
43
 
44
44
  def request
45
45
  end
46
+
47
+ def request_content_type
48
+ {:content_type => :json, :accept => :json}
49
+ end
50
+
51
+ def request_params_as_json
52
+ @options.to_json
53
+ end
46
54
  end
47
55
  end
48
56
  end
@@ -7,7 +7,7 @@ module Vero
7
7
  end
8
8
 
9
9
  def request
10
- RestClient.post(self.url, @options)
10
+ RestClient.post(self.url, self.request_params_as_json, self.request_content_type)
11
11
  end
12
12
 
13
13
  def validate!
@@ -7,7 +7,7 @@ module Vero
7
7
  end
8
8
 
9
9
  def request
10
- RestClient.put(url, @options)
10
+ RestClient.put(url, self.request_params_as_json, self.request_content_type)
11
11
  end
12
12
 
13
13
  def validate!
@@ -7,7 +7,7 @@ module Vero
7
7
  end
8
8
 
9
9
  def request
10
- RestClient.put(url, @options)
10
+ RestClient.put(url, self.request_params_as_json, self.request_content_type)
11
11
  end
12
12
 
13
13
  def validate!
@@ -7,7 +7,7 @@ module Vero
7
7
  end
8
8
 
9
9
  def request
10
- RestClient.post(url, @options)
10
+ RestClient.post(url, self.request_params_as_json, self.request_content_type)
11
11
  end
12
12
 
13
13
  def validate!
@@ -1,14 +1,26 @@
1
1
  module Vero
2
+ class SenderHash < ::Hash
3
+ def [](key)
4
+ if self.has_key?(key)
5
+ super
6
+ else
7
+ klass_name = key.to_s.split("_").map(&:capitalize).join
8
+ eval("Vero::Senders::#{klass_name}")
9
+ end
10
+ end
11
+ end
12
+
2
13
  class Sender
3
14
  def self.senders
4
15
  @senders ||= begin
5
- t = {
16
+ t = Vero::SenderHash.new
17
+
18
+ t.merge!({
6
19
  true => Vero::Senders::Invalid,
7
20
  false => Vero::Senders::Base,
8
21
  :none => Vero::Senders::Base,
9
- :thread => Vero::Senders::Invalid,
10
- :delayed_job => Vero::Senders::DelayedJob
11
- }
22
+ :thread => Vero::Senders::Invalid
23
+ })
12
24
 
13
25
  if RUBY_VERSION =~ /1\.9\./
14
26
  t.merge!(
@@ -7,7 +7,7 @@ module Vero
7
7
 
8
8
  module ClassMethods
9
9
  def log(object, message)
10
- return unless Vero::App.default_context.config.logging
10
+ return unless Vero::App.default_context.config.logging && !defined?(RSpec)
11
11
 
12
12
  message = "#{object.class.name}: #{message}"
13
13
 
@@ -1,3 +1,3 @@
1
1
  module Vero
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.5'
3
3
  end
@@ -1,54 +1,61 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Vero::API::Events::TrackAPI do
4
- subject { Vero::API::Events::TrackAPI.new('https://www.getvero.com', {}) }
5
- it "should inherit from Vero::API::BaseCaller" do
6
- subject.should be_a(Vero::API::BaseAPI)
7
- end
8
-
9
- it "should map to current version of Vero API" do
10
- subject.send(:url).should == "https://www.getvero.com/api/v2/events/track.json"
11
- end
12
4
 
13
- subject { Vero::API::Events::TrackAPI.new('https://www.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
14
- describe :validate! do
15
- it "should raise an error if test_event is a blank String" do
16
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => nil}
17
- subject.options = options
18
- expect { subject.send(:validate!) }.to raise_error(ArgumentError)
19
-
20
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}
21
- subject.options = options
22
- expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
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)
23
9
  end
24
10
 
25
- it "should raise an error if data is not either nil or a Hash" do
26
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => []}
27
- subject.options = options
28
- expect { subject.send(:validate!) }.to raise_error(ArgumentError)
29
-
30
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => nil}
31
- subject.options = options
32
- expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
33
-
34
- options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => {}}
35
- subject.options = options
36
- expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
11
+ it "should map to current version of Vero API" do
12
+ subject.send(:url).should == "https://www.getvero.com/api/v2/events/track.json"
37
13
  end
38
14
  end
39
-
40
- describe :request do
41
- it "should send a request to the Vero API" do
42
- RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/events/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'})
43
- RestClient.stub(:post).and_return(200)
44
- subject.send(:request)
15
+
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'}) }
18
+ describe :validate! do
19
+ it "should raise an error if test_event is a blank String" do
20
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => nil}
21
+ subject.options = options
22
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
23
+
24
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}
25
+ subject.options = options
26
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
27
+ end
28
+
29
+ it "should raise an error if data is not either nil or a Hash" do
30
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => []}
31
+ subject.options = options
32
+ expect { subject.send(:validate!) }.to raise_error(ArgumentError)
33
+
34
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => nil}
35
+ subject.options = options
36
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
37
+
38
+ options = {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event', :data => {}}
39
+ subject.options = options
40
+ expect { subject.send(:validate!) }.to_not raise_error(ArgumentError)
41
+ end
42
+ end
43
+
44
+ describe :request do
45
+ it "should send a JSON request to the Vero API" do
46
+ RestClient.should_receive(:post).with("https://www.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})
47
+ RestClient.stub(:post).and_return(200)
48
+ subject.send(:request)
49
+ end
45
50
  end
46
51
  end
47
52
 
48
53
  describe "integration test" do
49
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'})
56
+
50
57
  RestClient.stub(:post).and_return(200)
51
- expect { subject.perform }.to_not raise_error
58
+ expect { obj.perform }.to_not raise_error
52
59
  end
53
60
  end
54
61
  end
@@ -16,7 +16,7 @@ describe Vero::API::Users::EditAPI do
16
16
 
17
17
  describe :request do
18
18
  it "should send a request to the Vero API" do
19
- RestClient.should_receive(:put).with("https://www.getvero.com/api/v2/users/edit.json", {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }})
19
+ RestClient.should_receive(:put).with("https://www.getvero.com/api/v2/users/edit.json", {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}.to_json, {:content_type => :json, :accept => :json})
20
20
  RestClient.stub(:put).and_return(200)
21
21
  subject.send(:request)
22
22
  end
@@ -16,7 +16,7 @@ describe Vero::API::Users::EditTagsAPI do
16
16
 
17
17
  describe :request do
18
18
  it "should send a request to the Vero API" do
19
- RestClient.should_receive(:put).with("https://www.getvero.com/api/v2/users/tags/edit.json", {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]})
19
+ RestClient.should_receive(:put).with("https://www.getvero.com/api/v2/users/tags/edit.json", {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}.to_json, {:content_type => :json, :accept => :json})
20
20
  RestClient.stub(:put).and_return(200)
21
21
  subject.send(:request)
22
22
  end
@@ -39,7 +39,7 @@ describe Vero::API::Users::TrackAPI do
39
39
 
40
40
  describe :request do
41
41
  it "should send a request to the Vero API" do
42
- RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/users/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'})
42
+ RestClient.should_receive(:post).with("https://www.getvero.com/api/v2/users/track.json", {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}.to_json, {:content_type => :json, :accept => :json})
43
43
  RestClient.stub(:post).and_return(200)
44
44
  subject.send(:request)
45
45
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::Sender do
4
+ subject { Vero::Sender }
5
+ describe "self.senders" do
6
+ it "should be a Hash" do
7
+ subject.senders.should be_a(Hash)
8
+ end
9
+
10
+ # context "< Ruby 1.9" do
11
+ # before :all do
12
+ # Object.const_set :RUBY_VERSION, "1.8.7"
13
+ # end
14
+
15
+ # it "should have a default set of senders (true, false, none, thread)" do
16
+ # subject.senders.should == {
17
+ # true => Vero::Senders::Invalid,
18
+ # false => Vero::Senders::Base,
19
+ # :none => Vero::Senders::Base,
20
+ # :thread => Vero::Senders::Invalid,
21
+ # }
22
+ # end
23
+ # end
24
+
25
+ context "~> Ruby 1.9" do
26
+ # before :all do
27
+ # Object.const_set :RUBY_VERSION, "1.9.3"
28
+ # end
29
+
30
+ it "should have a default set of senders (true, false, none, thread)" do
31
+ subject.senders.should == {
32
+ true => Vero::Senders::Thread,
33
+ false => Vero::Senders::Base,
34
+ :none => Vero::Senders::Base,
35
+ :thread => Vero::Senders::Thread,
36
+ }
37
+ end
38
+ end
39
+
40
+ it "should automatically find senders that are not defined" do
41
+ subject.senders[:delayed_job].should == Vero::Senders::DelayedJob
42
+ subject.senders[:invalid].should == Vero::Senders::Invalid
43
+ subject.senders[:none].should == Vero::Senders::Base
44
+ end
45
+ end
46
+ end
@@ -11,6 +11,8 @@ describe Vero::Trackable do
11
11
  }
12
12
  @url = "https://www.getvero.com/api/v1/track.json"
13
13
  @user = User.new
14
+
15
+ @content_type_params = {:content_type => :json, :accept => :json}
14
16
  end
15
17
 
16
18
  context "the gem has not been configured" do
@@ -68,10 +70,10 @@ describe Vero::Trackable do
68
70
 
69
71
  RestClient.stub(:post).and_return(200)
70
72
 
71
- 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"}})
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)
72
74
  @user.track!(@request_params[:event_name], @request_params[:data]).should == 200
73
75
 
74
- 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"}})
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)
75
77
  @user.track!(@request_params[:event_name]).should == 200
76
78
  end
77
79
 
@@ -106,9 +108,9 @@ describe Vero::Trackable do
106
108
  before do
107
109
  @request_params = {
108
110
  :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
109
- :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
110
111
  :development_mode => true,
111
- :email => 'durkster@gmail.com'
112
+ :email => 'durkster@gmail.com',
113
+ :data => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
112
114
  }
113
115
  @url = "https://www.getvero.com/api/v2/users/track.json"
114
116
  end
@@ -120,7 +122,7 @@ describe Vero::Trackable do
120
122
  @user.stub(:with_vero_context).and_return(context)
121
123
 
122
124
  RestClient.stub(:post).and_return(200)
123
- RestClient.should_receive(:post).with(@url, @request_params)
125
+ RestClient.should_receive(:post).with(@url, @request_params.to_json, @content_type_params)
124
126
 
125
127
  @user.identify!.should == 200
126
128
  end
@@ -144,9 +146,9 @@ describe Vero::Trackable do
144
146
  before do
145
147
  @request_params = {
146
148
  :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
147
- :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"},
149
+ :development_mode => true,
148
150
  :email => 'durkster@gmail.com',
149
- :development_mode => true
151
+ :changes => {:email => 'durkster@gmail.com', :age => 20, :_user_type => "User"}
150
152
  }
151
153
  @url = "https://www.getvero.com/api/v2/users/edit.json"
152
154
  end
@@ -158,7 +160,7 @@ describe Vero::Trackable do
158
160
  @user.stub(:with_vero_context).and_return(context)
159
161
 
160
162
  RestClient.stub(:put).and_return(200)
161
- RestClient.should_receive(:put).with(@url, @request_params.merge(:email => "durkster1@gmail.com"))
163
+ RestClient.should_receive(:put).with(@url, @request_params.merge(:email => "durkster1@gmail.com").to_json, @content_type_params)
162
164
 
163
165
  @user.with_vero_context.update_user!("durkster1@gmail.com").should == 200
164
166
  end
@@ -170,7 +172,7 @@ describe Vero::Trackable do
170
172
  @user.stub(:with_vero_context).and_return(context)
171
173
 
172
174
  RestClient.stub(:put).and_return(200)
173
- RestClient.should_receive(:put).with(@url, @request_params)
175
+ RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
174
176
 
175
177
  @user.with_vero_context.update_user!.should == 200
176
178
  end
@@ -194,10 +196,10 @@ describe Vero::Trackable do
194
196
  before do
195
197
  @request_params = {
196
198
  :auth_token => 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
197
- :add => [],
198
- :remove => [],
199
+ :development_mode => true,
199
200
  :email => 'durkster@gmail.com',
200
- :development_mode => true
201
+ :add => [],
202
+ :remove => []
201
203
  }
202
204
  @url = "https://www.getvero.com/api/v2/users/tags/edit.json"
203
205
  end
@@ -210,7 +212,7 @@ describe Vero::Trackable do
210
212
  @user.stub(:with_vero_context).and_return(context)
211
213
 
212
214
  RestClient.stub(:put).and_return(200)
213
- RestClient.should_receive(:put).with(@url, @request_params)
215
+ RestClient.should_receive(:put).with(@url, @request_params.to_json, @content_type_params)
214
216
 
215
217
  @user.with_vero_context.update_user_tags!.should == 200
216
218
  end
@@ -1,8 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
-
4
3
  require 'vero'
5
- # require 'debugger'
6
4
 
7
5
  Dir[::File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
8
6
 
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
15
15
  dependencies = [
16
16
  [:development, 'rails'],
17
17
  [:development, 'rspec'],
18
+ [:development, 'delayed_job'],
19
+ [:development, 'delayed_job_active_record'],
18
20
  [:runtime, 'rest-client'],
19
- [:runtime, 'delayed_job'],
20
- [:runtime, 'delayed_job_active_record'],
21
21
  [:runtime, 'girl_friday']
22
22
  ]
23
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-09 00:00:00.000000000 Z
12
+ date: 2013-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rest-client
47
+ name: delayed_job
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :runtime
54
+ type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
@@ -60,14 +60,14 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: delayed_job
63
+ name: delayed_job_active_record
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
- type: :runtime
70
+ type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: delayed_job_active_record
79
+ name: rest-client
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -149,6 +149,7 @@ files:
149
149
  - spec/lib/app_spec.rb
150
150
  - spec/lib/config_spec.rb
151
151
  - spec/lib/context_spec.rb
152
+ - spec/lib/sender_spec.rb
152
153
  - spec/lib/trackable_spec.rb
153
154
  - spec/lib/view_helpers_spec.rb
154
155
  - spec/spec_helper.rb
@@ -188,6 +189,7 @@ test_files:
188
189
  - spec/lib/app_spec.rb
189
190
  - spec/lib/config_spec.rb
190
191
  - spec/lib/context_spec.rb
192
+ - spec/lib/sender_spec.rb
191
193
  - spec/lib/trackable_spec.rb
192
194
  - spec/lib/view_helpers_spec.rb
193
195
  - spec/spec_helper.rb