vero 0.0.4

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 ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+ gem 'rails'
5
+ gem 'debugger', :require => 'debugger'
6
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,116 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vero (0.0.4)
5
+ delayed_job
6
+ rest-client
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.5)
12
+ actionpack (= 3.2.5)
13
+ mail (~> 2.4.4)
14
+ actionpack (3.2.5)
15
+ activemodel (= 3.2.5)
16
+ activesupport (= 3.2.5)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.1)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.3)
24
+ activemodel (3.2.5)
25
+ activesupport (= 3.2.5)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.5)
28
+ activemodel (= 3.2.5)
29
+ activesupport (= 3.2.5)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.5)
33
+ activemodel (= 3.2.5)
34
+ activesupport (= 3.2.5)
35
+ activesupport (3.2.5)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.2)
39
+ builder (3.0.0)
40
+ columnize (0.3.6)
41
+ debugger (1.1.3)
42
+ columnize (>= 0.3.1)
43
+ debugger-linecache (~> 1.1.1)
44
+ debugger-ruby_core_source (~> 1.1.2)
45
+ debugger-linecache (1.1.1)
46
+ debugger-ruby_core_source (>= 1.1.1)
47
+ debugger-ruby_core_source (1.1.3)
48
+ delayed_job (3.0.3)
49
+ activesupport (~> 3.0)
50
+ diff-lcs (1.1.3)
51
+ erubis (2.7.0)
52
+ hike (1.2.1)
53
+ i18n (0.6.0)
54
+ journey (1.0.3)
55
+ json (1.7.3)
56
+ mail (2.4.4)
57
+ i18n (>= 0.4.0)
58
+ mime-types (~> 1.16)
59
+ treetop (~> 1.4.8)
60
+ mime-types (1.18)
61
+ multi_json (1.3.6)
62
+ polyglot (0.3.3)
63
+ rack (1.4.1)
64
+ rack-cache (1.2)
65
+ rack (>= 0.4)
66
+ rack-ssl (1.3.2)
67
+ rack
68
+ rack-test (0.6.1)
69
+ rack (>= 1.0)
70
+ rails (3.2.5)
71
+ actionmailer (= 3.2.5)
72
+ actionpack (= 3.2.5)
73
+ activerecord (= 3.2.5)
74
+ activeresource (= 3.2.5)
75
+ activesupport (= 3.2.5)
76
+ bundler (~> 1.0)
77
+ railties (= 3.2.5)
78
+ railties (3.2.5)
79
+ actionpack (= 3.2.5)
80
+ activesupport (= 3.2.5)
81
+ rack-ssl (~> 1.3.2)
82
+ rake (>= 0.8.7)
83
+ rdoc (~> 3.4)
84
+ thor (>= 0.14.6, < 2.0)
85
+ rake (0.9.2.2)
86
+ rdoc (3.12)
87
+ json (~> 1.4)
88
+ rest-client (1.6.7)
89
+ mime-types (>= 1.16)
90
+ rspec (2.10.0)
91
+ rspec-core (~> 2.10.0)
92
+ rspec-expectations (~> 2.10.0)
93
+ rspec-mocks (~> 2.10.0)
94
+ rspec-core (2.10.1)
95
+ rspec-expectations (2.10.0)
96
+ diff-lcs (~> 1.1.3)
97
+ rspec-mocks (2.10.1)
98
+ sprockets (2.1.3)
99
+ hike (~> 1.2)
100
+ rack (~> 1.0)
101
+ tilt (~> 1.1, != 1.3.0)
102
+ thor (0.15.2)
103
+ tilt (1.3.3)
104
+ treetop (1.4.10)
105
+ polyglot
106
+ polyglot (>= 0.3.1)
107
+ tzinfo (0.3.33)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ debugger
114
+ rails
115
+ rspec
116
+ vero!
data/README.markdown ADDED
@@ -0,0 +1,113 @@
1
+ # vero
2
+
3
+ vero makes it easy to interact with Vero's REST API from your Rails 3.x 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. For more information about the platform, visit [Vero](http://getvero.com).
4
+
5
+ ## Installation
6
+
7
+ Include in your Gemfile:
8
+
9
+ gem 'vero'
10
+
11
+ Or install the gem:
12
+
13
+ gem install 'vero'
14
+
15
+ Create a [Vero account](http://getvero.com). Create an initializer in your config folder called vero.rb with the following:
16
+
17
+ # config/initializers/vero.rb
18
+ Vero::App.init do |config|
19
+ config.api_key = "Your API key goes here"
20
+ config.secret = "Your API secret goes here"
21
+ end
22
+
23
+ You will be able to find your API key and secret by logging into Vero and clicking the 'Account' button at the top of the page.
24
+
25
+ ## Setup tracking
26
+
27
+ You will need to define who should be tracked and what information about them you'd like to send to Vero. In this example we'll track users:
28
+
29
+ # app/models/user.rb
30
+ class User < ActiveRecord::Base
31
+ include Vero::Trackable
32
+ trackable :email, :name, :age
33
+
34
+ ...
35
+ end
36
+
37
+ As you can see we're saying that a User is trackable and that we'd like to pass up their email address, name and age.
38
+
39
+ Each symbol passed to trackable should reference either an instance method or an ActiveRecord field. Therefore it's perfectly legal to do something like:
40
+
41
+ # app/models/user.rb
42
+ class User < ActiveRecord::Base
43
+ include Vero::Trackable
44
+ trackable :email, :contest_count
45
+
46
+ has_many :contests
47
+
48
+ def contest_count
49
+ self.contests.count
50
+ end
51
+ end
52
+
53
+ __NOTE: 'email' is a required field__.
54
+
55
+ If the user's email address is stored in a different field, you can do the following:
56
+
57
+ # app/models/user.rb
58
+ class User < ActiveRecord::Base
59
+ include Vero::Trackable
60
+ trackable :email
61
+
62
+ def email; self.email_address; end
63
+ end
64
+
65
+ ## Sending events
66
+
67
+ To send an event, call the #track instance method on a model that is trackable. If you're using Devise you can do the following:
68
+
69
+ # app/controllers/contests_controller.rb
70
+ class ContestsController < ActionController::Base
71
+ before_filter :authenticate_user!
72
+ ...
73
+
74
+
75
+ def create
76
+ @contest = current_user.contests.build(params[:contest])
77
+
78
+ if @contest.save
79
+ # Tell Vero that a new contest has been created
80
+ current_user.track('new_contest_created')
81
+
82
+ flash[:notice] = "New contest saved successfully!"
83
+ redirect_to contests_path
84
+ else
85
+ flash[:alert] = "Unable to create your contest. Please review your details and try again."
86
+ render 'new'
87
+ end
88
+ end
89
+ end
90
+
91
+ You may want to send additional data about the event:
92
+
93
+ # app/controllers/contests_controller.rb
94
+ class ContestsController < ActionController::Base
95
+ before_filter :authenticate_user!
96
+ ...
97
+
98
+
99
+ def create
100
+ @contest = current_user.contests.build(params[:contest])
101
+
102
+ if @contest.save
103
+ # Tell Vero that a new contest has been created, and the id and name
104
+ current_user.track('new_contest_created', {id: @contest.id, name: @content.name})
105
+
106
+ flash[:notice] = "New contest saved successfully!"
107
+ redirect_to contests_path
108
+ else
109
+ flash[:alert] = "Unable to create your contest. Please review your details and try again."
110
+ render 'new'
111
+ end
112
+ end
113
+ end
data/lib/vero/app.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Vero
2
+ class App
3
+ @@config = nil
4
+
5
+ def self.init(&block)
6
+ @@config = Config.new
7
+
8
+ if block_given?
9
+ block.call self.config
10
+ @@config.configured = true
11
+ end
12
+ end
13
+
14
+ def self.config
15
+ @@config
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ module Vero
2
+ class Config
3
+ attr_writer :domain
4
+ attr_accessor :api_key, :secret, :development_mode, :async, :configured
5
+
6
+ def initialize
7
+ self.configured = false
8
+ self.development_mode = Rails.env.development?
9
+ self.async = true
10
+ end
11
+
12
+ def request_params
13
+ temp = {}
14
+
15
+ temp_auth_token = self.auth_token
16
+ temp[:auth_token] = temp_auth_token unless temp_auth_token.nil?
17
+ temp[:development_mode] = self.development? unless self.development_mode.nil?
18
+
19
+ temp
20
+ end
21
+
22
+ def domain
23
+ @domain || 'www.getvero.com'
24
+ end
25
+
26
+ def auth_token
27
+ return if api_key.blank? || secret.blank?
28
+
29
+ Base64::encode64("#{api_key}:#{secret}").gsub(/[\n ]/, '')
30
+ end
31
+
32
+ def development?
33
+ self.development_mode || !Rails.env.production?
34
+ end
35
+
36
+ def configured?
37
+ self.configured
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ require 'rest-client'
2
+
3
+ module Vero
4
+ module Jobs
5
+ class RestPostJob < Struct.new(:url, :params)
6
+ def perform
7
+ RestClient.post(url, params)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ require 'delayed_job'
2
+ require 'vero/jobs/rest_post_job'
3
+
4
+ module Vero
5
+ module Trackable
6
+ def self.included(base)
7
+ @@vero_trackable_map = []
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def trackable(*args)
13
+ @@vero_trackable_map = args
14
+ end
15
+
16
+ def trackable_map
17
+ @@vero_trackable_map
18
+ end
19
+ end
20
+
21
+ def to_vero
22
+ self.class.trackable_map.inject({}) do |hash, symbol|
23
+ hash[symbol] = self.send(symbol)
24
+ hash
25
+ end
26
+ end
27
+
28
+ def track(event_name, event_data = {}, cta = '')
29
+ validate_track_params!(event_name, event_data, cta)
30
+
31
+ config = Vero::App.config
32
+ request_params = config.request_params
33
+ request_params.merge!(event_name: event_name, identity: self.to_vero, data: event_data, cta: cta)
34
+
35
+ method = !config.async ? :post_now : :post_later
36
+ self.send(method, "http://#{config.domain}/api/v1/track.json", request_params)
37
+ end
38
+
39
+ private
40
+ def post_now(url, params)
41
+ job = Vero::Jobs::RestPostJob.new(url, params)
42
+ job.perform
43
+ end
44
+
45
+ def post_later(url, params)
46
+ job = Vero::Jobs::RestPostJob.new(url, params)
47
+ ::Delayed::Job.enqueue job
48
+ 'success'
49
+ end
50
+
51
+ def validate_track_params!(event_name, event_data, cta)
52
+ result = true
53
+
54
+ result &&= event_name.kind_of?(String) && !event_name.blank?
55
+ result &&= event_data.nil? || event_data.kind_of?(Hash)
56
+ result &&= cta.nil? || cta.kind_of?(String)
57
+
58
+ raise ArgumentError.new({event_name: event_name, event_data: event_data, cta: cta}) unless result
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Vero
2
+ VERSION = '0.0.4'
3
+ end
data/lib/vero.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+
3
+ module Vero
4
+ autoload :Session, 'vero/session'
5
+ autoload :Config, 'vero/config'
6
+ autoload :App, 'vero/app'
7
+ autoload :Trackable, 'vero/trackable'
8
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::App do
4
+ describe "#init" do
5
+ it "should create a Config object" do
6
+ Vero::App.config.should be_nil
7
+ Vero::App.init {}
8
+ Vero::App.config.should_not be_nil
9
+ end
10
+
11
+ it "should ignore configuring the config if no block is provided" do
12
+ Vero::App.init
13
+ Vero::App.config.configured?.should be_false
14
+ end
15
+
16
+ it "should pass configuration defined in the block to the config file" do
17
+ Vero::App.init
18
+
19
+ Vero::App.config.api_key.should be_nil
20
+ Vero::App.init do |c|
21
+ c.api_key = "abcd1234"
22
+ end
23
+ Vero::App.config.api_key.should == "abcd1234"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::Config do
4
+ before :each do
5
+ @config = Vero::Config.new
6
+ end
7
+
8
+ it "should be async by default" do
9
+ @config.async.should be_true
10
+ end
11
+
12
+ describe "#auth_token" do
13
+ it "should return nil if either api_key or secret are not set" do
14
+ @config.api_key = nil
15
+ @config.secret = "abcd"
16
+ @config.auth_token.should be_nil
17
+
18
+ @config.api_key = "abcd"
19
+ @config.secret = nil
20
+ @config.auth_token.should be_nil
21
+
22
+ @config.api_key = "abcd"
23
+ @config.secret = "abcd"
24
+ @config.auth_token.should_not be_nil
25
+ end
26
+
27
+ it "should return an expected auth_token" do
28
+ @config.api_key = "abcd1234"
29
+ @config.secret = "efgh5678"
30
+ @config.auth_token.should == "YWJjZDEyMzQ6ZWZnaDU2Nzg="
31
+ end
32
+ end
33
+
34
+ describe "#request_params" do
35
+ it "should return a hash of auth_token and development_mode if they are set" do
36
+ @config.api_key = nil
37
+ @config.secret = nil
38
+ @config.development_mode = nil
39
+ @config.request_params.should == {}
40
+
41
+ @config.api_key = "abcd1234"
42
+ @config.secret = "abcd1234"
43
+ @config.request_params.should == {auth_token: "YWJjZDEyMzQ6YWJjZDEyMzQ="}
44
+
45
+ @config.development_mode = true
46
+ @config.request_params.should == {auth_token: "YWJjZDEyMzQ6YWJjZDEyMzQ=", development_mode: true}
47
+ end
48
+ end
49
+
50
+ describe "#domain" do
51
+ it "should return www.getvero.com when not set" do
52
+ @config.domain.should == 'www.getvero.com'
53
+ @config.domain = 'blah.com'
54
+ @config.domain.should_not == 'www.getvero.com'
55
+ end
56
+
57
+ it "should return the domain value" do
58
+ @config.domain = 'test.unbelieveable.com.au'
59
+ @config.domain.should == 'test.unbelieveable.com.au'
60
+ end
61
+ end
62
+
63
+ describe "#development?" do
64
+ it "should return the value set in development_mode" do
65
+ @config.development_mode = true
66
+ @config.development?.should be_true
67
+ end
68
+
69
+ it "should return true when development_mode is false but Rails.env is either development or test" do
70
+ @config.development_mode = false
71
+
72
+ stub_env('development') {
73
+ @config.development?.should be_true
74
+ }
75
+
76
+ stub_env('test') {
77
+ @config.development?.should be_true
78
+ }
79
+
80
+ stub_env('production') {
81
+ @config.development?.should be_false
82
+ }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vero::Trackable do
4
+ before :each do
5
+ Vero::App.init do |c|
6
+ c.api_key = 'abcd1234'
7
+ c.secret = 'efgh5678'
8
+ c.async = false
9
+ end
10
+ @user = User.new
11
+ end
12
+
13
+ describe "#track" do
14
+ before :each do
15
+ @request_params = {
16
+ event_name: 'test_event',
17
+ auth_token: 'YWJjZDEyMzQ6ZWZnaDU2Nzg=',
18
+ identity: {email: 'durkster@gmail.com', age: 20},
19
+ data: { test: 1 },
20
+ cta: 'test',
21
+ development_mode: true
22
+ }
23
+ @url = "http://www.getvero.com/api/v1/track.json"
24
+ end
25
+
26
+ it "should send a track request when async is set to false" do
27
+ @user.stub(:post_now).and_return(200)
28
+ @user.should_receive(:post_now).with(@url, @request_params).at_least(:once)
29
+ @user.track(@request_params[:event_name], @request_params[:data], 'test').should == 200
30
+ @user.track(@request_params[:event_name]).should == 200
31
+ end
32
+
33
+ it "should create a delayed job when async is set to true" do
34
+ @user.stub(:post_later).and_return('success')
35
+ @user.should_receive(:post_later).with(@url, @request_params).at_least(:once)
36
+
37
+ Vero::App.config.async = true
38
+ @user.track(@request_params[:event_name], @request_params[:data], 'test').should == 'success'
39
+ @user.track(@request_params[:event_name]).should == 'success'
40
+ end
41
+
42
+ it "should not send a track request when the required parameters are invalid" do
43
+ @user.stub(:post_now).and_return(200)
44
+
45
+ expect { @user.track(nil) }.to raise_error
46
+ expect { @user.track('') }.to raise_error
47
+ expect { @user.track('test', '') }.to raise_error
48
+ expect { @user.track('test', {}, 8) }.to raise_error
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'vero'
5
+ require 'debugger'
6
+
7
+ Dir[::File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ end
11
+
12
+ def stub_env(new_env, &block)
13
+ original_env = Rails.env
14
+ Rails.instance_variable_set("@_env", ActiveSupport::StringInquirer.new(new_env))
15
+ block.call
16
+ ensure
17
+ Rails.instance_variable_set("@_env", ActiveSupport::StringInquirer.new(original_env))
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'vero'
2
+
3
+ class User
4
+ include Vero::Trackable
5
+ trackable :email, :age
6
+
7
+ def email
8
+ 'durkster@gmail.com'
9
+ end
10
+
11
+ def age
12
+ 20
13
+ end
14
+ end
data/vero.gemspec ADDED
@@ -0,0 +1,38 @@
1
+
2
+ # -*- encoding: utf-8 -*-
3
+ $:.push('lib')
4
+ require "vero/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "vero"
8
+ s.version = Vero::VERSION.dup
9
+ s.date = "2012-06-03"
10
+ s.summary = "Rails 3.x gem for Vero"
11
+ s.email = "support@getvero.com"
12
+ s.homepage = "http://getvero.com/"
13
+ s.authors = ['James Lamont']
14
+
15
+ dependencies = [
16
+ [:runtime, 'rest-client'],
17
+ [:runtime, 'delayed_job']
18
+ ]
19
+
20
+ s.files = Dir['**/*']
21
+ s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
22
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+
26
+ ## Make sure you can build the gem on older versions of RubyGems too:
27
+ s.rubygems_version = "1.8.23"
28
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
29
+ s.specification_version = 3 if s.respond_to? :specification_version
30
+
31
+ dependencies.each do |type, name, version|
32
+ if s.respond_to?("add_#{type}_dependency")
33
+ s.send("add_#{type}_dependency", name, version)
34
+ else
35
+ s.add_dependency(name, version)
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vero
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Lamont
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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: delayed_job
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email: support@getvero.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - lib/vero/app.rb
55
+ - lib/vero/config.rb
56
+ - lib/vero/jobs/rest_post_job.rb
57
+ - lib/vero/trackable.rb
58
+ - lib/vero/version.rb
59
+ - lib/vero.rb
60
+ - README.markdown
61
+ - spec/lib/app_spec.rb
62
+ - spec/lib/config_spec.rb
63
+ - spec/lib/trackable_spec.rb
64
+ - spec/spec_helper.rb
65
+ - spec/support/user_support.rb
66
+ - vero.gemspec
67
+ homepage: http://getvero.com/
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.23
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Rails 3.x gem for Vero
91
+ test_files:
92
+ - spec/lib/app_spec.rb
93
+ - spec/lib/config_spec.rb
94
+ - spec/lib/trackable_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/support/user_support.rb