klaviyo 2.0.6 → 2.1.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/klaviyo.gemspec +2 -2
- data/lib/klaviyo/apis/data_privacy.rb +3 -3
- data/lib/klaviyo/apis/email_templates.rb +1 -1
- data/lib/klaviyo/apis/lists.rb +9 -9
- data/lib/klaviyo/apis/metrics.rb +4 -4
- data/lib/klaviyo/apis/profiles.rb +4 -4
- data/lib/klaviyo/apis/public.rb +9 -4
- data/lib/klaviyo/client.rb +29 -8
- data/lib/klaviyo/klaviyo_module.rb +3 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 637b6125081b06c6f8121a331e4bfaef0976a5293496a3f9fe5aaed3b8b96afc
|
4
|
+
data.tar.gz: 420103a5fec88c53524eeeeaf32826424feb3fe5bd4146b4127fc71059319512
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15ca790911f3306253271f36fe7e15da7c2e042a3a25614217aab530d52c4bfcfdf4cd675cd1bf4f761d7e4b9b126c07b87681def392daf9514d5ab072f016e2
|
7
|
+
data.tar.gz: 4eca152856c1ce76571c0745a6d437ed8ccea93e6fbf057f35d81771c80c11219f20198fb52cf561447554a939e8eea65fa0c2db041c54f426c7b70270d73a10
|
data/klaviyo.gemspec
CHANGED
@@ -2,8 +2,8 @@ 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 = '2.0
|
6
|
-
s.date = '2021-
|
5
|
+
s.version = '2.1.0'
|
6
|
+
s.date = '2021-10-01'
|
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
9
|
s.authors = ['Klaviyo Team']
|
@@ -2,7 +2,7 @@ module Klaviyo
|
|
2
2
|
class DataPrivacy < Client
|
3
3
|
DATA_PRIVACY = 'data-privacy'
|
4
4
|
DELETION_REQUEST = 'deletion-request'
|
5
|
-
|
5
|
+
|
6
6
|
# Submits a data privacy-related deletion request
|
7
7
|
# @param id_type [String] 'email' or 'phone_number' or 'person_id
|
8
8
|
# @param identifier [String] value for the identifier specified
|
@@ -11,9 +11,9 @@ module Klaviyo
|
|
11
11
|
unless ['email', 'phone_number', 'person_id'].include? id_type
|
12
12
|
raise Klaviyo::KlaviyoError.new(INVALID_ID_TYPE_ERROR)
|
13
13
|
end
|
14
|
-
|
14
|
+
data = Hash[id_type.to_sym, identifier]
|
15
15
|
path = "#{DATA_PRIVACY}/#{DELETION_REQUEST}"
|
16
|
-
v2_request(HTTP_POST, path,
|
16
|
+
v2_request(HTTP_POST, path, **data)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/klaviyo/apis/lists.rb
CHANGED
@@ -14,7 +14,7 @@ module Klaviyo
|
|
14
14
|
body = {
|
15
15
|
:list_name => list_name
|
16
16
|
}
|
17
|
-
v2_request(HTTP_POST, LISTS, body)
|
17
|
+
v2_request(HTTP_POST, LISTS, **body)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Retrieves all the lists in the Klaviyo account
|
@@ -40,7 +40,7 @@ module Klaviyo
|
|
40
40
|
body = {
|
41
41
|
:list_name => list_name
|
42
42
|
}
|
43
|
-
v2_request(HTTP_PUT, path, body)
|
43
|
+
v2_request(HTTP_PUT, path, **body)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Deletes a list
|
@@ -65,7 +65,7 @@ module Klaviyo
|
|
65
65
|
:phone_numbers => phone_numbers,
|
66
66
|
:push_tokens => push_tokens
|
67
67
|
}
|
68
|
-
v2_request(HTTP_GET, path, params)
|
68
|
+
v2_request(HTTP_GET, path, **params)
|
69
69
|
end
|
70
70
|
|
71
71
|
# Subscribe profiles to a list.
|
@@ -80,7 +80,7 @@ module Klaviyo
|
|
80
80
|
params = {
|
81
81
|
:profiles => profiles
|
82
82
|
}
|
83
|
-
v2_request(HTTP_POST, path, params)
|
83
|
+
v2_request(HTTP_POST, path, **params)
|
84
84
|
end
|
85
85
|
|
86
86
|
# Unsubscribe and remove profiles from a list
|
@@ -92,7 +92,7 @@ module Klaviyo
|
|
92
92
|
params = {
|
93
93
|
:emails => emails
|
94
94
|
}
|
95
|
-
v2_request(HTTP_DELETE, path, params)
|
95
|
+
v2_request(HTTP_DELETE, path, **params)
|
96
96
|
end
|
97
97
|
|
98
98
|
# Add profiles to a list
|
@@ -106,7 +106,7 @@ module Klaviyo
|
|
106
106
|
params = {
|
107
107
|
:profiles => profiles
|
108
108
|
}
|
109
|
-
v2_request(HTTP_POST, path, params)
|
109
|
+
v2_request(HTTP_POST, path, **params)
|
110
110
|
end
|
111
111
|
|
112
112
|
# Check if profiles are on a list
|
@@ -123,7 +123,7 @@ module Klaviyo
|
|
123
123
|
:phone_numbers => phone_numbers,
|
124
124
|
:push_tokens => push_tokens
|
125
125
|
}
|
126
|
-
v2_request(HTTP_GET, path, params)
|
126
|
+
v2_request(HTTP_GET, path, **params)
|
127
127
|
end
|
128
128
|
|
129
129
|
# Remove profiles from a list
|
@@ -139,7 +139,7 @@ module Klaviyo
|
|
139
139
|
:phone_numbers => phone_numbers,
|
140
140
|
:push_tokens => push_tokens
|
141
141
|
}
|
142
|
-
v2_request(HTTP_DELETE, path, params)
|
142
|
+
v2_request(HTTP_DELETE, path, **params)
|
143
143
|
end
|
144
144
|
|
145
145
|
# Get all emails, phone numbers, along with reasons for list exclusion
|
@@ -151,7 +151,7 @@ module Klaviyo
|
|
151
151
|
params = {
|
152
152
|
:marker => marker
|
153
153
|
}
|
154
|
-
v2_request(HTTP_GET, path, params)
|
154
|
+
v2_request(HTTP_GET, path, **params)
|
155
155
|
end
|
156
156
|
|
157
157
|
# Get all of the emails, phone numbers, and push tokens for profiles in a given list or segment
|
data/lib/klaviyo/apis/metrics.rb
CHANGED
@@ -11,7 +11,7 @@ module Klaviyo
|
|
11
11
|
:page => page,
|
12
12
|
:count => count
|
13
13
|
}
|
14
|
-
v1_request(HTTP_GET, METRICS, params)
|
14
|
+
v1_request(HTTP_GET, METRICS, **params)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Returns a batched timeline of all events in your Klaviyo account.
|
@@ -26,7 +26,7 @@ module Klaviyo
|
|
26
26
|
:count => count,
|
27
27
|
:sort => sort
|
28
28
|
}
|
29
|
-
v1_request(HTTP_GET, path, params)
|
29
|
+
v1_request(HTTP_GET, path, **params)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Returns a batched timeline for one specific type of metric.
|
@@ -42,7 +42,7 @@ module Klaviyo
|
|
42
42
|
:count => count,
|
43
43
|
:sort => sort
|
44
44
|
}
|
45
|
-
v1_request(HTTP_GET, path, params)
|
45
|
+
v1_request(HTTP_GET, path, **params)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Export event data, optionally filtering and segmented on available event properties
|
@@ -74,7 +74,7 @@ module Klaviyo
|
|
74
74
|
:by => by,
|
75
75
|
:count => count
|
76
76
|
}
|
77
|
-
v1_request(HTTP_GET, path, params)
|
77
|
+
v1_request(HTTP_GET, path, **params)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -12,7 +12,7 @@ module Klaviyo
|
|
12
12
|
params = {
|
13
13
|
:email => email
|
14
14
|
}
|
15
|
-
v2_request(HTTP_GET, path, params)
|
15
|
+
v2_request(HTTP_GET, path, **params)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Retrieve all the data attributes for a Klaviyo Person ID.
|
@@ -29,7 +29,7 @@ module Klaviyo
|
|
29
29
|
# @return returns the updated person object
|
30
30
|
def self.update_person_attributes(person_id, kwargs = {})
|
31
31
|
path = "#{PERSON}/#{person_id}"
|
32
|
-
v1_request(HTTP_PUT, path, kwargs)
|
32
|
+
v1_request(HTTP_PUT, path, **kwargs)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Listing a person's event timeline
|
@@ -45,7 +45,7 @@ module Klaviyo
|
|
45
45
|
:count => count,
|
46
46
|
:sort => sort
|
47
47
|
}
|
48
|
-
v1_request(HTTP_GET, path, params)
|
48
|
+
v1_request(HTTP_GET, path, **params)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Listing a person's event timeline for a particular metric
|
@@ -62,7 +62,7 @@ module Klaviyo
|
|
62
62
|
:count => count,
|
63
63
|
:sort => sort
|
64
64
|
}
|
65
|
-
v1_request(HTTP_GET, path, params)
|
65
|
+
v1_request(HTTP_GET, path, **params)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
data/lib/klaviyo/apis/public.rb
CHANGED
@@ -4,12 +4,15 @@ module Klaviyo
|
|
4
4
|
#
|
5
5
|
# @kwarg :id [String] the customer or profile id
|
6
6
|
# @kwarg :email [String] the customer or profile email
|
7
|
+
# @kwarg :phone_number [String] the customer or profile phone number
|
7
8
|
# @kwarg :properties [Hash] properties of the profile to add or update
|
9
|
+
# @kwargs :method [String] the HTTP method to use for the request. Accepts 'get' or 'post'. Defaults to 'get'.
|
8
10
|
def self.identify(kwargs = {})
|
9
11
|
defaults = {:id => nil,
|
10
12
|
:email => nil,
|
11
13
|
:phone_number => nil,
|
12
|
-
:properties => {}
|
14
|
+
:properties => {},
|
15
|
+
:method => HTTP_GET
|
13
16
|
}
|
14
17
|
kwargs = defaults.merge(kwargs)
|
15
18
|
|
@@ -27,7 +30,7 @@ module Klaviyo
|
|
27
30
|
:properties => properties
|
28
31
|
}
|
29
32
|
|
30
|
-
public_request(
|
33
|
+
public_request(kwargs[:method], 'identify', **params)
|
31
34
|
end
|
32
35
|
|
33
36
|
# Used for tracking events and customer behaviors
|
@@ -39,6 +42,7 @@ module Klaviyo
|
|
39
42
|
# @kwarg :properties [Hash] properties of the event
|
40
43
|
# @kwargs :customer_properties [Hash] properties of the customer or profile
|
41
44
|
# @kwargs :time [Integer] timestamp of the event
|
45
|
+
# @kwargs :method [String] the HTTP method to use for the request. Accepts 'get' or 'post'. Defaults to 'get'.
|
42
46
|
def self.track(event, kwargs = {})
|
43
47
|
defaults = {
|
44
48
|
:id => nil,
|
@@ -46,7 +50,8 @@ module Klaviyo
|
|
46
50
|
:phone_number => nil,
|
47
51
|
:properties => {},
|
48
52
|
:customer_properties => {},
|
49
|
-
:time => nil
|
53
|
+
:time => nil,
|
54
|
+
:method => HTTP_GET
|
50
55
|
}
|
51
56
|
|
52
57
|
kwargs = defaults.merge(kwargs)
|
@@ -68,7 +73,7 @@ module Klaviyo
|
|
68
73
|
}
|
69
74
|
params[:time] = kwargs[:time] if kwargs[:time]
|
70
75
|
|
71
|
-
public_request(
|
76
|
+
public_request(kwargs[:method], 'track', **params)
|
72
77
|
end
|
73
78
|
|
74
79
|
def self.track_once(event, kwargs = {})
|
data/lib/klaviyo/client.rb
CHANGED
@@ -4,6 +4,9 @@ module Klaviyo
|
|
4
4
|
V1_API = 'v1'
|
5
5
|
V2_API = 'v2'
|
6
6
|
|
7
|
+
KL_VERSION = '2.1.0'
|
8
|
+
KL_USER_AGENT = "Ruby_Klaviyo/#{KL_VERSION}"
|
9
|
+
|
7
10
|
HTTP_DELETE = 'delete'
|
8
11
|
HTTP_GET = 'get'
|
9
12
|
HTTP_POST = 'post'
|
@@ -29,7 +32,8 @@ module Klaviyo
|
|
29
32
|
connection = Faraday.new(
|
30
33
|
url: url,
|
31
34
|
headers: {
|
32
|
-
'Content-Type' => content_type
|
35
|
+
'Content-Type' => content_type,
|
36
|
+
'User-Agent' => KL_USER_AGENT
|
33
37
|
})
|
34
38
|
if content_type == CONTENT_JSON
|
35
39
|
kwargs[:body] = kwargs[:body].to_json
|
@@ -40,10 +44,22 @@ module Klaviyo
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def self.public_request(method, path, **kwargs)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
check_public_api_key_is_valid()
|
48
|
+
if method == HTTP_GET
|
49
|
+
params = build_params(kwargs)
|
50
|
+
url = "#{BASE_API_URL}/#{path}?#{params}"
|
51
|
+
res = Faraday.get(url, {}, { 'User-Agent' => KL_USER_AGENT }).body
|
52
|
+
elsif method == HTTP_POST
|
53
|
+
url = URI("#{BASE_API_URL}/#{path}")
|
54
|
+
response = Faraday.post(url) do |req|
|
55
|
+
req.headers['Content-Type'] = CONTENT_URL_FORM
|
56
|
+
req.headers['Accept'] = 'text/html'
|
57
|
+
req.headers['User-Agent'] = KL_USER_AGENT
|
58
|
+
req.body = {data: "#{kwargs.to_json}"}
|
59
|
+
end
|
60
|
+
else
|
61
|
+
raise KlaviyoError.new(INVALID_HTTP_METHOD)
|
62
|
+
end
|
47
63
|
end
|
48
64
|
|
49
65
|
def self.v1_request(method, path, content_type: CONTENT_JSON, **kwargs)
|
@@ -55,7 +71,7 @@ module Klaviyo
|
|
55
71
|
}
|
56
72
|
data[:body] = data[:body].merge(kwargs[:params])
|
57
73
|
full_url = "#{V1_API}/#{path}"
|
58
|
-
request(method, full_url, content_type, data)
|
74
|
+
request(method, full_url, content_type, **data)
|
59
75
|
else
|
60
76
|
defaults = {:page => nil,
|
61
77
|
:count => nil,
|
@@ -75,7 +91,7 @@ module Klaviyo
|
|
75
91
|
}
|
76
92
|
data = {}
|
77
93
|
data[:body] = key.merge(kwargs)
|
78
|
-
request(method, path, CONTENT_JSON, data)
|
94
|
+
request(method, path, CONTENT_JSON, **data)
|
79
95
|
end
|
80
96
|
|
81
97
|
def self.build_params(params)
|
@@ -96,10 +112,15 @@ module Klaviyo
|
|
96
112
|
end
|
97
113
|
end
|
98
114
|
|
99
|
-
def self.
|
115
|
+
def self.check_public_api_key_is_valid()
|
100
116
|
if !Klaviyo.public_api_key
|
101
117
|
raise KlaviyoError.new(NO_PUBLIC_API_KEY_ERROR)
|
102
118
|
end
|
119
|
+
if ( Klaviyo.public_api_key =~ /pk_\w{34}$/ ) == 0
|
120
|
+
warn(PRIVATE_KEY_AS_PUBLIC)
|
121
|
+
elsif ( Klaviyo.public_api_key =~ /\w{6}$/ ) != 0
|
122
|
+
raise KlaviyoError.new(INCORRECT_PUBLIC_API_KEY_LENGTH)
|
123
|
+
end
|
103
124
|
end
|
104
125
|
|
105
126
|
def self.encode_params(kwargs)
|
@@ -24,4 +24,7 @@ module Klaviyo
|
|
24
24
|
NO_PUBLIC_API_KEY_ERROR = 'Please provide your Public API key for this request'
|
25
25
|
REQUIRED_ARG_ERROR = 'You must identify a user by email, ID or phone_number'
|
26
26
|
INVALID_ID_TYPE_ERROR = 'Invalid id_type provided, must be one of: email, phone_number, person_id'
|
27
|
+
PRIVATE_KEY_AS_PUBLIC = 'Private API key added in place of Public API key'
|
28
|
+
INCORRECT_PUBLIC_API_KEY_LENGTH = 'Public API Key must be 6 characters'
|
29
|
+
INVALID_HTTP_METHOD = 'Invalid HTTP method present, please use "get" or "post"'
|
27
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klaviyo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Klaviyo Team
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -87,7 +87,7 @@ files:
|
|
87
87
|
homepage: https://www.klaviyo.com/
|
88
88
|
licenses: []
|
89
89
|
metadata: {}
|
90
|
-
post_install_message:
|
90
|
+
post_install_message:
|
91
91
|
rdoc_options: []
|
92
92
|
require_paths:
|
93
93
|
- lib
|
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.0.
|
106
|
-
signing_key:
|
105
|
+
rubygems_version: 3.0.3
|
106
|
+
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: You heard us, a Ruby wrapper for the Klaviyo API
|
109
109
|
test_files: []
|