Skip to content

Commit 6e1d28e

Browse files
authored
Merge pull request #90 from sendwithus/an-88919984186-template-data-support
Add support for template_data optional fields for template operations
2 parents 8732d9f + ddda32d commit 6e1d28e

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.5.0
2+
- Add optional `template_data` fields to template calls
3+
14
## 4.4.0
25
- **[#88](https://github.com/sendwithus/sendwithus_ruby/pull/88) Fix problematic `render` implementation.** `template_data` serves two purposes, defining template data and specifying the optional API parameter for `locale`. Previously, `locale` would be stripped out of `template_data` in the API request, preventing users from specifying variables named `locale` in their own template data.
36

lib/send_with_us/api.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,15 @@ def render(template_id, version_id = nil, template_data = {}, strict = false)
160160
SendWithUs::ApiRequest.new(@configuration).post(:'render', payload)
161161
end
162162

163-
def create_template(name, subject, html, text, preheader='', amp_html='')
163+
def create_template(name, subject, html, text, preheader='', amp_html='', template_data={})
164164
payload = {
165165
name: name,
166166
subject: subject,
167167
html: html,
168168
text: text,
169169
preheader: preheader,
170-
amp_html: amp_html
170+
amp_html: amp_html,
171+
template_data: template_data
171172
}
172173

173174
payload = payload.to_json
@@ -272,28 +273,30 @@ def get_template_version(template_id, version_id)
272273
SendWithUs::ApiRequest.new(@configuration).get(endpoint)
273274
end
274275

275-
def update_template_version(template_id, version_id, name, subject, html, text, preheader='', amp_html='')
276+
def update_template_version(template_id, version_id, name, subject, html, text, preheader='', amp_html='', template_data={})
276277
payload = {
277278
name: name,
278279
subject: subject,
279280
html: html,
280281
text: text,
281282
preheader: preheader,
282-
amp_html: amp_html
283+
amp_html: amp_html,
284+
template_data: template_data
283285
}
284286

285287
endpoint = "templates/#{template_id}/versions/#{version_id}"
286288
SendWithUs::ApiRequest.new(@configuration).put(endpoint, payload.to_json)
287289
end
288290

289-
def create_template_version(template_id, name, subject, html, text, preheader='', amp_html='')
291+
def create_template_version(template_id, name, subject, html, text, preheader='', amp_html='', template_data={})
290292
payload = {
291293
name: name,
292294
subject: subject,
293295
html: html,
294296
text: text,
295297
preheader: preheader,
296-
amp_html: amp_html
298+
amp_html: amp_html,
299+
template_data: template_data
297300
}
298301

299302
endpoint = "templates/#{template_id}/versions"

lib/send_with_us/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SendWithUs
2-
VERSION = '4.4.0'
2+
VERSION = '4.5.0'
33
end

test/lib/send_with_us/api_request_test.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def build_objects
2121
:name => 'Test Template '.concat(Random.new.rand(100000).to_s),
2222
:id => 'test_fixture_1',
2323
:preheader => 'Test preheader',
24-
:amp_html => '<html><head></head><body>AMP HTML</body></html>'
24+
:amp_html => '<html><head></head><body>AMP HTML</body></html>',
25+
:template_data => {data: 'I AM DATA'}
2526
}
2627
end
2728

@@ -261,7 +262,8 @@ def test_update_template_version_with_optional_fields
261262
@template[:html],
262263
'sample text payload',
263264
preheader=@template[:preheader],
264-
amp_html=@template[:amp_html]
265+
amp_html=@template[:amp_html],
266+
template_data=@template[:template_data]
265267
)
266268

267269
assert_instance_of( Net::HTTPOK, result )
@@ -289,7 +291,8 @@ def test_create_template_version_with_optional_fields
289291
@template[:html],
290292
'sample text payload',
291293
preheader=@template[:preheader],
292-
amp_html=@template[:amp_html]
294+
amp_html=@template[:amp_html],
295+
template_data=@template[:template_data]
293296
)
294297

295298
assert_instance_of( Net::HTTPOK, result )

test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
require 'rubygems'
77
require 'bundler'
8+
MiniTest = Minitest unless defined?(MiniTest)
89
require "mocha/minitest"
910

1011
begin

0 commit comments

Comments
 (0)