klaviyo 2.0.9 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: f20097f9b9538503cc8f541dd7e6d71c6c70904e51fdd59f636670f56d0b53c5
4
- data.tar.gz: 98032c0e8a4ac60b16501495b71d35ce09bd28bd62fce4c49392448929555ffa
2
+ SHA1:
3
+ metadata.gz: a6eaa11bdc826d37a755546d9cb771a469ff9039
4
+ data.tar.gz: 9f599d1c47bc281311a8adeb5f0c90e8467e4b65
5
5
  SHA512:
6
- metadata.gz: e4f99398385906828f37a4e1f25f05ca76493a905d526177da2cc189301fba84adc76551711213c85003337b0278d0cade9c8ba52e0c0726176465fd2c8132cd
7
- data.tar.gz: e109724a853cbf44a3546298fdfc04037a9cfb748b72a3edd96fab1475e209a3ea67c697ce940ff54d6aac57120f37aa853076398c016995b1b4b11f70279694
6
+ metadata.gz: 9a9ddabcb4a51a640a3f6b265d329a77934a5146803a4e4c67482fe4fbb7589e8dc722c193c55a7ae547ef917da6a61ad44e666442f7107f0963affdb8af7166
7
+ data.tar.gz: a04c3224f53c41f732e99f423b0e0e895772b3edd87b2824b179aec24f14c258f12f541631d035550fab32241f43558d04dd92b159fb9145e83d76737ee36d5b
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.9'
6
- s.date = '2021-07-30'
5
+ s.version = '2.0.1'
6
+ s.date = '2020-11-23'
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']
@@ -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
@@ -1,6 +1,8 @@
1
1
  module Klaviyo
2
2
  class Metrics < Client
3
3
  EXPORT = 'export'
4
+ METRIC = 'metric'
5
+ METRICS = 'metrics'
4
6
 
5
7
  # Returns a list of all metrics in Klaviyo
6
8
  # @param page [Integer] which page to return, default 0
@@ -11,7 +13,7 @@ module Klaviyo
11
13
  :page => page,
12
14
  :count => count
13
15
  }
14
- v1_request(HTTP_GET, METRICS, **params)
16
+ v1_request(HTTP_GET, METRICS, params)
15
17
  end
16
18
 
17
19
  # Returns a batched timeline of all events in your Klaviyo account.
@@ -26,7 +28,7 @@ module Klaviyo
26
28
  :count => count,
27
29
  :sort => sort
28
30
  }
29
- v1_request(HTTP_GET, path, **params)
31
+ v1_request(HTTP_GET, path, params)
30
32
  end
31
33
 
32
34
  # Returns a batched timeline for one specific type of metric.
@@ -42,7 +44,7 @@ module Klaviyo
42
44
  :count => count,
43
45
  :sort => sort
44
46
  }
45
- v1_request(HTTP_GET, path, **params)
47
+ v1_request(HTTP_GET, path, params)
46
48
  end
47
49
 
48
50
  # Export event data, optionally filtering and segmented on available event properties
@@ -74,7 +76,7 @@ module Klaviyo
74
76
  :by => by,
75
77
  :count => count
76
78
  }
77
- v1_request(HTTP_GET, path, **params)
79
+ v1_request(HTTP_GET, path, params)
78
80
  end
79
81
  end
80
82
  end
@@ -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
@@ -29,7 +16,7 @@ module Klaviyo
29
16
  # @return returns the updated person object
30
17
  def self.update_person_attributes(person_id, kwargs = {})
31
18
  path = "#{PERSON}/#{person_id}"
32
- v1_request(HTTP_PUT, path, **kwargs)
19
+ v1_request(HTTP_PUT, path, kwargs)
33
20
  end
34
21
 
35
22
  # Listing a person's event timeline
@@ -45,7 +32,7 @@ module Klaviyo
45
32
  :count => count,
46
33
  :sort => sort
47
34
  }
48
- v1_request(HTTP_GET, path, **params)
35
+ v1_request(HTTP_GET, path, params)
49
36
  end
50
37
 
51
38
  # Listing a person's event timeline for a particular metric
@@ -62,7 +49,7 @@ module Klaviyo
62
49
  :count => count,
63
50
  :sort => sort
64
51
  }
65
- v1_request(HTTP_GET, path, **params)
52
+ v1_request(HTTP_GET, path, params)
66
53
  end
67
54
  end
68
55
  end
@@ -4,25 +4,20 @@ 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
8
7
  # @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'.
10
8
  def self.identify(kwargs = {})
11
9
  defaults = {:id => nil,
12
10
  :email => nil,
13
- :phone_number => nil,
14
- :properties => {},
15
- :method => HTTP_GET
11
+ :properties => {}
16
12
  }
17
13
  kwargs = defaults.merge(kwargs)
18
14
 
19
- unless check_required_args(kwargs)
15
+ if !check_email_or_id_exists(kwargs)
20
16
  return
21
17
  end
22
18
 
23
19
  properties = kwargs[:properties]
24
20
  properties[:email] = kwargs[:email] unless kwargs[:email].to_s.empty?
25
- properties[:$phone_number] = kwargs[:phone_number] unless kwargs[:phone_number].to_s.empty?
26
21
  properties[:id] = kwargs[:id] unless kwargs[:id].to_s.empty?
27
22
 
28
23
  params = {
@@ -30,7 +25,7 @@ module Klaviyo
30
25
  :properties => properties
31
26
  }
32
27
 
33
- public_request(kwargs[:method], 'identify', **params)
28
+ public_request(HTTP_GET, 'identify', params)
34
29
  end
35
30
 
36
31
  # Used for tracking events and customer behaviors
@@ -38,31 +33,26 @@ module Klaviyo
38
33
  # @param event [String] the event to track
39
34
  # @kwarg :id [String] the customer or profile id
40
35
  # @kwarg :email [String] the customer or profile email
41
- # @kwarg :phone_number [String] the customer or profile phone number
42
36
  # @kwarg :properties [Hash] properties of the event
43
37
  # @kwargs :customer_properties [Hash] properties of the customer or profile
44
38
  # @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'.
46
39
  def self.track(event, kwargs = {})
47
40
  defaults = {
48
41
  :id => nil,
49
42
  :email => nil,
50
- :phone_number => nil,
51
43
  :properties => {},
52
44
  :customer_properties => {},
53
- :time => nil,
54
- :method => HTTP_GET
45
+ :time => nil
55
46
  }
56
47
 
57
48
  kwargs = defaults.merge(kwargs)
58
49
 
59
- unless check_required_args(kwargs)
50
+ if !check_email_or_id_exists(kwargs)
60
51
  return
61
52
  end
62
53
 
63
54
  customer_properties = kwargs[:customer_properties]
64
55
  customer_properties[:email] = kwargs[:email] unless kwargs[:email].to_s.empty?
65
- customer_properties[:$phone_number] = kwargs[:phone_number] unless kwargs[:phone_number].to_s.empty?
66
56
  customer_properties[:id] = kwargs[:id] unless kwargs[:id].to_s.empty?
67
57
 
68
58
  params = {
@@ -71,9 +61,9 @@ module Klaviyo
71
61
  :properties => kwargs[:properties],
72
62
  :customer_properties => customer_properties
73
63
  }
74
- params[:time] = kwargs[:time] if kwargs[:time]
64
+ params[:time] = kwargs[:time].to_time.to_i if kwargs[:time]
75
65
 
76
- public_request(kwargs[:method], 'track', **params)
66
+ public_request(HTTP_GET, 'track', params)
77
67
  end
78
68
 
79
69
  def self.track_once(event, kwargs = {})
@@ -10,92 +10,62 @@ 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, content_type, **kwargs)
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' => 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, **kwargs)
43
- check_public_api_key_is_valid()
44
- if method == HTTP_GET
45
- params = build_params(kwargs)
46
- url = "#{BASE_API_URL}/#{path}?#{params}"
47
- res = Faraday.get(url).body
48
- elsif method == HTTP_POST
49
- url = URI("#{BASE_API_URL}/#{path}")
50
- response = Faraday.post(url) do |req|
51
- req.headers['Content-Type'] = CONTENT_URL_FORM
52
- req.headers['Accept'] = 'text/html'
53
- req.body = {data: "#{kwargs.to_json}"}
54
- end
55
- else
56
- raise KlaviyoError.new(INVALID_HTTP_METHOD)
57
- end
34
+ def self.public_request(method, path, kwargs = {})
35
+ check_public_api_key_exists()
36
+ params = build_params(kwargs)
37
+ url = "#{BASE_API_URL}/#{path}?#{params}"
38
+ res = Faraday.get(url).body
58
39
  end
59
40
 
60
- def self.v1_request(method, path, content_type: CONTENT_JSON, **kwargs)
61
- if content_type == CONTENT_URL_FORM
62
- data = {
63
- :body => {
64
- :api_key => Klaviyo.private_api_key
65
- }
66
- }
67
- data[:body] = data[:body].merge(kwargs[:params])
68
- full_url = "#{V1_API}/#{path}"
69
- request(method, full_url, content_type, **data)
70
- else
71
- defaults = {:page => nil,
72
- :count => nil,
73
- :since => nil,
74
- :sort => nil}
75
- params = defaults.merge(kwargs)
76
- query_params = encode_params(params)
77
- full_url = "#{V1_API}/#{path}?api_key=#{Klaviyo.private_api_key}#{query_params}"
78
- request(method, full_url, content_type)
79
- 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)
80
50
  end
81
51
 
82
- def self.v2_request(method, path, **kwargs)
52
+ def self.v2_request(method, path, kwargs = {})
83
53
  path = "#{V2_API}/#{path}"
84
54
  key = {
85
55
  "api_key": "#{Klaviyo.private_api_key}"
86
56
  }
87
57
  data = {}
88
58
  data[:body] = key.merge(kwargs)
89
- request(method, path, CONTENT_JSON, **data)
59
+ request(method, path, data)
90
60
  end
91
61
 
92
62
  def self.build_params(params)
93
- "data=#{CGI.escape(Base64.encode64(JSON.generate(params)).gsub(/\n/, ''))}"
63
+ "data=#{Base64.encode64(JSON.generate(params)).gsub(/\n/,'')}"
94
64
  end
95
65
 
96
- def self.check_required_args(kwargs)
97
- if kwargs[:email].to_s.empty? and kwargs[:phone_number].to_s.empty? and kwargs[:id].to_s.empty?
98
- raise Klaviyo::KlaviyoError.new(REQUIRED_ARG_ERROR)
66
+ def self.check_email_or_id_exists(kwargs)
67
+ if kwargs[:email].to_s.empty? and kwargs[:id].to_s.empty?
68
+ raise Klaviyo::KlaviyoError.new(NO_ID_OR_EMAIL_ERROR)
99
69
  else
100
70
  return true
101
71
  end
@@ -107,16 +77,10 @@ module Klaviyo
107
77
  end
108
78
  end
109
79
 
110
- def self.check_public_api_key_is_valid()
80
+ def self.check_public_api_key_exists()
111
81
  if !Klaviyo.public_api_key
112
82
  raise KlaviyoError.new(NO_PUBLIC_API_KEY_ERROR)
113
83
  end
114
- if ( Klaviyo.public_api_key =~ /pk_\w{34}$/ ) == 0
115
- raise KlaviyoError.new(PRIVATE_KEY_AS_PUBLIC)
116
- end
117
- if ( Klaviyo.public_api_key =~ /\w{6}$/ ) != 0
118
- raise KlaviyoError.new(INCORRECT_PUBLIC_API_KEY_LENGTH)
119
- end
120
84
  end
121
85
 
122
86
  def self.encode_params(kwargs)
@@ -8,9 +8,6 @@ require_relative 'apis/public'
8
8
  require_relative 'apis/lists'
9
9
  require_relative 'apis/metrics'
10
10
  require_relative 'apis/profiles'
11
- require_relative 'apis/campaigns'
12
- require_relative 'apis/email_templates'
13
- require_relative 'apis/data_privacy'
14
11
 
15
12
  module Klaviyo
16
13
  class << self
@@ -22,9 +19,5 @@ module Klaviyo
22
19
 
23
20
  NO_PRIVATE_API_KEY_ERROR = 'Please provide your Private API key for this request'
24
21
  NO_PUBLIC_API_KEY_ERROR = 'Please provide your Public API key for this request'
25
- 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
- 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"'
22
+ NO_ID_OR_EMAIL_ERROR = 'You must identify a user by email or ID'
30
23
  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.9
4
+ version: 2.0.1
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-07-30 00:00:00.000000000 Z
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -74,9 +74,6 @@ extra_rdoc_files: []
74
74
  files:
75
75
  - klaviyo.gemspec
76
76
  - lib/klaviyo.rb
77
- - lib/klaviyo/apis/campaigns.rb
78
- - lib/klaviyo/apis/data_privacy.rb
79
- - lib/klaviyo/apis/email_templates.rb
80
77
  - lib/klaviyo/apis/lists.rb
81
78
  - lib/klaviyo/apis/metrics.rb
82
79
  - lib/klaviyo/apis/profiles.rb
@@ -87,7 +84,7 @@ files:
87
84
  homepage: https://www.klaviyo.com/
88
85
  licenses: []
89
86
  metadata: {}
90
- post_install_message:
87
+ post_install_message:
91
88
  rdoc_options: []
92
89
  require_paths:
93
90
  - lib
@@ -102,8 +99,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
99
  - !ruby/object:Gem::Version
103
100
  version: '0'
104
101
  requirements: []
105
- rubygems_version: 3.0.8
106
- signing_key:
102
+ rubyforge_project:
103
+ rubygems_version: 2.5.1
104
+ signing_key:
107
105
  specification_version: 4
108
106
  summary: You heard us, a Ruby wrapper for the Klaviyo API
109
107
  test_files: []
@@ -1,41 +0,0 @@
1
- module Klaviyo
2
- class Campaigns < Client
3
- CANCEL = 'cancel'
4
- CAMPAIGN = 'campaign'
5
- CAMPAIGNS = 'campaigns'
6
- SEND = 'send'
7
-
8
- # Retrieves all the campaigns from Klaviyo account
9
- # @return [List] of JSON formatted campaing objects
10
- def self.get_campaigns()
11
- v1_request(HTTP_GET, CAMPAIGNS)
12
- end
13
-
14
- # Retrieves the details of the list
15
- # @param campaign_id the if of campaign
16
- # @return [JSON] a JSON object containing information about the campaign
17
- def self.get_campaign_details(campaign_id)
18
- path = "#{CAMPAIGN}/#{campaign_id}"
19
-
20
- v1_request(HTTP_GET, path)
21
- end
22
-
23
- # Sends the campaign immediately
24
- # @param campaign_id [String] the id of campaign
25
- # @return will return with HTTP ok in case of success
26
- def self.send_campaign(campaign_id)
27
- path = "#{CAMPAIGN}/#{campaign_id}/#{SEND}"
28
-
29
- v1_request(HTTP_POST, path)
30
- end
31
-
32
- # Cancels the campaign with specified campaign_id
33
- # @param campaign_id [String] the id of campaign
34
- # @return [JSON] a JSON object containing the campaign details
35
- def self.cancel_campaign(campaign_id)
36
- path = "#{CAMPAIGN}/#{campaign_id}/#{CANCEL}"
37
-
38
- v1_request(HTTP_POST, path)
39
- end
40
- end
41
- end
@@ -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
- data = Hash[id_type.to_sym, identifier]
15
- path = "#{DATA_PRIVACY}/#{DELETION_REQUEST}"
16
- v2_request(HTTP_POST, path, **data)
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