Skip to content
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: 'test@example.com')
from = SendGrid::Email.new(email: 'test@example.com')
subject = 'Hello World from the Twilio SendGrid Ruby Library'
to = Email.new(email: 'test@example.com')
content = Content.new(type: 'text/plain', value: 'some text here')
to = SendGrid::Email.new(email: 'test@example.com')
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: 'test@example.com')
mail.from = SendGrid::Email.new(email: 'test@example.com')
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
personalization = Personalization.new
personalization.add_to(Email.new(email: 'test1@example.com', 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: 'test@example.com')
mail.reply_to = SendGrid::Email.new(email: 'test@example.com')

# 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: 'test@example.com')
mail.from = SendGrid::Email.new(email: 'test@example.com')
personalization = Personalization.new
personalization.add_to(Email.new(email: 'test1@example.com', 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: 'test@example.com')
to = Email.new(email: 'test@example.com')
from = SendGrid::Email.new(email: 'test@example.com')
to = SendGrid::Email.new(email: 'test@example.com')
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":"test@example.com"}, "subject":"Sending with Twilio SendGrid is Fun", "personalizations":[{"to":[{"email":"test@example.com"}]}], "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: 'test@example.com')
mail.from = SendGrid::Email.new(email: 'test@example.com')
mail.subject = 'Hello World from the Twilio SendGrid Ruby Library'
personalization = Personalization.new
personalization.add_to(Email.new(email: 'test1@example.com', 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: 'test@example.com')
mail.reply_to = SendGrid::Email.new(email: 'test@example.com')

# 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":"test@example.com"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"test@example.com","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":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]},{"bcc":[{"email":"test5@example.com","name":"Example User 5"},{"email":"test6@example.com","name":"Example User 6"}],"cc":[{"email":"test3@example.com","name":"Example User 3"},{"email":"test4@example.com","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":"test1@example.com","name":"Example User 1"},{"email":"test2@example.com","name":"Example User 2"}]}],"reply_to":{"email":"test@example.com"},"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: 'test@example.com')
mail.from = SendGrid::Email.new(email: 'test@example.com')
mail.subject = 'I\'m replacing the subject tag'
personalization = Personalization.new
personalization.add_to(Email.new(email: 'test@example.com'))
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: 'test@example.com')
mail = SendGrid::Mail.new
mail.from = SendGrid::Email.new(email: 'test@example.com')
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: 'test@example.com')
mail = SendGrid::Mail.new
mail.from = SendGrid::Email.new(email: 'test@example.com')
personalization = Personalization.new
personalization.add_to(Email.new(email: 'test@example.com'))
personalization.add_dynamic_template_data({
Expand Down
Loading