vero 0.9.1 → 0.10.0
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.
- checksums.yaml +4 -4
- data/Gemfile +15 -1
- data/Gemfile.lock +95 -73
- data/README.markdown +145 -121
- data/lib/generators/vero_generator.rb +18 -19
- data/lib/vero.rb +7 -3
- data/lib/vero/api.rb +14 -4
- data/lib/vero/api/base_api.rb +11 -10
- data/lib/vero/api/events/track_api.rb +5 -3
- data/lib/vero/api/users/delete_api.rb +21 -0
- data/lib/vero/api/users/edit_api.rb +5 -3
- data/lib/vero/api/users/edit_tags_api.rb +7 -5
- data/lib/vero/api/users/reidentify_api.rb +5 -3
- data/lib/vero/api/users/resubscribe_api.rb +3 -1
- data/lib/vero/api/users/track_api.rb +5 -3
- data/lib/vero/api/users/unsubscribe_api.rb +3 -1
- data/lib/vero/app.rb +4 -2
- data/lib/vero/config.rb +11 -8
- data/lib/vero/context.rb +9 -11
- data/lib/vero/context/api.rb +9 -7
- data/lib/vero/dsl.rb +3 -1
- data/lib/vero/railtie.rb +5 -3
- data/lib/vero/sender.rb +12 -31
- data/lib/vero/senders/base.rb +3 -1
- data/lib/vero/senders/delayed_job.rb +7 -7
- data/lib/vero/senders/invalid.rb +5 -3
- data/lib/vero/senders/resque.rb +8 -8
- data/lib/vero/senders/sidekiq.rb +3 -1
- data/lib/vero/senders/{thread.rb → sucker_punch.rb} +5 -3
- data/lib/vero/trackable.rb +4 -2
- data/lib/vero/trackable/base.rb +10 -9
- data/lib/vero/trackable/interface.rb +3 -1
- data/lib/vero/utility/ext.rb +3 -1
- data/lib/vero/utility/logger.rb +4 -6
- data/lib/vero/version.rb +3 -1
- data/lib/vero/view_helpers/javascript.rb +20 -20
- data/spec/lib/api/base_api_spec.rb +10 -8
- data/spec/lib/api/events/track_api_spec.rb +23 -21
- data/spec/lib/api/users/delete_api_spec.rb +33 -0
- data/spec/lib/api/users/edit_api_spec.rb +12 -10
- data/spec/lib/api/users/edit_tags_api_spec.rb +22 -20
- data/spec/lib/api/users/reidentify_spec.rb +16 -14
- data/spec/lib/api/users/resubscribe_api_spec.rb +16 -10
- data/spec/lib/api/users/track_api_spec.rb +21 -19
- data/spec/lib/api/users/unsubscribe_api_spec.rb +12 -10
- data/spec/lib/api_spec.rb +29 -24
- data/spec/lib/app_spec.rb +12 -10
- data/spec/lib/config_spec.rb +31 -29
- data/spec/lib/context_spec.rb +13 -11
- data/spec/lib/dsl_spec.rb +3 -1
- data/spec/lib/sender_spec.rb +12 -24
- data/spec/lib/senders/sidekiq_spec.rb +16 -9
- data/spec/lib/trackable_spec.rb +88 -114
- data/spec/lib/view_helpers_spec.rb +12 -8
- data/spec/spec_helper.rb +10 -4
- data/spec/support/base_config_shared_examples.rb +5 -3
- data/spec/support/user_support.rb +15 -7
- data/spec/support/vero_user_support.rb +4 -2
- data/vero.gemspec +14 -30
- metadata +30 -125
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class VeroGenerator < Rails::Generators::Base
|
2
4
|
class_option :heroku
|
3
5
|
class_option :api_key
|
@@ -6,30 +8,27 @@ class VeroGenerator < Rails::Generators::Base
|
|
6
8
|
def create_initializer_file
|
7
9
|
type = options[:heroku] || 'standard'
|
8
10
|
|
9
|
-
if options[:heroku].blank? && (options[:api_key].blank? || options[:api_secret].blank?)
|
10
|
-
|
11
|
-
end
|
12
|
-
create_file "config/initializers/vero.rb", self.send("#{type}_initializer_content".to_sym)
|
11
|
+
abort('You must provide an API KEY and API SECRET to proceed.') if options[:heroku].blank? && (options[:api_key].blank? || options[:api_secret].blank?)
|
12
|
+
create_file 'config/initializers/vero.rb', send("#{type}_initializer_content".to_sym)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
|
+
|
16
17
|
def standard_initializer_content
|
17
|
-
|
18
|
-
Vero::App.init do |config|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
END_TEXT
|
23
|
-
text
|
18
|
+
<<~END_TEXT
|
19
|
+
Vero::App.init do |config|
|
20
|
+
config.api_key = '#{options[:api_key]}'
|
21
|
+
config.secret = '#{options[:api_secret]}'
|
22
|
+
end
|
23
|
+
END_TEXT
|
24
24
|
end
|
25
25
|
|
26
26
|
def heroku_initializer_content
|
27
|
-
|
28
|
-
Vero::App.init do |config|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
END_TEXT
|
33
|
-
text
|
27
|
+
<<~END_TEXT
|
28
|
+
Vero::App.init do |config|
|
29
|
+
config.api_key = ENV['VERO_API_KEY']
|
30
|
+
config.secret = ENV['VERO_API_SECRET']
|
31
|
+
end
|
32
|
+
END_TEXT
|
34
33
|
end
|
35
|
-
end
|
34
|
+
end
|
data/lib/vero.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rest-client'
|
2
4
|
require 'vero/utility/ext'
|
3
5
|
|
@@ -9,12 +11,13 @@ module Vero
|
|
9
11
|
autoload :Trackable, 'vero/trackable'
|
10
12
|
autoload :DSL, 'vero/dsl'
|
11
13
|
autoload :Sender, 'vero/sender'
|
14
|
+
autoload :SuckerPunchWorker, 'vero/senders/sucker_punch'
|
12
15
|
autoload :ResqueWorker, 'vero/senders/resque'
|
13
16
|
autoload :SidekiqWorker, 'vero/senders/sidekiq'
|
14
17
|
|
15
18
|
module Api
|
16
19
|
module Workers
|
17
|
-
autoload :BaseAPI,
|
20
|
+
autoload :BaseAPI, 'vero/api/base_api'
|
18
21
|
|
19
22
|
module Events
|
20
23
|
autoload :TrackAPI, 'vero/api/events/track_api'
|
@@ -27,6 +30,7 @@ module Vero
|
|
27
30
|
autoload :UnsubscribeAPI, 'vero/api/users/unsubscribe_api'
|
28
31
|
autoload :ResubscribeAPI, 'vero/api/users/resubscribe_api'
|
29
32
|
autoload :ReidentifyAPI, 'vero/api/users/reidentify_api'
|
33
|
+
autoload :DeleteAPI, 'vero/api/users/delete_api'
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
@@ -40,11 +44,11 @@ module Vero
|
|
40
44
|
autoload :Resque, 'vero/senders/resque'
|
41
45
|
autoload :Sidekiq, 'vero/senders/sidekiq'
|
42
46
|
autoload :Invalid, 'vero/senders/invalid'
|
43
|
-
autoload :
|
47
|
+
autoload :SuckerPunch, 'vero/senders/sucker_punch'
|
44
48
|
end
|
45
49
|
|
46
50
|
module Utility
|
47
|
-
autoload :Logger,
|
51
|
+
autoload :Logger, 'vero/utility/logger'
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
data/lib/vero/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
class Base
|
@@ -8,21 +10,21 @@ module Vero
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def config
|
11
|
-
|
13
|
+
context.config
|
12
14
|
end
|
13
15
|
|
14
16
|
def run_api(api_klass, options)
|
15
17
|
return if config.disabled
|
18
|
+
|
16
19
|
validate_configured!
|
17
20
|
options.merge!(config.request_params)
|
18
21
|
Vero::Sender.send(api_klass, config.async, config.domain, options)
|
19
22
|
end
|
20
23
|
|
21
24
|
protected
|
25
|
+
|
22
26
|
def validate_configured!
|
23
|
-
unless config.configured?
|
24
|
-
raise "You must configure the 'vero' gem. Visit https://github.com/getvero/vero for more details."
|
25
|
-
end
|
27
|
+
raise "You must configure the 'vero' gem. Visit https://github.com/getvero/vero for more details." unless config.configured?
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -61,6 +63,10 @@ module Vero
|
|
61
63
|
new(context).resubscribe!(options)
|
62
64
|
end
|
63
65
|
|
66
|
+
def self.delete!(options, context = Vero::App.default_context)
|
67
|
+
new(context).delete!(options)
|
68
|
+
end
|
69
|
+
|
64
70
|
def track!(options)
|
65
71
|
run_api(Vero::Api::Workers::Users::TrackAPI, options)
|
66
72
|
end
|
@@ -84,6 +90,10 @@ module Vero
|
|
84
90
|
def reidentify!(options)
|
85
91
|
run_api(Vero::Api::Workers::Users::ReidentifyAPI, options)
|
86
92
|
end
|
93
|
+
|
94
|
+
def delete!(options)
|
95
|
+
run_api(Vero::Api::Workers::Users::DeleteAPI, options)
|
96
|
+
end
|
87
97
|
end
|
88
98
|
end
|
89
99
|
end
|
data/lib/vero/api/base_api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'rest-client'
|
3
5
|
|
@@ -5,10 +7,11 @@ module Vero
|
|
5
7
|
module Api
|
6
8
|
module Workers
|
7
9
|
class BaseAPI
|
8
|
-
attr_accessor :domain
|
10
|
+
attr_accessor :domain
|
11
|
+
attr_reader :options
|
9
12
|
|
10
13
|
def self.perform(domain, options)
|
11
|
-
caller =
|
14
|
+
caller = new(domain, options)
|
12
15
|
caller.perform
|
13
16
|
end
|
14
17
|
|
@@ -28,6 +31,7 @@ module Vero
|
|
28
31
|
end
|
29
32
|
|
30
33
|
protected
|
34
|
+
|
31
35
|
def setup_logging
|
32
36
|
return unless Vero::App.logger
|
33
37
|
|
@@ -38,18 +42,16 @@ module Vero
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
|
-
def url
|
42
|
-
end
|
45
|
+
def url; end
|
43
46
|
|
44
47
|
def validate!
|
45
48
|
raise "#{self.class.name}#validate! should be overridden"
|
46
49
|
end
|
47
50
|
|
48
|
-
def request
|
49
|
-
end
|
51
|
+
def request; end
|
50
52
|
|
51
53
|
def request_content_type
|
52
|
-
{:
|
54
|
+
{ content_type: :json, accept: :json }
|
53
55
|
end
|
54
56
|
|
55
57
|
def request_params_as_json
|
@@ -57,12 +59,11 @@ module Vero
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def options_with_symbolized_keys(val)
|
60
|
-
val.
|
62
|
+
val.each_with_object({}) do |(k, v), h|
|
61
63
|
h[k.to_sym] = v
|
62
|
-
h
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
68
|
-
end
|
69
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -8,12 +10,12 @@ module Vero
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def request
|
11
|
-
RestClient.post(
|
13
|
+
RestClient.post(url, request_params_as_json, request_content_type)
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
16
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :event_name' if options[:event_name].to_s.blank?
|
18
|
+
raise ArgumentError, ':data must be either nil or a Hash' unless options[:data].nil? || options[:data].is_a?(Hash)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Vero
|
2
|
+
module Api
|
3
|
+
module Workers
|
4
|
+
module Users
|
5
|
+
class DeleteAPI < BaseAPI
|
6
|
+
def url
|
7
|
+
"#{@domain}/api/v2/users/delete.json"
|
8
|
+
end
|
9
|
+
|
10
|
+
def request
|
11
|
+
RestClient.post(url, @options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate!
|
15
|
+
raise ArgumentError.new("Missing :id") if options[:id].to_s.blank?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -8,12 +10,12 @@ module Vero
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def request
|
11
|
-
RestClient.put(url,
|
13
|
+
RestClient.put(url, request_params_as_json, request_content_type)
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
16
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :id or :email' if options[:id].to_s.blank? && options[:email].to_s.blank?
|
18
|
+
raise ArgumentError, ':changes must be a Hash' unless options[:changes].is_a?(Hash)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -8,14 +10,14 @@ module Vero
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def request
|
11
|
-
RestClient.put(url,
|
13
|
+
RestClient.put(url, request_params_as_json, request_content_type)
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
16
|
-
raise ArgumentError
|
17
|
-
raise ArgumentError
|
18
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :id or :email' if options[:id].to_s.blank? && options[:email].to_s.blank?
|
18
|
+
raise ArgumentError, ':add must an Array if present' unless options[:add].nil? || options[:add].is_a?(Array)
|
19
|
+
raise ArgumentError, ':remove must an Array if present' unless options[:remove].nil? || options[:remove].is_a?(Array)
|
20
|
+
raise ArgumentError, 'Either :add or :remove must be present' if options[:remove].nil? && options[:add].nil?
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -8,12 +10,12 @@ module Vero
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def request
|
11
|
-
RestClient.put(url,
|
13
|
+
RestClient.put(url, request_params_as_json, request_content_type)
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
16
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :id' if options[:id].to_s.blank?
|
18
|
+
raise ArgumentError, 'Missing :new_id' if options[:new_id].to_s.blank?
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -12,7 +14,7 @@ module Vero
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :id or :email' if options[:id].to_s.blank? && options[:email].to_s.blank?
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -8,12 +10,12 @@ module Vero
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def request
|
11
|
-
RestClient.post(url,
|
13
|
+
RestClient.post(url, request_params_as_json, request_content_type)
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
16
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :id or :email' if options[:id].to_s.blank? && options[:email].to_s.blank?
|
18
|
+
raise ArgumentError, ':data must be either nil or a Hash' unless options[:data].nil? || options[:data].is_a?(Hash)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
module Api
|
3
5
|
module Workers
|
@@ -12,7 +14,7 @@ module Vero
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def validate!
|
15
|
-
raise ArgumentError
|
17
|
+
raise ArgumentError, 'Missing :id or :email' if options[:id].to_s.blank? && options[:email].to_s.blank?
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/lib/vero/app.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vero
|
2
4
|
class App
|
3
5
|
include Vero::Utility::Logger
|
4
6
|
|
5
7
|
def self.default_context
|
6
|
-
@@default_context ||= Context.new
|
8
|
+
@@default_context ||= Context.new # rubocop:disable Style/ClassVars
|
7
9
|
end
|
8
10
|
|
9
11
|
def self.init(&block)
|
@@ -22,4 +24,4 @@ module Vero
|
|
22
24
|
default_context.configured?
|
23
25
|
end
|
24
26
|
end
|
25
|
-
end
|
27
|
+
end
|
data/lib/vero/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
|
3
5
|
module Vero
|
@@ -6,21 +8,21 @@ module Vero
|
|
6
8
|
attr_accessor :api_key, :secret, :development_mode, :async, :disabled, :logging
|
7
9
|
|
8
10
|
def self.available_attributes
|
9
|
-
[
|
11
|
+
%i[api_key secret development_mode async disabled logging domain]
|
10
12
|
end
|
11
13
|
|
12
14
|
def initialize
|
13
|
-
|
15
|
+
reset!
|
14
16
|
end
|
15
17
|
|
16
18
|
def config_params
|
17
|
-
|
19
|
+
{ api_key: api_key, secret: secret }
|
18
20
|
end
|
19
21
|
|
20
22
|
def request_params
|
21
23
|
{
|
22
|
-
:
|
23
|
-
:
|
24
|
+
auth_token: auth_token,
|
25
|
+
development_mode: development_mode
|
24
26
|
}.reject { |_, v| v.nil? }
|
25
27
|
end
|
26
28
|
|
@@ -28,13 +30,14 @@ module Vero
|
|
28
30
|
if @domain.blank?
|
29
31
|
'https://api.getvero.com'
|
30
32
|
else
|
31
|
-
@domain =~
|
33
|
+
@domain =~ %r{https?://.+} ? @domain : "http://#{@domain}"
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def auth_token
|
36
38
|
return unless auth_token?
|
37
|
-
|
39
|
+
|
40
|
+
::Base64.encode64("#{api_key}:#{secret}").gsub(/[\n ]/, '')
|
38
41
|
end
|
39
42
|
|
40
43
|
def auth_token?
|
@@ -63,7 +66,7 @@ module Vero
|
|
63
66
|
|
64
67
|
Vero::Config.available_attributes.each do |symbol|
|
65
68
|
method_name = "#{symbol}=".to_sym
|
66
|
-
|
69
|
+
send(method_name, attributes[symbol]) if respond_to?(method_name) && attributes.key?(symbol)
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|