From 7bcfd63b7e37b2b8cb74b4fddaf5c6018c4b0be0 Mon Sep 17 00:00:00 2001 From: Rohan Khanna Date: Tue, 31 Oct 2017 18:46:37 +0530 Subject: [PATCH 1/2] Modified Mail Class calling with SendGrid::Mail --- README.md | 2 +- USE_CASES.md | 2 +- examples/helpers/mail/example.rb | 4 ++-- test/sendgrid/helpers/mail/test_mail.rb | 30 ++++++++++++------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3f5b2efb..371f65bd 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ from = Email.new(email: 'test@example.com') to = Email.new(email: 'test@example.com') subject = 'Sending with SendGrid is Fun' content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') -mail = Mail.new(from, subject, to, content) +mail = SendGrid::Mail.new(from, subject, to, content) sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) response = sg.client.mail._('send').post(request_body: mail.to_json) diff --git a/USE_CASES.md b/USE_CASES.md index 6d97bc28..b60726b2 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -49,7 +49,7 @@ I hope you are having a great day in -city- :) require 'sendgrid-ruby' include SendGrid -mail = Mail.new +mail = SendGrid::Mail.new mail.from = Email.new(email: 'test@example.com') mail.subject = 'I\'m replacing the subject tag' personalization = Personalization.new diff --git a/examples/helpers/mail/example.rb b/examples/helpers/mail/example.rb index eea0b161..d92f0066 100644 --- a/examples/helpers/mail/example.rb +++ b/examples/helpers/mail/example.rb @@ -7,7 +7,7 @@ def hello_world subject = 'Hello World from the SendGrid Ruby Library' to = Email.new(email: 'test@example.com') content = Content.new(type: 'text/plain', value: 'some text here') - mail = Mail.new(from, subject, to, content) + mail = SendGrid::Mail.new(from, subject, to, content) # puts JSON.pretty_generate(mail.to_json) puts mail.to_json @@ -19,7 +19,7 @@ def hello_world end def kitchen_sink - mail = Mail.new + mail = SendGrid::Mail.new mail.from = Email.new(email: 'test@example.com') mail.subject = 'Hello World from the SendGrid Ruby Library' personalization = Personalization.new diff --git a/test/sendgrid/helpers/mail/test_mail.rb b/test/sendgrid/helpers/mail/test_mail.rb index 664322ec..87dc8581 100644 --- a/test/sendgrid/helpers/mail/test_mail.rb +++ b/test/sendgrid/helpers/mail/test_mail.rb @@ -13,13 +13,13 @@ def test_hello_world to = Email.new(email: 'test@example.com') subject = 'Sending with SendGrid is Fun' content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') - mail = Mail.new(from, subject, to, content) + mail = SendGrid::Mail.new(from, subject, to, content) assert_equal(mail.to_json, JSON.parse('{"from":{"email":"test@example.com"}, "subject":"Sending with 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 = Mail.new + mail = SendGrid::Mail.new mail.from = Email.new(email: "test@example.com") mail.subject = "Hello World from the SendGrid Ruby Library" personalization = Personalization.new @@ -119,39 +119,39 @@ def test_kitchen_sink end def test_that_personalizations_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.personalizations) end def test_that_contents_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.contents) end def test_that_attachments_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.attachments) end def test_that_categories_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.categories) end def test_add_personalization - mail = Mail.new + mail = SendGrid::Mail.new mail.add_personalization('foo') assert_equal(['foo'.to_json], mail.personalizations) end def test_add_content - mail = Mail.new + mail = SendGrid::Mail.new mail.add_content('foo') assert_equal(['foo'.to_json], mail.contents) end def test_add_section - mail = Mail.new + mail = SendGrid::Mail.new mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1')) expected_json = { "sections"=>{ @@ -170,7 +170,7 @@ def test_add_section end def test_add_header - mail = Mail.new + mail = SendGrid::Mail.new mail.add_header(Header.new(key: 'X-Test3', value: 'test3')) expected_json = { "headers"=>{ @@ -189,7 +189,7 @@ def test_add_header end def test_add_custom_arg - mail = Mail.new + mail = SendGrid::Mail.new mail.add_custom_arg(CustomArg.new(key: 'campaign 1', value: 'welcome 1')) expected_json = { "custom_args"=>{ @@ -208,20 +208,20 @@ def test_add_custom_arg end def test_add_attachment - mail = Mail.new + mail = SendGrid::Mail.new mail.add_attachment('foo') assert_equal(['foo'.to_json], mail.attachments) end def test_add_valid_category - mail = Mail.new + mail = SendGrid::Mail.new category = Category.new(name: 'foo') mail.add_category(category) assert_equal(['foo'], mail.categories) end def test_add_more_than_1_valid_category - mail = Mail.new + mail = SendGrid::Mail.new category_1 = Category.new(name: 'foo') category_2 = Category.new(name: 'bar') mail.add_category(category_1) @@ -230,7 +230,7 @@ def test_add_more_than_1_valid_category end def test_add_invalid_category - mail = Mail.new + mail = SendGrid::Mail.new assert_raises(NoMethodError) do mail.add_category('foo') end From b4c4b50a329ad5e94c8711eb6e991df84dd87577 Mon Sep 17 00:00:00 2001 From: Rohan Khanna Date: Tue, 31 Oct 2017 18:46:37 +0530 Subject: [PATCH 2/2] Modified Mail Class calling with SendGrid::Mail --- README.md | 2 +- USE_CASES.md | 2 +- examples/helpers/mail/example.rb | 4 ++-- test/sendgrid/helpers/mail/test_mail.rb | 30 ++++++++++++------------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3f5b2efb..371f65bd 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ from = Email.new(email: 'test@example.com') to = Email.new(email: 'test@example.com') subject = 'Sending with SendGrid is Fun' content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') -mail = Mail.new(from, subject, to, content) +mail = SendGrid::Mail.new(from, subject, to, content) sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) response = sg.client.mail._('send').post(request_body: mail.to_json) diff --git a/USE_CASES.md b/USE_CASES.md index 6d97bc28..b60726b2 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -49,7 +49,7 @@ I hope you are having a great day in -city- :) require 'sendgrid-ruby' include SendGrid -mail = Mail.new +mail = SendGrid::Mail.new mail.from = Email.new(email: 'test@example.com') mail.subject = 'I\'m replacing the subject tag' personalization = Personalization.new diff --git a/examples/helpers/mail/example.rb b/examples/helpers/mail/example.rb index eea0b161..d92f0066 100644 --- a/examples/helpers/mail/example.rb +++ b/examples/helpers/mail/example.rb @@ -7,7 +7,7 @@ def hello_world subject = 'Hello World from the SendGrid Ruby Library' to = Email.new(email: 'test@example.com') content = Content.new(type: 'text/plain', value: 'some text here') - mail = Mail.new(from, subject, to, content) + mail = SendGrid::Mail.new(from, subject, to, content) # puts JSON.pretty_generate(mail.to_json) puts mail.to_json @@ -19,7 +19,7 @@ def hello_world end def kitchen_sink - mail = Mail.new + mail = SendGrid::Mail.new mail.from = Email.new(email: 'test@example.com') mail.subject = 'Hello World from the SendGrid Ruby Library' personalization = Personalization.new diff --git a/test/sendgrid/helpers/mail/test_mail.rb b/test/sendgrid/helpers/mail/test_mail.rb index 664322ec..87dc8581 100644 --- a/test/sendgrid/helpers/mail/test_mail.rb +++ b/test/sendgrid/helpers/mail/test_mail.rb @@ -13,13 +13,13 @@ def test_hello_world to = Email.new(email: 'test@example.com') subject = 'Sending with SendGrid is Fun' content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby') - mail = Mail.new(from, subject, to, content) + mail = SendGrid::Mail.new(from, subject, to, content) assert_equal(mail.to_json, JSON.parse('{"from":{"email":"test@example.com"}, "subject":"Sending with 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 = Mail.new + mail = SendGrid::Mail.new mail.from = Email.new(email: "test@example.com") mail.subject = "Hello World from the SendGrid Ruby Library" personalization = Personalization.new @@ -119,39 +119,39 @@ def test_kitchen_sink end def test_that_personalizations_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.personalizations) end def test_that_contents_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.contents) end def test_that_attachments_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.attachments) end def test_that_categories_is_empty_initially - mail = Mail.new + mail = SendGrid::Mail.new assert_equal([], mail.categories) end def test_add_personalization - mail = Mail.new + mail = SendGrid::Mail.new mail.add_personalization('foo') assert_equal(['foo'.to_json], mail.personalizations) end def test_add_content - mail = Mail.new + mail = SendGrid::Mail.new mail.add_content('foo') assert_equal(['foo'.to_json], mail.contents) end def test_add_section - mail = Mail.new + mail = SendGrid::Mail.new mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1')) expected_json = { "sections"=>{ @@ -170,7 +170,7 @@ def test_add_section end def test_add_header - mail = Mail.new + mail = SendGrid::Mail.new mail.add_header(Header.new(key: 'X-Test3', value: 'test3')) expected_json = { "headers"=>{ @@ -189,7 +189,7 @@ def test_add_header end def test_add_custom_arg - mail = Mail.new + mail = SendGrid::Mail.new mail.add_custom_arg(CustomArg.new(key: 'campaign 1', value: 'welcome 1')) expected_json = { "custom_args"=>{ @@ -208,20 +208,20 @@ def test_add_custom_arg end def test_add_attachment - mail = Mail.new + mail = SendGrid::Mail.new mail.add_attachment('foo') assert_equal(['foo'.to_json], mail.attachments) end def test_add_valid_category - mail = Mail.new + mail = SendGrid::Mail.new category = Category.new(name: 'foo') mail.add_category(category) assert_equal(['foo'], mail.categories) end def test_add_more_than_1_valid_category - mail = Mail.new + mail = SendGrid::Mail.new category_1 = Category.new(name: 'foo') category_2 = Category.new(name: 'bar') mail.add_category(category_1) @@ -230,7 +230,7 @@ def test_add_more_than_1_valid_category end def test_add_invalid_category - mail = Mail.new + mail = SendGrid::Mail.new assert_raises(NoMethodError) do mail.add_category('foo') end