Skip to content
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

Send a Single Email to a Single Recipient #100

Closed
thinkingserious opened this issue Sep 23, 2016 · 4 comments
Closed

Send a Single Email to a Single Recipient #100

thinkingserious opened this issue Sep 23, 2016 · 4 comments
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@thinkingserious
Copy link
Contributor

Acceptance Criteria:

  • A email object that represents the response body payload
  • A mail object that handles sending email objects, data validation and error handling

Reference:

@ssonal
Copy link

ssonal commented Oct 5, 2016

Hi,

I'm looking to help out, but I'm not sure what's required of this issue. From what I can tell, ruby-http-client manages the actual request, returning the status code, errors and body payload.

@thinkingserious
Copy link
Contributor Author

Hi @ssonal,

This issue is part of a bigger project: Mail Helper Enhancement (v3 mail/send).

Specifically, we want to refactor the Mail Helper so that it is much easier to use. I would start by proposing a new method signature. For example, we currently have:

require 'sendgrid-ruby'
include SendGrid

from = Email.new(email: '[email protected]')
subject = 'Hello World from the SendGrid Ruby Library!'
to = Email.new(email: '[email protected]')
content = Content.new(type: 'text/plain', value: 'Hello, Email!')
mail = 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)
puts response.status_code
puts response.body
puts response.headers

Perhaps a new version would be:

require 'sendgrid-ruby'
include SendGrid


from = Email.new(email: '[email protected]')
subject = 'Hello World from the SendGrid Ruby Library!'
to = Email.new(email: '[email protected]')
content = Content.new(type: 'text/plain', value: 'Hello, Email!')
mail = Mail.new(from, subject, to, content)

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.send(mail)
puts response.status_code
puts response.body
puts response.headers

@hanumakanthvvn
Copy link

@thinkingserious So in this case for new method signature, we can add new method in lib/sendgrid/client.rb as

def send(mail)
  data = mail.kind_of?(Mail) ? mail.to_json : mail
  @client.mail._("send").post(request_body: data)
end

And we can call it as

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.send(mail)

Am i correct?

@thinkingserious thinkingserious added the type: community enhancement feature request not on Twilio's roadmap label May 2, 2017
@thinkingserious
Copy link
Contributor Author

This has been moved here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

3 participants