Skip to content

Commit 66cc93b

Browse files
committed
Fix example code
Resolves issue described in #438
1 parent 02b6a2a commit 66cc93b

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

examples/helpers/mail/example.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
require 'json'
44

55
def hello_world
6-
from = Email.new(email: '[email protected]')
6+
from = SendGrid::Email.new(email: '[email protected]')
77
subject = 'Hello World from the Twilio SendGrid Ruby Library'
8-
to = Email.new(email: '[email protected]')
9-
content = Content.new(type: 'text/plain', value: 'some text here')
8+
to = SendGrid::Email.new(email: '[email protected]')
9+
content = SendGrid::Content.new(type: 'text/plain', value: 'some text here')
1010
mail = SendGrid::Mail.new(from, subject, to, content)
1111
# puts JSON.pretty_generate(mail.to_json)
1212
puts mail.to_json
@@ -21,7 +21,7 @@ def hello_world
2121
# rubocop:disable Metrics/AbcSize
2222
def kitchen_sink
2323
mail = SendGrid::Mail.new
24-
mail.from = Email.new(email: '[email protected]')
24+
mail.from = SendGrid::Email.new(email: '[email protected]')
2525
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
2626
personalization = Personalization.new
2727
personalization.add_to(Email.new(email: '[email protected]', name: 'Example User'))
@@ -117,7 +117,7 @@ def kitchen_sink
117117
tracking_settings.ganalytics = Ganalytics.new(enable: true, utm_source: 'some source', utm_medium: 'some medium', utm_term: 'some term', utm_content: 'some content', utm_campaign: 'some campaign')
118118
mail.tracking_settings = tracking_settings
119119

120-
mail.reply_to = Email.new(email: '[email protected]')
120+
mail.reply_to = SendGrid::Email.new(email: '[email protected]')
121121

122122
# puts JSON.pretty_generate(mail.to_json)
123123
puts mail.to_json
@@ -131,9 +131,9 @@ def kitchen_sink
131131
# rubocop:enable Metrics/AbcSize
132132

133133
def dynamic_template_data_hello_world
134-
mail = Mail.new
134+
mail = SendGrid::Mail.new
135135
mail.template_id = '' # a non-legacy template id
136-
mail.from = Email.new(email: '[email protected]')
136+
mail.from = SendGrid::Email.new(email: '[email protected]')
137137
personalization = Personalization.new
138138
personalization.add_to(Email.new(email: '[email protected]', name: 'Example User'))
139139
personalization.add_dynamic_template_data(

test/sendgrid/helpers/mail/test_mail.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ class TestMail < Minitest::Test
88
def setup; end
99

1010
def test_hello_world
11-
from = Email.new(email: '[email protected]')
12-
to = Email.new(email: '[email protected]')
11+
from = SendGrid::Email.new(email: '[email protected]')
12+
to = SendGrid::Email.new(email: '[email protected]')
1313
subject = 'Sending with Twilio SendGrid is Fun'
14-
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
14+
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
1515
mail = SendGrid::Mail.new(from, subject, to, content)
1616

1717
assert_equal(mail.to_json, JSON.parse('{"from":{"email":"[email protected]"}, "subject":"Sending with Twilio SendGrid is Fun", "personalizations":[{"to":[{"email":"[email protected]"}]}], "content":[{"type":"text/plain", "value":"and easy to do anywhere, even with Ruby"}]}'))
1818
end
1919

2020
def test_kitchen_sink
2121
mail = SendGrid::Mail.new
22-
mail.from = Email.new(email: '[email protected]')
22+
mail.from = SendGrid::Email.new(email: '[email protected]')
2323
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
2424
personalization = Personalization.new
2525
personalization.add_to(Email.new(email: '[email protected]', name: 'Example User 1'))
@@ -112,7 +112,7 @@ def test_kitchen_sink
112112
tracking_settings.ganalytics = Ganalytics.new(enable: true, utm_source: 'some source', utm_medium: 'some medium', utm_term: 'some term', utm_content: 'some content', utm_campaign: 'some campaign')
113113
mail.tracking_settings = tracking_settings
114114

115-
mail.reply_to = Email.new(email: '[email protected]')
115+
mail.reply_to = SendGrid::Email.new(email: '[email protected]')
116116

117117
# rubocop:disable Layout/LineLength
118118
assert_equal(mail.to_json, JSON.parse('{"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","content_id":"Balance Sheet","disposition":"attachment","filename":"balance_001.pdf","type":"application/pdf"},{"content":"BwdW","content_id":"Banner","disposition":"inline","filename":"banner.png","type":"image/png"}],"batch_id":"sendgrid_batch_id","categories":["May","2016"],"content":[{"type":"text/plain","value":"some text here"},{"type":"text/html","value":"<html><body>some text here</body></html>"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"[email protected]"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"[email protected]","enable":true},"bypass_list_management":{"enable":true},"footer":{"enable":true,"html":"<html><body>Footer Text</body></html>","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"[email protected]","name":"Example User 5"},{"email":"[email protected]","name":"Example User 6"}],"cc":[{"email":"[email protected]","name":"Example User 3"},{"email":"[email protected]","name":"Example User 4"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"[email protected]","name":"Example User 1"},{"email":"[email protected]","name":"Example User 2"}]},{"bcc":[{"email":"[email protected]","name":"Example User 5"},{"email":"[email protected]","name":"Example User 6"}],"cc":[{"email":"[email protected]","name":"Example User 3"},{"email":"[email protected]","name":"Example User 4"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"[email protected]","name":"Example User 1"},{"email":"[email protected]","name":"Example User 2"}]}],"reply_to":{"email":"[email protected]"},"sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"send_at":1443636842,"subject":"Hello World from the Twilio SendGrid Ruby Library","template_id":"13b8f94f-bcae-4ec6-b752-70d6cb59f932","tracking_settings":{"click_tracking":{"enable":false,"enable_text":false},"ganalytics":{"enable":true,"utm_campaign":"some campaign","utm_content":"some content","utm_medium":"some medium","utm_source":"some source","utm_term":"some term"},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"html":"html to insert into the text/html portion of the message","substitution_tag":"Optional tag to replace with the open image in the body of the message","text":"text to insert into the text/plain portion of the message"}}}'))
@@ -209,7 +209,7 @@ def test_add_custom_arg
209209
end
210210

211211
def test_add_non_string_custom_arg
212-
mail = Mail.new
212+
mail = SendGrid::Mail.new
213213
mail.add_custom_arg(CustomArg.new(key: 'Integer', value: 1))
214214
mail.add_custom_arg(CustomArg.new(key: 'Array', value: [1, 'a', true]))
215215
mail.add_custom_arg(CustomArg.new(key: 'Hash', value: { 'a' => 1, 'b' => 2 }))
@@ -251,7 +251,7 @@ def test_add_invalid_category
251251
end
252252

253253
def test_check_for_secrets
254-
mail = Mail.new
254+
mail = SendGrid::Mail.new
255255
mail.add_content(Content.new(type: 'text/plain', value: 'Sensitive information: SG.a123b456'))
256256
assert_raises(SecurityError) do
257257
mail.check_for_secrets([/SG.[a-zA-Z0-9_-]*/])

use-cases/legacy-templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require 'sendgrid-ruby'
3838
include SendGrid
3939

4040
mail = SendGrid::Mail.new
41-
mail.from = Email.new(email: '[email protected]')
41+
mail.from = SendGrid::Email.new(email: '[email protected]')
4242
mail.subject = 'I\'m replacing the subject tag'
4343
personalization = Personalization.new
4444
personalization.add_to(Email.new(email: '[email protected]'))

use-cases/personalizations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ require 'sendgrid-ruby'
77
include SendGrid
88

99
# Note that the domain for all From addresses must match
10-
mail = Mail.new
11-
mail.from = Email.new(email: '[email protected]')
10+
mail = SendGrid::Mail.new
11+
mail.from = SendGrid::Email.new(email: '[email protected]')
1212
mail.add_content(Content.new(type: 'text/plain', value: 'Some test text'))
1313
mail.subject = 'Personalized Test Email'
1414

@@ -31,4 +31,4 @@ end
3131
puts response.status_code
3232
puts response.body
3333
puts response.headers
34-
```
34+
```

use-cases/transactional-templates.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Template Body:
3434
require 'sendgrid-ruby'
3535
include SendGrid
3636

37-
mail = Mail.new
38-
mail.from = Email.new(email: '[email protected]')
37+
mail = SendGrid::Mail.new
38+
mail.from = SendGrid::Email.new(email: '[email protected]')
3939
personalization = Personalization.new
4040
personalization.add_to(Email.new(email: '[email protected]'))
4141
personalization.add_dynamic_template_data({

0 commit comments

Comments
 (0)