Skip to content

docs: Fixes documented example code #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/helpers/mail/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
require 'json'

def hello_world
from = Email.new(email: '[email protected]')
from = SendGrid::Email.new(email: '[email protected]')
subject = 'Hello World from the Twilio SendGrid Ruby Library'
to = Email.new(email: '[email protected]')
content = Content.new(type: 'text/plain', value: 'some text here')
to = SendGrid::Email.new(email: '[email protected]')
content = SendGrid::Content.new(type: 'text/plain', value: 'some text here')
mail = SendGrid::Mail.new(from, subject, to, content)
# puts JSON.pretty_generate(mail.to_json)
puts mail.to_json
Expand All @@ -21,7 +21,7 @@ def hello_world
# rubocop:disable Metrics/AbcSize
def kitchen_sink
mail = SendGrid::Mail.new
mail.from = Email.new(email: '[email protected]')
mail.from = SendGrid::Email.new(email: '[email protected]')
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
personalization = Personalization.new
personalization.add_to(Email.new(email: '[email protected]', name: 'Example User'))
Expand Down Expand Up @@ -117,7 +117,7 @@ def kitchen_sink
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')
mail.tracking_settings = tracking_settings

mail.reply_to = Email.new(email: '[email protected]')
mail.reply_to = SendGrid::Email.new(email: '[email protected]')

# puts JSON.pretty_generate(mail.to_json)
puts mail.to_json
Expand All @@ -131,9 +131,9 @@ def kitchen_sink
# rubocop:enable Metrics/AbcSize

def dynamic_template_data_hello_world
mail = Mail.new
mail = SendGrid::Mail.new
mail.template_id = '' # a non-legacy template id
mail.from = Email.new(email: '[email protected]')
mail.from = SendGrid::Email.new(email: '[email protected]')
personalization = Personalization.new
personalization.add_to(Email.new(email: '[email protected]', name: 'Example User'))
personalization.add_dynamic_template_data(
Expand Down
14 changes: 7 additions & 7 deletions test/sendgrid/helpers/mail/test_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class TestMail < Minitest::Test
def setup; end

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

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"}]}'))
end

def test_kitchen_sink
mail = SendGrid::Mail.new
mail.from = Email.new(email: '[email protected]')
mail.from = SendGrid::Email.new(email: '[email protected]')
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
personalization = Personalization.new
personalization.add_to(Email.new(email: '[email protected]', name: 'Example User 1'))
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_kitchen_sink
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')
mail.tracking_settings = tracking_settings

mail.reply_to = Email.new(email: '[email protected]')
mail.reply_to = SendGrid::Email.new(email: '[email protected]')

# rubocop:disable Layout/LineLength
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"}}}'))
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_add_custom_arg
end

def test_add_non_string_custom_arg
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_custom_arg(CustomArg.new(key: 'Integer', value: 1))
mail.add_custom_arg(CustomArg.new(key: 'Array', value: [1, 'a', true]))
mail.add_custom_arg(CustomArg.new(key: 'Hash', value: { 'a' => 1, 'b' => 2 }))
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_add_invalid_category
end

def test_check_for_secrets
mail = Mail.new
mail = SendGrid::Mail.new
mail.add_content(Content.new(type: 'text/plain', value: 'Sensitive information: SG.a123b456'))
assert_raises(SecurityError) do
mail.check_for_secrets([/SG.[a-zA-Z0-9_-]*/])
Expand Down
2 changes: 1 addition & 1 deletion use-cases/legacy-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require 'sendgrid-ruby'
include SendGrid

mail = SendGrid::Mail.new
mail.from = Email.new(email: '[email protected]')
mail.from = SendGrid::Email.new(email: '[email protected]')
mail.subject = 'I\'m replacing the subject tag'
personalization = Personalization.new
personalization.add_to(Email.new(email: '[email protected]'))
Expand Down
6 changes: 3 additions & 3 deletions use-cases/personalizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ require 'sendgrid-ruby'
include SendGrid

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

Expand All @@ -31,4 +31,4 @@ end
puts response.status_code
puts response.body
puts response.headers
```
```
4 changes: 2 additions & 2 deletions use-cases/transactional-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Template Body:
require 'sendgrid-ruby'
include SendGrid

mail = Mail.new
mail.from = Email.new(email: '[email protected]')
mail = SendGrid::Mail.new
mail.from = SendGrid::Email.new(email: '[email protected]')
personalization = Personalization.new
personalization.add_to(Email.new(email: '[email protected]'))
personalization.add_dynamic_template_data({
Expand Down
Loading