sendgrid-ruby 1.1.6 → 6.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +21 -0
  3. data/.env_sample +1 -3
  4. data/.gitignore +1 -0
  5. data/.travis.yml +28 -17
  6. data/CHANGELOG.md +231 -1
  7. data/CODE_OF_CONDUCT.md +73 -0
  8. data/CONTRIBUTING.md +214 -0
  9. data/Gemfile +5 -4
  10. data/ISSUE_TEMPLATE.md +26 -0
  11. data/LICENSE.md +21 -0
  12. data/Makefile +7 -0
  13. data/PULL_REQUEST_TEMPLATE.md +31 -0
  14. data/README.md +161 -225
  15. data/Rakefile +9 -2
  16. data/TROUBLESHOOTING.md +137 -0
  17. data/UPGRADE.md +5 -0
  18. data/USAGE.md +5037 -0
  19. data/USE_CASES.md +377 -0
  20. data/config.ru +4 -0
  21. data/docker/Dockerfile +12 -0
  22. data/docker/README.md +30 -0
  23. data/examples/accesssettings/accesssettings.rb +83 -0
  24. data/examples/alerts/alerts.rb +62 -0
  25. data/examples/apikeys/apikeys.rb +84 -0
  26. data/examples/asm/asm.rb +173 -0
  27. data/examples/browsers/browsers.rb +16 -0
  28. data/examples/campaigns/campaigns.rb +153 -0
  29. data/examples/categories/categories.rb +36 -0
  30. data/examples/clients/clients.rb +27 -0
  31. data/examples/contactdb/contactdb.rb +395 -0
  32. data/examples/devices/devices.rb +16 -0
  33. data/examples/geo/geo.rb +16 -0
  34. data/examples/helpers/mail/example.rb +147 -0
  35. data/examples/helpers/settings/example.rb +23 -0
  36. data/examples/helpers/stats/example.rb +42 -0
  37. data/examples/ips/ips.rb +167 -0
  38. data/examples/mail/mail.rb +173 -0
  39. data/examples/mailboxproviders/mailboxproviders.rb +16 -0
  40. data/examples/mailsettings/mailsettings.rb +219 -0
  41. data/examples/partnersettings/partnersettings.rb +39 -0
  42. data/examples/scopes/scopes.rb +61 -0
  43. data/examples/senderauthentication/senderauthentication.rb +310 -0
  44. data/examples/senders/senders.rb +98 -0
  45. data/examples/stats/stats.rb +16 -0
  46. data/examples/subusers/subusers.rb +169 -0
  47. data/examples/suppression/suppression.rb +201 -0
  48. data/examples/templates/templates.rb +129 -0
  49. data/examples/trackingsettings/trackingsettings.rb +110 -0
  50. data/examples/user/user.rb +293 -0
  51. data/gemfiles/Sinatra_1.gemfile +6 -0
  52. data/gemfiles/Sinatra_2.gemfile +6 -0
  53. data/lib/sendgrid/client.rb +33 -57
  54. data/lib/sendgrid/helpers/inbound/README.md +98 -0
  55. data/lib/sendgrid/helpers/inbound/app.rb +32 -0
  56. data/lib/sendgrid/helpers/inbound/config.yml +26 -0
  57. data/lib/sendgrid/helpers/inbound/public/index.html +10 -0
  58. data/lib/sendgrid/helpers/inbound/sample_data/default_data.txt +58 -0
  59. data/lib/sendgrid/helpers/inbound/sample_data/raw_data.txt +57 -0
  60. data/lib/sendgrid/helpers/inbound/sample_data/raw_data_with_attachments.txt +298 -0
  61. data/lib/sendgrid/helpers/inbound/send.rb +26 -0
  62. data/lib/sendgrid/helpers/ip_management/ip_management.rb +17 -0
  63. data/lib/sendgrid/helpers/mail/README.md +14 -0
  64. data/lib/sendgrid/helpers/mail/asm.rb +33 -0
  65. data/lib/sendgrid/helpers/mail/attachment.rb +86 -0
  66. data/lib/sendgrid/helpers/mail/bcc_settings.rb +33 -0
  67. data/lib/sendgrid/helpers/mail/bypass_list_management.rb +43 -0
  68. data/lib/sendgrid/helpers/mail/category.rb +20 -0
  69. data/lib/sendgrid/helpers/mail/click_tracking.rb +33 -0
  70. data/lib/sendgrid/helpers/mail/content.rb +20 -0
  71. data/lib/sendgrid/helpers/mail/custom_arg.rb +24 -0
  72. data/lib/sendgrid/helpers/mail/email.rb +29 -0
  73. data/lib/sendgrid/helpers/mail/footer.rb +43 -0
  74. data/lib/sendgrid/helpers/mail/ganalytics.rb +74 -0
  75. data/lib/sendgrid/helpers/mail/header.rb +24 -0
  76. data/lib/sendgrid/helpers/mail/mail.rb +140 -0
  77. data/lib/sendgrid/helpers/mail/mail_settings.rb +63 -0
  78. data/lib/sendgrid/helpers/mail/open_tracking.rb +33 -0
  79. data/lib/sendgrid/helpers/mail/personalization.rb +82 -0
  80. data/lib/sendgrid/helpers/mail/section.rb +24 -0
  81. data/lib/sendgrid/helpers/mail/spam_check.rb +43 -0
  82. data/lib/sendgrid/helpers/mail/subscription_tracking.rb +53 -0
  83. data/lib/sendgrid/helpers/mail/substitution.rb +24 -0
  84. data/lib/sendgrid/helpers/mail/tracking_settings.rb +53 -0
  85. data/lib/sendgrid/helpers/permissions/scope.rb +28 -0
  86. data/lib/sendgrid/helpers/permissions/scopes.yml +309 -0
  87. data/lib/sendgrid/helpers/settings/README.md +14 -0
  88. data/lib/sendgrid/helpers/settings/mail_settings_dto.rb +13 -0
  89. data/lib/sendgrid/helpers/settings/partner_settings_dto.rb +13 -0
  90. data/lib/sendgrid/helpers/settings/settings.rb +28 -0
  91. data/lib/sendgrid/helpers/settings/tracking_settings_dto.rb +24 -0
  92. data/lib/sendgrid/helpers/settings/user_settings_dto.rb +13 -0
  93. data/lib/sendgrid/helpers/stats/email_stats.rb +46 -0
  94. data/lib/sendgrid/helpers/stats/metrics.rb +35 -0
  95. data/lib/sendgrid/helpers/stats/stats_response.rb +31 -0
  96. data/lib/sendgrid/version.rb +1 -1
  97. data/lib/sendgrid-ruby.rb +27 -6
  98. data/mail_helper_v3.md +390 -0
  99. data/sendgrid-ruby.gemspec +13 -17
  100. data/spec/sendgrid/helpers/ip_management/ip_management_spec.rb +12 -0
  101. data/spec/sendgrid/helpers/settings/mail_settings_dto_spec.rb +32 -0
  102. data/spec/sendgrid/helpers/settings/partner_settings_dto_spec.rb +24 -0
  103. data/spec/sendgrid/helpers/settings/settings_spec.rb +25 -0
  104. data/spec/sendgrid/helpers/settings/tracking_settings_dto_spec.rb +27 -0
  105. data/spec/sendgrid/helpers/settings/user_settings_dto_spec.rb +24 -0
  106. data/spec/sendgrid/helpers/stats/email_stats_spec.rb +112 -0
  107. data/spec/sendgrid/helpers/stats/metrics_spec.rb +46 -0
  108. data/spec/sendgrid/helpers/stats/stats_response_spec.rb +76 -0
  109. data/spec/spec_helper.rb +10 -1
  110. data/test/prism.sh +42 -0
  111. data/test/sendgrid/helpers/mail/test_attachment.rb +35 -0
  112. data/test/sendgrid/helpers/mail/test_category.rb +27 -0
  113. data/test/sendgrid/helpers/mail/test_email.rb +34 -0
  114. data/test/sendgrid/helpers/mail/test_mail.rb +261 -0
  115. data/test/sendgrid/helpers/mail/test_personalizations.rb +161 -0
  116. data/test/sendgrid/permissions/test_scopes.rb +38 -0
  117. data/test/sendgrid/test_sendgrid-ruby.rb +2751 -0
  118. metadata +149 -115
  119. data/.rspec +0 -2
  120. data/.rubocop.yml +0 -30
  121. data/FETCH_HEAD +0 -0
  122. data/Guardfile +0 -10
  123. data/LICENSE.txt +0 -22
  124. data/example.rb +0 -41
  125. data/lib/sendgrid/exceptions.rb +0 -7
  126. data/lib/sendgrid/mail.rb +0 -182
  127. data/lib/sendgrid/recipient.rb +0 -29
  128. data/lib/sendgrid/response.rb +0 -14
  129. data/lib/sendgrid/template.rb +0 -26
  130. data/lib/sendgrid/template_mailer.rb +0 -59
  131. data/spec/lib/sendgrid/client_spec.rb +0 -87
  132. data/spec/lib/sendgrid/mail_spec.rb +0 -151
  133. data/spec/lib/sendgrid/recipient_spec.rb +0 -91
  134. data/spec/lib/sendgrid/template_mailer_spec.rb +0 -86
  135. data/spec/lib/sendgrid/template_spec.rb +0 -61
  136. data/spec/lib/sendgrid_spec.rb +0 -7
data/mail_helper_v3.md ADDED
@@ -0,0 +1,390 @@
1
+ Hello!
2
+
3
+ It is now time to implement the final piece of our v2 to v3 migration. Before we dig into writing the code, we would love to get feedback on the following proposed interfaces.
4
+
5
+ We are starting with the use cases below for the first iteration. (we have completed this work on [our C# library](https://github.com/sendgrid/sendgrid-csharp/blob/master/USE_CASES.md), you can check that out for a sneak peek of where we are heading).
6
+
7
+ # Send a Single Email to a Single Recipient
8
+
9
+ The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.
10
+
11
+ ```ruby
12
+ require 'sendgrid-ruby'
13
+
14
+ from = SendGrid::Email.new('test@example.com', 'Example User')
15
+ to = SendGrid::Email.new('test@example.com', 'Example User')
16
+ subject = 'Sending with Twilio SendGrid is Fun'
17
+ plain_text_content = 'and easy to do anywhere, even with Ruby'
18
+ html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
19
+ msg = SendGrid::Mail.create(from: from,
20
+ tos: to,
21
+ subject: subject,
22
+ plain_text_content: plain_text_content,
23
+ html_content: html_content,
24
+ substitutions: {})
25
+
26
+ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
27
+
28
+ begin
29
+ response = client.send_email(msg)
30
+ rescue Exception => e
31
+ puts e.message
32
+ end
33
+ puts response.status_code
34
+ puts response.body
35
+ puts response.headers
36
+ ```
37
+
38
+ # Send a Single Email to Multiple Recipients
39
+
40
+ The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.
41
+
42
+ ```ruby
43
+ require 'sendgrid-ruby'
44
+
45
+ from = SendGrid::Email.new('test@example.com', 'Example User')
46
+ tos = [
47
+ SendGrid::Email.new('test1@example.com', 'Example User1'),
48
+ SendGrid::Email.new('test2@example.com', 'Example User2'),
49
+ SendGrid::Email.new('test3@example.com', 'Example User3')
50
+ ];
51
+ subject = 'Sending with Twilio SendGrid is Fun'
52
+ plain_text_content = 'and easy to do anywhere, even with Ruby'
53
+ html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
54
+ msg = SendGrid::Mail.create(from: from,
55
+ tos: tos,
56
+ subject: subject,
57
+ plain_text_content: plain_text_content,
58
+ html_content: html_content,
59
+ substitutions: {})
60
+
61
+ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
62
+
63
+ begin
64
+ response = client.send_email(msg)
65
+ rescue Exception => e
66
+ puts e.message
67
+ end
68
+ puts response.status_code
69
+ puts response.body
70
+ puts response.headers
71
+ ```
72
+
73
+ # Send Multiple Emails to Multiple Recipients
74
+
75
+ The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.
76
+
77
+ ```ruby
78
+ require 'sendgrid-ruby'
79
+
80
+ from = SendGrid::Email.new('test@example.com', 'Example User')
81
+ tos = [
82
+ SendGrid::Email.new('test1@example.com', 'Example User1'),
83
+ SendGrid::Email.new('test2@example.com', 'Example User2'),
84
+ SendGrid::Email.new('test3@example.com', 'Example User3')
85
+ ];
86
+ subjects = [
87
+ 'Sending with Twilio SendGrid is Fun',
88
+ 'Sending with Twilio SendGrid is Super Fun',
89
+ 'Sending with Twilio SendGrid is Super Duper Fun'
90
+ ];
91
+ plain_text_content = 'and easy to do anywhere, even with Ruby'
92
+ html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
93
+ values = [
94
+ 'Name 1',
95
+ 'Name 2',
96
+ 'Name 3'
97
+ ]
98
+ substitutions = {
99
+ '-name1-' => values
100
+ }
101
+ msg = SendGrid::Mail.create(from: from,
102
+ tos: tos,
103
+ subject: subjects,
104
+ plain_text_content: plain_text_content,
105
+ html_content: html_content,
106
+ substitutions: substitutions)
107
+
108
+ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
109
+
110
+ begin
111
+ response = client.send_email(msg)
112
+ rescue Exception => e
113
+ puts e.message
114
+ end
115
+ puts response.status_code
116
+ puts response.body
117
+ puts response.headers
118
+ ```
119
+
120
+ # Kitchen Sink - an example with all settings used
121
+
122
+ The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.
123
+
124
+ ```ruby
125
+ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
126
+
127
+ from = SendGrid::Email.new('test@example.com', 'Example User')
128
+ to = SendGrid::Email.new('test@example.com', 'Example User')
129
+ subject = 'Sending with Twilio SendGrid is Fun'
130
+ plain_text_content = 'and easy to do anywhere, even with Ruby'
131
+ html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
132
+ msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
133
+
134
+ # For a detailed description of each of these settings, please see the [documentation](https://sendgrid.com/docs/API_Reference/api_v3.html).
135
+
136
+ msg.add_to(SendGrid::Email.new('test1@example.com', 'Example User1'))
137
+ to_emails = [
138
+ SendGrid::Email.new('test2@example.com', 'Example User2'),
139
+ SendGrid::Email.new('test3@example.com', 'Example User3')
140
+ ];
141
+ msg.add_tos(to_emails)
142
+
143
+ msg.add_cc(SendGrid::Email.new('test4@example.com', 'Example User4'))
144
+ cc_emails = [
145
+ SendGrid::Email.new('test5@example.com', 'Example User5'),
146
+ SendGrid::Email.new('test6@example.com', 'Example User6')
147
+ ];
148
+ msg.add_ccs(cc_emails)
149
+
150
+ msg.add_bcc(SendGrid::Email.new('test7@example.com', 'Example User7'))
151
+ bcc_emails = [
152
+ SendGrid::Email.new('test8@example.com', 'Example User8'),
153
+ SendGrid::Email.new('test9@example.com', 'Example User9')
154
+ ];
155
+ msg.add_bccs(bcc_emails)
156
+
157
+ msg.add_header('X-Test1', 'Test1')
158
+ msg.add_header('X-Test2', 'Test2')
159
+ headers = [
160
+ 'X-Test3' => 'Test3',
161
+ 'X-Test4' => 'Test4'
162
+ ]
163
+ msg.add_headers(headers)
164
+
165
+ msg.add_substitution('%name1%', 'Example Name 1');
166
+ msg.add_substitution('%city1%', 'Denver');
167
+ substitutions = [
168
+ '%name2%' => 'Example Name 2',
169
+ '%city2%' => 'Orange'
170
+ ]
171
+ msg.add_substitutions(substitutions)
172
+
173
+ msg.add_custom_arg('marketing1', 'false')
174
+ msg.add_custom_arg('transactional1', 'true')
175
+ custom_args = [
176
+ 'marketing2' => 'true',
177
+ 'transactional2' => 'false'
178
+ ]
179
+ msg.add_custom_args(custom_args)
180
+
181
+ msg.set_send_at(1461775051)
182
+
183
+ msg.set_subject('this subject overrides the Global Subject on the default Personalization')
184
+
185
+ # If you need to add more [Personalizations](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html), here is an example of adding another Personalization by passing in a personalization index.
186
+
187
+ msg.add_to(SendGrid::Email.new('test10@example.com', 'Example User10'), 1)
188
+ to_emails = [
189
+ SendGrid::Email.new('test11@example.com', 'Example User11'),
190
+ SendGrid::Email.new('test12@example.com', 'Example User12')
191
+ ];
192
+ msg.add_tos(to_emails, 1)
193
+
194
+ msg.add_cc(SendGrid::Email.new('test13@example.com', 'Example User13'), 1)
195
+ cc_emails = [
196
+ SendGrid::Email.new('test14@example.com', 'Example User14'),
197
+ SendGrid::Email.new('test15@example.com', 'Example User15')
198
+ ];
199
+ msg.add_ccs(cc_emails, 1)
200
+
201
+ msg.add_bcc(SendGrid::Email.new('test16@example.com', 'Example User16'), 1)
202
+ bcc_emails = [
203
+ SendGrid::Email.new('test17@example.com', 'Example User17'),
204
+ SendGrid::Email.new('test18@example.com', 'Example User18')
205
+ ];
206
+ msg.add_bccs(bcc_emails, 1)
207
+
208
+ msg.add_header('X-Test5', 'Test5', 1)
209
+ msg.add_header('X-Test6', 'Test6', 1)
210
+ headers = [
211
+ 'X-Test7' => 'Test7',
212
+ 'X-Test8' => 'Test8'
213
+ ]
214
+ msg.add_headers(headers, 1)
215
+
216
+ msg.add_substitution('%name3%', 'Example Name 3', 1);
217
+ msg.add_substitution('%city3%', 'Redwood City', 1);
218
+ substitutions = [
219
+ '%name4%' => 'Example Name 4',
220
+ '%city4%' => 'London'
221
+ ]
222
+ msg.add_substitutions(substitutions, 1)
223
+
224
+ msg.add_custom_arg('marketing3', 'true', 1)
225
+ msg.add_custom_arg('transactional3', 'false', 1)
226
+ custom_args = [
227
+ 'marketing4' => 'false',
228
+ 'transactional4' => 'true'
229
+ ]
230
+ msg.add_custom_args(custom_args, 1)
231
+
232
+ msg.set_send_at(1461775052, 1)
233
+
234
+ msg.set_subject('this subject overrides the Global Subject on the second Personalization', 1)
235
+
236
+ # The values below this comment are global to entire message
237
+
238
+ msg.set_from(SendGrid::Email.new('test0@example.com', 'Example User0'))
239
+
240
+ msg.set_global_subject('Sending with Twilio SendGrid is Fun');
241
+
242
+ msg.add_content(MimeType::Text, 'and easy to do anywhere, even with Ruby')
243
+ msg.add_content(MimeType::Html, '<strong>and easy to do anywhere, even with Ruby</strong>')
244
+ contents = [
245
+ SendGrid::Content.new('text/calendar', 'Party Time!!'),
246
+ SendGrid::Content.new('text/calendar2', 'Party Time 2!!')
247
+ ]
248
+ msg.add_contents(contents)
249
+
250
+ msg.add_attachment('balance_001.pdf',
251
+ 'base64 encoded content',
252
+ 'application/pdf',
253
+ 'attachment',
254
+ 'Balance Sheet')
255
+
256
+ attachments = [
257
+ SendGrid::Attachment.new('banner.png',
258
+ 'base64 encoded content',
259
+ 'image/png',
260
+ 'inline',
261
+ 'Banner'),
262
+ SendGrid::Attachment.new('banner2.png',
263
+ 'base64 encoded content',
264
+ 'image/png',
265
+ 'inline',
266
+ 'Banner 2'),
267
+ ]
268
+ msg.add_attachments(attachments)
269
+
270
+ msg.set_template_id('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
271
+
272
+ msg.add_global_header('X-Day', 'Monday')
273
+ global_headers = [
274
+ 'X-Month' => 'January',
275
+ 'X-Year' => '2017'
276
+ ]
277
+ msg.set_global_headers(global_headers)
278
+
279
+ msg.add_section('%section1%', 'Substitution for Section 1 Tag')
280
+ sections = [
281
+ '%section2%' => 'Substitution for Section 2 Tag',
282
+ '%section3%' => 'Substitution for Section 3 Tag'
283
+ ]
284
+ msg.add_sections(sections)
285
+
286
+ begin
287
+ response = client.send_email(msg)
288
+ rescue Exception => e
289
+ puts e.message
290
+ end
291
+ puts response.status_code
292
+ puts response.body
293
+ puts response.headers
294
+ ```
295
+
296
+ # Attachments
297
+
298
+ The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.
299
+
300
+ ```ruby
301
+ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
302
+
303
+ from = SendGrid::Email.new('test@example.com', 'Example User')
304
+ to = SendGrid::Email.new('test@example.com', 'Example User')
305
+ subject = 'Sending with Twilio SendGrid is Fun'
306
+ plain_text_content = 'and easy to do anywhere, even with Ruby'
307
+ html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
308
+ msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
309
+ bytes = File.read('/path/to/the/attachment.pdf')
310
+ encoded = Base64.encode64(bytes)
311
+ msg.add_attachment('balance_001.pdf',
312
+ encoded,
313
+ 'application/pdf',
314
+ 'attachment',
315
+ 'Balance Sheet')
316
+
317
+ begin
318
+ response = client.send_email(msg)
319
+ rescue Exception => e
320
+ puts e.message
321
+ end
322
+ puts response.status_code
323
+ puts response.body
324
+ puts response.headers
325
+ ```
326
+
327
+ # Transactional Templates
328
+
329
+ The following code assumes you are storing the API key in an [environment variable (recommended)](https://github.com/sendgrid/sendgrid-ruby/blob/master/TROUBLESHOOTING.md#environment-variables-and-your-sendgrid-api-key). If you don't have your key stored in an environment variable, you can assign it directly to `api_key` for testing purposes.
330
+
331
+ For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.
332
+
333
+ Template ID (replace with your own):
334
+
335
+ ```text
336
+ 13b8f94f-bcae-4ec6-b752-70d6cb59f932
337
+ ```
338
+
339
+ Email Subject:
340
+
341
+ ```text
342
+ <%subject%>
343
+ ```
344
+
345
+ Template Body:
346
+
347
+ ```html
348
+ <html>
349
+ <head>
350
+ <title></title>
351
+ </head>
352
+ <body>
353
+ Hello -name-,
354
+ <br /><br/>
355
+ I'm glad you are trying out the template feature!
356
+ <br /><br/>
357
+ <%body%>
358
+ <br /><br/>
359
+ I hope you are having a great day in -city- :)
360
+ <br /><br/>
361
+ </body>
362
+ </html>
363
+ ```
364
+
365
+ ```ruby
366
+ client = SendGrid::Client.new(api_key: ENV['SENDGRID_API_KEY'])
367
+
368
+ from = SendGrid::Email.new('test@example.com', 'Example User')
369
+ to = SendGrid::Email.new('test@example.com', 'Example User')
370
+ subject = 'Sending with Twilio SendGrid is Fun'
371
+ plain_text_content = 'and easy to do anywhere, even with Ruby'
372
+ html_content = '<strong>and easy to do anywhere, even with Ruby</strong>'
373
+ msg = SendGrid::Message.new(from, to, subject, plain_text_content, html_content)
374
+
375
+ substitutions = [
376
+ '-name-' => 'Example User',
377
+ '-city-' => 'Denver'
378
+ ]
379
+ msg.add_substitutions(substitutions)
380
+ msg.set_template_id('13b8f94f-bcae-4ec6-b752-70d6cb59f932')
381
+
382
+ begin
383
+ response = client.send_email(msg)
384
+ rescue Exception => e
385
+ puts e.message
386
+ end
387
+ puts response.status_code
388
+ puts response.body
389
+ puts response.headers
390
+ ```
@@ -6,29 +6,25 @@ require 'sendgrid/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'sendgrid-ruby'
8
8
  spec.version = SendGrid::VERSION
9
- spec.authors = ['Robin Johnson', 'Eddie Zaneski']
10
- spec.email = 'community@sendgrid.com'
11
- spec.summary = 'Official SendGrid Gem'
12
- spec.description = 'Interact with SendGrids API in native Ruby'
9
+ spec.authors = ['Elmer Thomas', 'Robin Johnson', 'Eddie Zaneski']
10
+ spec.email = 'dx@sendgrid.com'
11
+ spec.summary = 'Official Twilio SendGrid Gem'
12
+ spec.description = 'Official Twilio SendGrid Gem to Interact with Twilio SendGrids API in native Ruby'
13
13
  spec.homepage = 'http://github.com/sendgrid/sendgrid-ruby'
14
- spec.license = 'MIT'
15
14
 
15
+ spec.required_ruby_version = '>= 2.2'
16
+
17
+ spec.license = 'MIT'
16
18
  spec.files = `git ls-files -z`.split("\x0")
17
19
  spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
18
20
  spec.test_files = spec.files.grep(/^(test|spec|features)/)
19
21
  spec.require_paths = ['lib']
20
-
21
- spec.add_dependency 'smtpapi', '~> 0.1'
22
- spec.add_dependency 'faraday', '~> 0.9'
23
- spec.add_dependency 'mimemagic'
24
- spec.add_development_dependency 'rake'
22
+ spec.add_dependency 'ruby_http_client', '~> 3.3.0'
23
+ spec.add_development_dependency 'sinatra', '>= 1.4.7', '< 3'
24
+ spec.add_development_dependency 'rake', '~> 0'
25
25
  spec.add_development_dependency 'rspec'
26
- spec.add_development_dependency 'rspec-nc'
27
- spec.add_development_dependency 'webmock'
28
- spec.add_development_dependency 'guard'
29
- spec.add_development_dependency 'guard-rspec'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'faker'
30
28
  spec.add_development_dependency 'rubocop'
31
- spec.add_development_dependency 'guard-rubocop'
32
- spec.add_development_dependency 'ruby_gntp'
33
- spec.add_development_dependency 'bundler', '~> 1.6'
29
+ spec.add_development_dependency 'minitest', '~> 5.9'
34
30
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendGrid::IpManagement do
4
+ let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
5
+ let(:ip_management) { SendGrid::IpManagement.new(sendgrid_client: sendgrid_client) }
6
+
7
+ describe '.new' do
8
+ it 'initializes correctly' do
9
+ expect(ip_management).to be_a SendGrid::IpManagement
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendGrid::MailSettingsDto do
4
+ let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
5
+ let(:mail_settings) { SendGrid::MailSettingsDto }
6
+ let(:setting_name) { 'bcc' }
7
+ let(:setting_params) { {email: Faker::Internet.email, enabled: rand(1..100).even?} }
8
+
9
+ it { should respond_to :bcc }
10
+ it { should respond_to :address_whitelist }
11
+ it { should respond_to :bounce_purge }
12
+ it { should respond_to :footer }
13
+ it { should respond_to :forward_spam }
14
+ it { should respond_to :forward_bounce }
15
+ it { should respond_to :plain_content }
16
+ it { should respond_to :spam_check }
17
+ it { should respond_to :template }
18
+
19
+ describe '.fetch' do
20
+ it 'calls get on sendgrid_client' do
21
+ args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
22
+ expect(mail_settings.fetch(args)).to be_a SendGrid::Response
23
+ end
24
+ end
25
+
26
+ describe '.update' do
27
+ it 'calls patch on sendgrid_client' do
28
+ args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
29
+ expect(mail_settings.update(args)).to be_a SendGrid::Response
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendGrid::PartnerSettingsDto do
4
+ let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
5
+ let(:partner_settings) { SendGrid::PartnerSettingsDto }
6
+ let(:setting_name) { 'new_relic' }
7
+ let(:setting_params) { {license_key: 'key', enabled: rand(1..100).even?} }
8
+
9
+ it { should respond_to :new_relic }
10
+
11
+ describe '.fetch' do
12
+ it 'calls get on sendgrid_client' do
13
+ args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
14
+ expect(partner_settings.fetch(args)).to be_a SendGrid::Response
15
+ end
16
+ end
17
+
18
+ describe '.update' do
19
+ it 'calls patch on sendgrid_client' do
20
+ args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
21
+ expect(partner_settings.update(args)).to be_a SendGrid::Response
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendGrid::Settings do
4
+ let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
5
+ let(:settings) { SendGrid::Settings.new(sendgrid_client: sendgrid_client) }
6
+
7
+ describe '.new' do
8
+ it 'initializes correctly' do
9
+ expect(settings).to be_a SendGrid::Settings
10
+ end
11
+ end
12
+
13
+ describe '.bcc' do
14
+ it 'fetches bcc data' do
15
+ expect(settings.bcc).to be_a SendGrid::Response
16
+ end
17
+ end
18
+
19
+ describe '.update_bcc' do
20
+ it 'updates bcc' do
21
+ bcc_response = settings.update_bcc(enabled: true, email: "email@example.com")
22
+ expect(bcc_response).to be_a SendGrid::Response
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendGrid::TrackingSettingsDto do
4
+ let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
5
+ let(:tracking_settings) { SendGrid::TrackingSettingsDto }
6
+ let(:setting_name) { 'open_tracking' }
7
+ let(:setting_params) { {enabled: rand(1..100).even?} }
8
+
9
+ it { should respond_to :open_tracking }
10
+ it { should respond_to :click_tracking }
11
+ it { should respond_to :google_analytics }
12
+ it { should respond_to :subscription_tracking }
13
+
14
+ describe '.fetch' do
15
+ it 'calls get on sendgrid_client' do
16
+ args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
17
+ expect(tracking_settings.fetch(args)).to be_a SendGrid::Response
18
+ end
19
+ end
20
+
21
+ describe '.update' do
22
+ it 'calls patch on sendgrid_client' do
23
+ args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
24
+ expect(tracking_settings.update(args)).to be_a SendGrid::Response
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe SendGrid::UserSettingsDto do
4
+ let(:sendgrid_client) { SendGrid::API.new(api_key: 'fake_key').client }
5
+ let(:user_settings) { SendGrid::UserSettingsDto }
6
+ let(:setting_name) { 'enforced_tls' }
7
+ let(:setting_params) { {require_tls: rand(1..100).even?} }
8
+
9
+ it { should respond_to :enforced_tls }
10
+
11
+ describe '.fetch' do
12
+ it 'calls get on sendgrid_client' do
13
+ args = { sendgrid_client: sendgrid_client, name: setting_name, query_params: {} }
14
+ expect(user_settings.fetch(args)).to be_a SendGrid::Response
15
+ end
16
+ end
17
+
18
+ describe '.update' do
19
+ it 'calls patch on sendgrid_client' do
20
+ args = { sendgrid_client: sendgrid_client, name: setting_name, request_body: setting_params }
21
+ expect(user_settings.update(args)).to be_a SendGrid::Response
22
+ end
23
+ end
24
+ end