send_with_us 1.5.0 → 1.6.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.
data/README.md CHANGED
@@ -21,7 +21,19 @@ bundle install
21
21
 
22
22
  ## Usage
23
23
 
24
- ### General
24
+ ### Send
25
+
26
+ #### send_with parameters
27
+ - **email\_id** - *string* - Template ID being sent
28
+ - **to** - *hash* - Recipients' email address
29
+ - **data** - *hash* - Email data
30
+ - **from** - *hash* - From name/address/reply\_to
31
+ - **cc** - *array* - array of CC addresses
32
+ - **bcc** - *array* - array of BCC addresses
33
+ - **files** - *array* - array of files to attach
34
+ - **esp\_account** - *string* - ESP account used to send email
35
+ - **version\_name** - *string* - version of template to send
36
+ - **headers** - *hash* - custom email headers **NOTE** only supported by some ESPs
25
37
 
26
38
  For any Ruby project:
27
39
  ```ruby
@@ -33,25 +45,25 @@ begin
33
45
 
34
46
  # only required params
35
47
  result = obj.send_with(
36
- 'EMAIL_ID',
48
+ 'template_id',
37
49
  { address: "user@example.com" })
38
50
  puts result
39
51
 
40
52
  # with all optional params
41
53
  result = obj.send_with(
42
- 'email_id',
54
+ 'template_id',
43
55
  { name: 'Matt', address: 'recipient@example.com' },
44
56
  { company_name: 'TestCo' },
45
57
  { name: 'Company',
46
58
  address: 'company@example.com',
47
59
  reply_to: 'info@example.com' },
48
- 'esp_MYESPACCOUNT',
49
- 'v2') # version name
60
+ 'esp_MYESPACCOUNT',
61
+ 'v2') # version name
50
62
  puts result
51
63
 
52
64
  # full cc/bcc support
53
65
  result = obj.send_with(
54
- 'email_id',
66
+ 'template_id',
55
67
  { name: 'Matt', address: 'recipient@example.com' },
56
68
  { company_name: 'TestCo' },
57
69
  { name: 'Company',
@@ -71,7 +83,7 @@ begin
71
83
 
72
84
  # Attachment support
73
85
  result = obj.send_with(
74
- 'email_id',
86
+ 'template_id',
75
87
  { name: 'Matt', address: 'recipient@example.com' },
76
88
  { company_name: 'TestCo' },
77
89
  { name: 'Company',
@@ -85,7 +97,7 @@ begin
85
97
  # Set ESP account
86
98
  # See: https://help.sendwithus.com/support/solutions/articles/1000088976-set-up-and-use-multiple
87
99
  result = obj.send_with(
88
- 'email_id',
100
+ 'template_id',
89
101
  { name: 'Matt', address: 'recipient@example.com' },
90
102
  { company_name: 'TestCo' },
91
103
  { name: 'Company',
@@ -101,6 +113,30 @@ rescue => e
101
113
  end
102
114
  ```
103
115
 
116
+ ### Render a Template
117
+
118
+ - **email\_id** - *string* - Template ID being rendered
119
+ - **version\_id** - *string* - Version ID to render (optional)
120
+ - **data** - *hash* - Email data to render the template with
121
+
122
+ ```ruby
123
+ require 'rubygems'
124
+ require 'send_with_us'
125
+
126
+ begin
127
+ obj = SendWithUs::Api.new( api_key: 'YOUR API KEY', debug: true )
128
+
129
+ result = obj.render(
130
+ 'template_id',
131
+ 'version_id',
132
+ { company_name: 'TestCo' },
133
+
134
+ puts result
135
+ rescue => e
136
+ puts "Error - #{e.class.name}: #{e.message}"
137
+ end
138
+ ```
139
+
104
140
  ### Remove Customer from Drip Campaign
105
141
  ```ruby
106
142
  require 'rubygems'
@@ -141,7 +177,7 @@ begin
141
177
  # Remove customer@example.com from campaign dc_asdf1234
142
178
  result = obj.remove_from_drip_campaign('cusomter@example.com', 'dc_asdf1234')
143
179
  puts result
144
- rescue => e
180
+ rescue => e
145
181
  puts "error - #{e.class.name}: #{e.message}"
146
182
  end
147
183
  ```
@@ -190,7 +226,7 @@ In your application code where you want to send an email:
190
226
 
191
227
  ```ruby
192
228
  begin
193
- result = SendWithUs::Api.new.send_with('email_id', { address: 'recipient@example.com' }, { company_name: 'TestCo' })
229
+ result = SendWithUs::Api.new.send_with('template_id', { address: 'recipient@example.com' }, { company_name: 'TestCo' })
194
230
  puts result
195
231
  rescue => e
196
232
  puts "Error - #{e.class.name}: #{e.message}"
@@ -207,7 +243,7 @@ Take a look at our Mailer that you can use to replace ActionMailer
207
243
  The following errors may be generated:
208
244
 
209
245
  ```ruby
210
- SendWithUs::ApiInvalidEndpoint - the target URI is probably incorrect or email_id is invalid
246
+ SendWithUs::ApiInvalidEndpoint - the target URI is probably incorrect or template_id is invalid
211
247
  SendWithUs::ApiInvalidKey - the sendwithus API key is invalid
212
248
  SendWithUs::ApiBadRequest - the API request is invalid
213
249
  SendWithUs::ApiConnectionRefused - the target URI is probably incorrect
@@ -81,6 +81,17 @@ module SendWithUs
81
81
  SendWithUs::ApiRequest.new(@configuration).get(:emails)
82
82
  end
83
83
 
84
+ def render(template_id, version_id = nil, template_data = {})
85
+ payload = {
86
+ template_id: template_id,
87
+ template_data: template_data,
88
+ }
89
+ payload[:version_id] = version_id if version_id
90
+ payload = payload.to_json
91
+
92
+ SendWithUs::ApiRequest.new(@configuration).post(:'render', payload)
93
+ end
94
+
84
95
  def create_template(name, subject, html, text)
85
96
  payload = {
86
97
  name: name,
@@ -1,3 +1,3 @@
1
1
  module SendWithUs
2
- VERSION = '1.5.0'
2
+ VERSION = '1.6.0'
3
3
  end
@@ -103,6 +103,36 @@ class TestApiRequest < MiniTest::Unit::TestCase
103
103
  assert_instance_of( Net::HTTPOK, result )
104
104
  end
105
105
 
106
+ def test_render
107
+ build_objects
108
+ email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
109
+ result = @api.render(
110
+ email_id
111
+ )
112
+ assert_instance_of( Net::HTTPOK, result )
113
+ end
114
+
115
+ def test_render_with_version
116
+ build_objects
117
+ email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
118
+ result = @api.render(
119
+ email_id,
120
+ 'ver_UQuRkPN7aJjEoNfoHzvffD'
121
+ )
122
+ assert_instance_of( Net::HTTPOK, result )
123
+ end
124
+
125
+ def test_render_with_version_and_data
126
+ build_objects
127
+ email_id = 'tem_9YvYsaLW2Mw4tmPiLcVvpC'
128
+ result = @api.render(
129
+ email_id,
130
+ 'ver_UQuRkPN7aJjEoNfoHzvffD',
131
+ {'foo' => 'bar'}
132
+ )
133
+ assert_instance_of( Net::HTTPOK, result )
134
+ end
135
+
106
136
  def test_emails
107
137
  build_objects
108
138
  Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPSuccess.new(1.0, 200, "OK"))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: send_with_us
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-11-28 00:00:00.000000000 Z
14
+ date: 2014-12-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake