klaviyo 0.9.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b500c9a9b23a831e8dbd4973b10e86420af64d70
4
+ data.tar.gz: 75585569e42545281d0622a40c5f888f261d6622
5
+ SHA512:
6
+ metadata.gz: eecb6c11c4b4a893271f914db129724362ae6d74d5950ef79b5aa90e83939ea6c937af40122768b2e1f409640cef72587e19bfc3af05b1fda9dc33c4b46c3c20
7
+ data.tar.gz: 98d0566c1c134ea9ab32c0968927019d0231532aeeb72a86e432aeef60a4314f54dd12450269d9dc0762a373feef0b15dfdba8a68b2ef387fe8ce29c9576ff39
@@ -2,17 +2,17 @@ files = ['klaviyo.gemspec', '{lib}/**/*'].map {|f| Dir[f]}.flatten
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'klaviyo'
5
- s.version = '0.9.4'
6
- s.date = '2012-09-06'
5
+ s.version = '1.0.0'
6
+ s.date = '2014-09-06'
7
7
  s.summary = 'You heard us, a Ruby wrapper for the Klaviyo API'
8
8
  s.description = 'Ruby wrapper for the Klaviyo API'
9
- s.authors = ['Andrew Bialecki']
10
- s.email = 'andrew@klaviyo.com'
9
+ s.authors = ['Klaviyo Team']
10
+ s.email = 'hello@klaviyo.com'
11
11
  s.files = files
12
- s.homepage = 'http://www.klaviyo.com/'
12
+ s.homepage = 'https://www.klaviyo.com/'
13
13
  s.require_path = 'lib'
14
14
  s.has_rdoc = false
15
15
  s.add_dependency 'json'
16
16
  s.add_dependency 'rack'
17
17
  s.add_dependency 'escape'
18
- end
18
+ end
@@ -1,7 +1,6 @@
1
1
  require 'open-uri'
2
2
  require 'base64'
3
3
  require 'json'
4
- require 'klaviyo/client/middleware'
5
4
 
6
5
  module Klaviyo
7
6
  class KlaviyoError < StandardError; end
@@ -23,15 +22,17 @@ module Klaviyo
23
22
  customer_properties = kwargs[:customer_properties]
24
23
  customer_properties[:email] = kwargs[:email] unless kwargs[:email].to_s.empty?
25
24
  customer_properties[:id] = kwargs[:id] unless kwargs[:id].to_s.empty?
26
-
27
- params = build_params({
25
+
26
+ params = {
28
27
  :token => @api_key,
29
28
  :event => event,
30
29
  :properties => kwargs[:properties],
31
30
  :customer_properties => customer_properties,
32
31
  :ip => ''
33
- })
32
+ }
34
33
  params[:time] = kwargs[:time].to_time.to_i if kwargs[:time]
34
+
35
+ params = build_params(params)
35
36
  request('crm/api/track', params)
36
37
  end
37
38
 
@@ -0,0 +1,68 @@
1
+ module Rack
2
+ class Klaviyo
3
+ def initialize(app, api_key, options={})
4
+ @app = app
5
+ @api_key = api_key
6
+ @options = {
7
+ :insert_js_last => true
8
+ }.merge(options)
9
+ end
10
+
11
+ def call(env)
12
+ @env = env
13
+
14
+ @status, @headers, @response = @app.call(env)
15
+
16
+ if is_trackable_response?
17
+ update_response!
18
+ update_content_length!
19
+ end
20
+
21
+ [@status, @headers, @response]
22
+ end
23
+
24
+ private
25
+
26
+ def update_response!
27
+ @response.each do |part|
28
+ insert_at = part.index(@options[:insert_js_last] ? '</body' : '</head')
29
+ unless insert_at.nil?
30
+ part.insert(insert_at, render_script)
31
+ end
32
+ end
33
+ end
34
+
35
+ def update_content_length!
36
+ new_size = 0
37
+ @response.each{|part| new_size += part.bytesize}
38
+ @headers.merge!('Content-Length' => new_size.to_s)
39
+ end
40
+
41
+ def is_ajax_request?
42
+ @env.has_key?('HTTP_X_REQUESTED_WITH') && @env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
43
+ end
44
+
45
+ def is_html_response?
46
+ @headers['Content-Type'].include?('text/html') if @headers.has_key?('Content-Type')
47
+ end
48
+
49
+ def is_trackable_response?
50
+ is_html_response? && !is_ajax_request?
51
+ end
52
+
53
+ def render_script
54
+ <<-EOT
55
+ <script text="text/javascript">
56
+ var _learnq = _learnq || [];
57
+ _learnq.push(['account', '#{@api_key}']);
58
+
59
+ (function () {
60
+ var b = document.createElement('script'); b.type = 'text/javascript'; b.async = true;
61
+ b.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'a.klaviyo.com/media/js/analytics/analytics.js';
62
+ var a = document.getElementsByTagName('script')[0]; a.parentNode.insertBefore(b, a);
63
+ })();
64
+ </script>
65
+ EOT
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,96 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klaviyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
- - Andrew Bialecki
7
+ - Klaviyo Team
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-06 00:00:00.000000000 Z
11
+ date: 2014-09-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rack
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: escape
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Ruby wrapper for the Klaviyo API
63
- email: andrew@klaviyo.com
56
+ email: hello@klaviyo.com
64
57
  executables: []
65
58
  extensions: []
66
59
  extra_rdoc_files: []
67
60
  files:
68
61
  - klaviyo.gemspec
69
- - lib/klaviyo/client/middleware.rb
70
62
  - lib/klaviyo/client.rb
71
63
  - lib/klaviyo.rb
72
- homepage: http://www.klaviyo.com/
64
+ - lib/rack/klaviyo.rb
65
+ homepage: https://www.klaviyo.com/
73
66
  licenses: []
67
+ metadata: {}
74
68
  post_install_message:
75
69
  rdoc_options: []
76
70
  require_paths:
77
71
  - lib
78
72
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
73
  requirements:
81
- - - ! '>='
74
+ - - '>='
82
75
  - !ruby/object:Gem::Version
83
76
  version: '0'
84
77
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
78
  requirements:
87
- - - ! '>='
79
+ - - '>='
88
80
  - !ruby/object:Gem::Version
89
81
  version: '0'
90
82
  requirements: []
91
83
  rubyforge_project:
92
- rubygems_version: 1.8.24
84
+ rubygems_version: 2.0.14
93
85
  signing_key:
94
- specification_version: 3
86
+ specification_version: 4
95
87
  summary: You heard us, a Ruby wrapper for the Klaviyo API
96
88
  test_files: []
@@ -1,72 +0,0 @@
1
- require 'rack'
2
-
3
- module Klaviyo
4
- class Client
5
- class Middleware
6
- def initialize(app, api_key, options={})
7
- @app = app
8
- @api_key = api_key
9
- @options = {
10
- :insert_js_last => true
11
- }.merge(options)
12
- end
13
-
14
- def call(env)
15
- @env = env
16
-
17
- @status, @headers, @response = @app.call(env)
18
-
19
- if is_trackable_response?
20
- update_response!
21
- update_content_length!
22
- end
23
-
24
- [@status, @headers, @response]
25
- end
26
-
27
- private
28
-
29
- def update_response!
30
- @response.each do |part|
31
- insert_at = part.index(@options[:insert_js_last] ? '</body' : '</head')
32
- unless insert_at.nil?
33
- part.insert(insert_at, render_script)
34
- end
35
- end
36
- end
37
-
38
- def update_content_length!
39
- new_size = 0
40
- @response.each{|part| new_size += part.bytesize}
41
- @headers.merge!('Content-Length' => new_size.to_s)
42
- end
43
-
44
- def is_ajax_request?
45
- @env.has_key?('HTTP_X_REQUESTED_WITH') && @env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
46
- end
47
-
48
- def is_html_response?
49
- @headers['Content-Type'].include?('text/html') if @headers.has_key?('Content-Type')
50
- end
51
-
52
- def is_trackable_response?
53
- is_html_response? && !is_ajax_request?
54
- end
55
-
56
- def render_script
57
- <<-EOT
58
- <script text="text/javascript">
59
- var _learnq = _learnq || [];
60
- _learnq.push(['account', '#{@api_key}']);
61
-
62
- (function () {
63
- var b = document.createElement('script'); b.type = 'text/javascript'; b.async = true;
64
- b.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'a.klaviyo.com/media/js/learnmarklet.js';
65
- var a = document.getElementsByTagName('script')[0]; a.parentNode.insertBefore(b, a);
66
- })();
67
- </script>
68
- EOT
69
- end
70
- end
71
- end
72
- end