klaviyo 2.0.6 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/klaviyo.gemspec +2 -2
- data/lib/klaviyo/apis/metrics.rb +2 -0
- data/lib/klaviyo/apis/profiles.rb +0 -13
- data/lib/klaviyo/apis/public.rb +2 -2
- data/lib/klaviyo/client.rb +16 -35
- data/lib/klaviyo/klaviyo_module.rb +0 -3
- metadata +2 -4
- data/lib/klaviyo/apis/data_privacy.rb +0 -19
- data/lib/klaviyo/apis/email_templates.rb +0 -97
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 438fe72ddfdd5e636f8026c8e0b02daf22586e58c4a2628065db088b633bb1be
|
4
|
+
data.tar.gz: c586d57114a208aa6843fa6dd218d2e2ceae454282c8b4b297a7ab122cd89dd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce5653e39bc762647ee52f29a3c0b2d8ea672b782a5192e9ca3d3da11a41e388f67a5c11f7eb28ce7f274f691a445677ee345eb3855ba2fa422ed30407a282f
|
7
|
+
data.tar.gz: 5f831ad7a264a16b697435e1cafe6c942f7c58572bdf67041d74b3f65f398fd4ba948e0c70edbccb6d5839d16f0831553ce2868fe43b6b6fe796d9dfef2e2103
|
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.0.3'
|
6
|
+
s.date = '2021-01-11'
|
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']
|
data/lib/klaviyo/apis/metrics.rb
CHANGED
@@ -1,19 +1,6 @@
|
|
1
1
|
module Klaviyo
|
2
2
|
class Profiles < Client
|
3
3
|
PERSON = 'person'
|
4
|
-
PEOPLE = 'people'
|
5
|
-
SEARCH = 'search'
|
6
|
-
|
7
|
-
# Retrieves the id of the profile given email
|
8
|
-
# @param email [String] the email of the profile
|
9
|
-
# @return [JSON] a JSON object containing id of the profile
|
10
|
-
def self.get_profile_id_by_email(email)
|
11
|
-
path = "#{PEOPLE}/#{SEARCH}"
|
12
|
-
params = {
|
13
|
-
:email => email
|
14
|
-
}
|
15
|
-
v2_request(HTTP_GET, path, params)
|
16
|
-
end
|
17
4
|
|
18
5
|
# Retrieve all the data attributes for a Klaviyo Person ID.
|
19
6
|
# @param person_id [String] the id of the profile
|
data/lib/klaviyo/apis/public.rb
CHANGED
@@ -66,9 +66,9 @@ module Klaviyo
|
|
66
66
|
:properties => kwargs[:properties],
|
67
67
|
:customer_properties => customer_properties
|
68
68
|
}
|
69
|
-
params[:time] = kwargs[:time] if kwargs[:time]
|
69
|
+
params[:time] = kwargs[:time].to_time.to_i if kwargs[:time]
|
70
70
|
|
71
|
-
public_request(HTTP_GET, 'track',
|
71
|
+
public_request(HTTP_GET, 'track', params)
|
72
72
|
end
|
73
73
|
|
74
74
|
def self.track_once(event, kwargs = {})
|
data/lib/klaviyo/client.rb
CHANGED
@@ -10,76 +10,57 @@ module Klaviyo
|
|
10
10
|
HTTP_PUT = 'put'
|
11
11
|
|
12
12
|
ALL = 'all'
|
13
|
-
METRIC = 'metric'
|
14
|
-
METRICS = 'metrics'
|
15
13
|
TIMELINE = 'timeline'
|
16
14
|
|
17
15
|
DEFAULT_COUNT = 100
|
18
16
|
DEFAULT_PAGE = 0
|
19
17
|
DEFAULT_SORT_DESC = 'desc'
|
20
18
|
|
21
|
-
CONTENT_JSON = 'application/json'
|
22
|
-
CONTENT_URL_FORM = 'application/x-www-form-urlencoded'
|
23
|
-
|
24
19
|
private
|
25
20
|
|
26
|
-
def self.request(method, path,
|
21
|
+
def self.request(method, path, kwargs = {})
|
27
22
|
check_private_api_key_exists()
|
28
23
|
url = "#{BASE_API_URL}/#{path}"
|
29
24
|
connection = Faraday.new(
|
30
25
|
url: url,
|
31
26
|
headers: {
|
32
|
-
'Content-Type' =>
|
27
|
+
'Content-Type' => 'application/json'
|
33
28
|
})
|
34
|
-
if content_type == CONTENT_JSON
|
35
|
-
kwargs[:body] = kwargs[:body].to_json
|
36
|
-
end
|
37
29
|
response = connection.send(method) do |req|
|
38
|
-
req.body = kwargs[:body] || nil
|
30
|
+
req.body = kwargs[:body].to_json || nil
|
39
31
|
end
|
40
32
|
end
|
41
33
|
|
42
|
-
def self.public_request(method, path,
|
34
|
+
def self.public_request(method, path, kwargs = {})
|
43
35
|
check_public_api_key_exists()
|
44
36
|
params = build_params(kwargs)
|
45
37
|
url = "#{BASE_API_URL}/#{path}?#{params}"
|
46
38
|
res = Faraday.get(url).body
|
47
39
|
end
|
48
40
|
|
49
|
-
def self.v1_request(method, path,
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
request(method, full_url, content_type, data)
|
59
|
-
else
|
60
|
-
defaults = {:page => nil,
|
61
|
-
:count => nil,
|
62
|
-
:since => nil,
|
63
|
-
:sort => nil}
|
64
|
-
params = defaults.merge(kwargs)
|
65
|
-
query_params = encode_params(params)
|
66
|
-
full_url = "#{V1_API}/#{path}?api_key=#{Klaviyo.private_api_key}#{query_params}"
|
67
|
-
request(method, full_url, content_type)
|
68
|
-
end
|
41
|
+
def self.v1_request(method, path, kwargs = {})
|
42
|
+
defaults = {:page => nil,
|
43
|
+
:count => nil,
|
44
|
+
:since => nil,
|
45
|
+
:sort => nil}
|
46
|
+
params = defaults.merge(kwargs)
|
47
|
+
query_params = encode_params(params)
|
48
|
+
full_url = "#{V1_API}/#{path}?api_key=#{Klaviyo.private_api_key}#{query_params}"
|
49
|
+
request(method, full_url)
|
69
50
|
end
|
70
51
|
|
71
|
-
def self.v2_request(method, path,
|
52
|
+
def self.v2_request(method, path, kwargs = {})
|
72
53
|
path = "#{V2_API}/#{path}"
|
73
54
|
key = {
|
74
55
|
"api_key": "#{Klaviyo.private_api_key}"
|
75
56
|
}
|
76
57
|
data = {}
|
77
58
|
data[:body] = key.merge(kwargs)
|
78
|
-
request(method, path,
|
59
|
+
request(method, path, data)
|
79
60
|
end
|
80
61
|
|
81
62
|
def self.build_params(params)
|
82
|
-
"data=#{
|
63
|
+
"data=#{Base64.encode64(JSON.generate(params)).gsub(/\n/,'')}"
|
83
64
|
end
|
84
65
|
|
85
66
|
def self.check_required_args(kwargs)
|
@@ -9,8 +9,6 @@ require_relative 'apis/lists'
|
|
9
9
|
require_relative 'apis/metrics'
|
10
10
|
require_relative 'apis/profiles'
|
11
11
|
require_relative 'apis/campaigns'
|
12
|
-
require_relative 'apis/email_templates'
|
13
|
-
require_relative 'apis/data_privacy'
|
14
12
|
|
15
13
|
module Klaviyo
|
16
14
|
class << self
|
@@ -23,5 +21,4 @@ module Klaviyo
|
|
23
21
|
NO_PRIVATE_API_KEY_ERROR = 'Please provide your Private API key for this request'
|
24
22
|
NO_PUBLIC_API_KEY_ERROR = 'Please provide your Public API key for this request'
|
25
23
|
REQUIRED_ARG_ERROR = 'You must identify a user by email, ID or phone_number'
|
26
|
-
INVALID_ID_TYPE_ERROR = 'Invalid id_type provided, must be one of: email, phone_number, person_id'
|
27
24
|
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.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Klaviyo Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -75,8 +75,6 @@ files:
|
|
75
75
|
- klaviyo.gemspec
|
76
76
|
- lib/klaviyo.rb
|
77
77
|
- lib/klaviyo/apis/campaigns.rb
|
78
|
-
- lib/klaviyo/apis/data_privacy.rb
|
79
|
-
- lib/klaviyo/apis/email_templates.rb
|
80
78
|
- lib/klaviyo/apis/lists.rb
|
81
79
|
- lib/klaviyo/apis/metrics.rb
|
82
80
|
- lib/klaviyo/apis/profiles.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Klaviyo
|
2
|
-
class DataPrivacy < Client
|
3
|
-
DATA_PRIVACY = 'data-privacy'
|
4
|
-
DELETION_REQUEST = 'deletion-request'
|
5
|
-
|
6
|
-
# Submits a data privacy-related deletion request
|
7
|
-
# @param id_type [String] 'email' or 'phone_number' or 'person_id
|
8
|
-
# @param identifier [String] value for the identifier specified
|
9
|
-
# @return a dictionary with a confirmation that deletion task submitted for the customer
|
10
|
-
def self.request_profile_deletion(id_type, identifier)
|
11
|
-
unless ['email', 'phone_number', 'person_id'].include? id_type
|
12
|
-
raise Klaviyo::KlaviyoError.new(INVALID_ID_TYPE_ERROR)
|
13
|
-
end
|
14
|
-
identifier = { id_type => identifier }
|
15
|
-
path = "#{DATA_PRIVACY}/#{DELETION_REQUEST}"
|
16
|
-
v2_request(HTTP_POST, path, identifier)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module Klaviyo
|
2
|
-
class EmailTemplates < Client
|
3
|
-
EMAIL_TEMPLATES = 'email-templates'
|
4
|
-
EMAIL_TEMPLATE = 'email-template'
|
5
|
-
CLONE = 'clone'
|
6
|
-
RENDER = 'render'
|
7
|
-
SEND = 'send'
|
8
|
-
|
9
|
-
# Returns a list of all the email templates you've created.
|
10
|
-
# The templates are returned in sorted order by name.
|
11
|
-
# @return [List] of JSON formatted email template objects
|
12
|
-
def self.get_templates()
|
13
|
-
v1_request(HTTP_GET, EMAIL_TEMPLATES)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Creates a new email template
|
17
|
-
# @param :name [String] The name of the email template
|
18
|
-
# @param :html [String] The HTML content for this template
|
19
|
-
# @return [JSON] a JSON object containing information about the email template
|
20
|
-
def self.create_template(name: nil, html: nil)
|
21
|
-
params = {
|
22
|
-
name: name,
|
23
|
-
html: html
|
24
|
-
}
|
25
|
-
v1_request(HTTP_POST, EMAIL_TEMPLATES, content_type: CONTENT_URL_FORM, params: params)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Updates the name and/or HTML content of a template. Only updates imported
|
29
|
-
# HTML templates; does not currently update drag & drop templates
|
30
|
-
# @param template_id [String] The id of the email template
|
31
|
-
# @param :name [String] The name of the email template
|
32
|
-
# @param :html [String] The HTML content for this template
|
33
|
-
# @return [JSON] a JSON object containing information about the email template
|
34
|
-
def self.update_template(template_id, name:, html:)
|
35
|
-
path = "#{EMAIL_TEMPLATE}/#{template_id}"
|
36
|
-
params = {
|
37
|
-
name: name,
|
38
|
-
html: html
|
39
|
-
}
|
40
|
-
v1_request(HTTP_PUT, path, params)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Deletes a given template.
|
44
|
-
# @param template_id [String] The id of the email template
|
45
|
-
# @return [JSON] a JSON object containing information about the email template
|
46
|
-
def self.delete_template(template_id)
|
47
|
-
path = "#{EMAIL_TEMPLATE}/#{template_id}"
|
48
|
-
v1_request(HTTP_DELETE, path)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Creates a copy of a given template with a new name
|
52
|
-
# @param template_id [String] The id of the email template to copy
|
53
|
-
# @param :name [String] The name of the newly cloned email template
|
54
|
-
# @return [JSON] a JSON object containing information about the email template
|
55
|
-
def self.clone_template(template_id, name:)
|
56
|
-
path = "#{EMAIL_TEMPLATE}/#{template_id}/#{CLONE}"
|
57
|
-
params = {
|
58
|
-
name: name
|
59
|
-
}
|
60
|
-
v1_request(HTTP_POST, path, content_type: CONTENT_URL_FORM, params: params)
|
61
|
-
end
|
62
|
-
|
63
|
-
# Renders the specified template with the provided data and return HTML
|
64
|
-
# and text versions of the email
|
65
|
-
# @param template_id [String] The id of the email template to copy
|
66
|
-
# @param :context [Hash] The context the email template will be rendered with
|
67
|
-
# @return [JSON] a JSON object containing information about the email template
|
68
|
-
def self.render_template(template_id, context: {})
|
69
|
-
path = "#{EMAIL_TEMPLATE}/#{template_id}/#{RENDER}"
|
70
|
-
params = {
|
71
|
-
context: context
|
72
|
-
}
|
73
|
-
v1_request(HTTP_POST, path, content_type: CONTENT_URL_FORM, params: params)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Renders the specified template with the provided data and then send the
|
77
|
-
# contents in an email via the service specified
|
78
|
-
# @param template_id [String] The id of the email template to copy
|
79
|
-
# @param :from_email [String] The from email address; used in the reply-to header
|
80
|
-
# @param :from_name [String] The name the email is sent from
|
81
|
-
# @param :subject [String] The subject of the email template
|
82
|
-
# @param :to [Mixed] The email this template is being sent to
|
83
|
-
# @param :context [Hash] The context the email template will be rendered with
|
84
|
-
# @return [JSON] a JSON object containing information about the email template
|
85
|
-
def self.send_template(template_id, from_email:, from_name:, subject:, to:, context: {})
|
86
|
-
path = "#{EMAIL_TEMPLATE}/#{template_id}/#{SEND}"
|
87
|
-
params = {
|
88
|
-
from_email: from_email,
|
89
|
-
from_name: from_name,
|
90
|
-
subject: subject,
|
91
|
-
to: to,
|
92
|
-
context: context
|
93
|
-
}
|
94
|
-
v1_request(HTTP_POST, path, content_type: CONTENT_URL_FORM, params: params)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|