sendgrid / sendgrid-ruby

The Official Twilio SendGrid Led, Community Driven Ruby API Library
https://sendgrid.com
MIT License
621 stars 324 forks source link

Does this SDK supports email address validation? #442

Closed emanuelhfarias closed 3 years ago

emanuelhfarias commented 3 years ago

I'm a bit confused, there are two API docs for Sendgrid V3: one and two

What is the difference? I see in the README that this project follows one, but this API does't have Email Address Validation feature from Pro Plan and docs two has.

I've looked for this feature in ruby SDK but didn't find, so I end up implementing the ugly way:

require 'uri'
require 'net/http'

url = URI("https://api.sendgrid.com/v3/validations/email")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["authorization"] = 'Bearer <<YOUR_API_KEY_HERE>>'
request["content-type"] = 'application/json'
request.body = "{\"email\":\"john.doe@gmial.com\",\"source\":\"signup\"}"

response = http.request(request)

Is there any plans to support this? or at least some guide so I can integrate this feature in this SDK

Thanks

childish-sambino commented 3 years ago

Two is the one you should use. The other should be removed at some point.

You can simplify things a bit using this library:

data = "{\"email\":\"john.doe@gmial.com\",\"source\":\"signup\"}"
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client._("validations/email").post(request_body: data)
emanuelhfarias commented 3 years ago

@childish-sambino wow, thanks. I think this solves my problem. I'm closing this issue.