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
12 changes: 10 additions & 2 deletions lib/sendgrid_toolkit/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ def send_mail(options = {})

private
def convert_params(options)
options["x-smtpapi"] = options["x-smtpapi"].to_json if options.has_key?("x-smtpapi")
options
if options.has_key?("x-smtpapi") && !x_smtpapi_parsable_json?(options)
options["x-smtpapi"] = options["x-smtpapi"].to_json
end
options
end

def x_smtpapi_parsable_json? options
!!JSON.parse(options["x-smtpapi"])
rescue
false
end
end
end
7 changes: 7 additions & 0 deletions spec/lib/sendgrid_toolkit/mail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,12 @@
response = @obj.send_mail :to => "scottb@sendgrid.com", :from => "testing@fiverr.com", :subject => "Subject", :text => "Text", "x-smtpapi" => xsmtpapi
response.request.options[:query]["x-smtpapi"].should == xsmtpapi.to_json
end

it "only converts x-smtpapi to json if it has not been converted yet" do
FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/mail\.send\.json\?|, :body => '{"message":"success"}')
xsmtpapi = {:category => "Testing", :to => ["scottb@sendgrid.com"]}.to_json
response = @obj.send_mail :to => "scottb@sendgrid.com", :from => "testing@fiverr.com", :subject => "Subject", :text => "Text", "x-smtpapi" => xsmtpapi
response.request.options[:query]["x-smtpapi"].should == xsmtpapi
end
end
end