forked from freerobby/sendgrid_toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for the Mail module.
- Loading branch information
Showing
4 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module SendgridToolkit | ||
class Mail < AbstractSendgridClient | ||
def send_mail(options = {}) | ||
options.assert_valid_keys :to, :api_headers, :subject, :from, :text, :html, :reply_to, :from_name, :to_name, :date, :headers | ||
options["X-SMTPAPI"] = options[:api_headers] | ||
response = api_post('mail', 'send', options) | ||
raise(SendEmailError, "SendMail API refused to send email: #{response["errors"].inspect}") if response["message"] == "error" | ||
true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require File.expand_path("#{File.dirname(__FILE__)}/../../helper") | ||
|
||
describe SendgridToolkit::Mail do | ||
before do | ||
FakeWeb.clean_registry | ||
@obj = SendgridToolkit::Mail.new("fakeuser", "fakepass") | ||
end | ||
|
||
describe "#send" do | ||
it "returns an error when some attributes are missing" do | ||
FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/mail\.send\.json\?|, :body => '[{"email":"user@domain.com"},{"email":"user2@domain2.com"},{"email":"user3@domain2.com"}]') | ||
emails = @obj.send_mail(:to => "elad@fiverr.com", :from => "testing@fiverr.com", :subject => "Hi there!", :text => "testing body", :x_smtpapi => {:category => "Testing", :to => ["elad@fiverr.com"]}) | ||
emails[0]['email'].should == "user@domain.com" | ||
emails[1]['email'].should == "user2@domain2.com" | ||
emails[2]['email'].should == "user3@domain2.com" | ||
end | ||
end | ||
end | ||
end |