From a71fe23b22daed4a772d3648968fb069231aaa3e Mon Sep 17 00:00:00 2001 From: Daniel Arnold Date: Tue, 8 Feb 2022 17:49:47 -0500 Subject: [PATCH 1/2] emailable 4.0.0: switch all endpoints to use options hash arguments instead of keyword arguments. modify README to reflect these changes. upgrade pry gem version to fix warning. bump version to 4.0.0. --- Gemfile.lock | 12 +++++----- README.md | 40 +++++++++++++++++++++++++------- lib/emailable.rb | 8 +++---- lib/emailable/batch.rb | 16 ++++++------- lib/emailable/email_validator.rb | 2 +- lib/emailable/version.rb | 2 +- 6 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 83d2a49..7e856b6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - emailable (3.1.1) + emailable (4.0.0) GEM remote: https://rubygems.org/ @@ -17,20 +17,20 @@ GEM ansi (1.5.0) awesome_print (1.8.0) builder (3.2.3) - coderay (1.1.2) + coderay (1.1.3) concurrent-ruby (1.1.7) i18n (1.8.5) concurrent-ruby (~> 1.0) - method_source (0.9.2) + method_source (1.0.0) minitest (5.11.3) minitest-reporters (1.3.6) ansi builder minitest (>= 5.0) ruby-progressbar - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) + pry (0.14.1) + coderay (~> 1.1) + method_source (~> 1.0) rake (13.0.1) ruby-progressbar (1.10.1) thread_safe (0.3.6) diff --git a/README.md b/README.md index 77c9b09..3ce7453 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ Or install it yourself as: ## Usage -The library needs to be configured with your account's API key which is available in your [Emailable Dashboard](https://app.emailable.com/api). Set `Emailable.api_key` to its value: +The library needs to be configured with your account's API key which is +available in your [Emailable Dashboard](https://app.emailable.com/api). Set +`Emailable.api_key` to its value: ### Setup @@ -47,6 +49,9 @@ Emailable.api_key = 'live_...' Emailable.verify('jarrett@emailable.com') ``` +All supported parameters for the verify endpoint can be passed in as hash +arguments to the `verify` method. + #### Slow Email Server Handling Some email servers are slow to respond. As a result, the timeout may be reached @@ -60,23 +65,30 @@ email `slow@example.com`. ### Batch Verification +First, create an `Emailable::Batch` object. Then, call the `verify` method to +start the batch. All supported parameters for the batch verification endpoint +can be passed in as hash arguments to the `verify` method. + #### Start a batch ```ruby emails = ['jarrett@emailable.com', 'support@emailable.com', ...] batch = Emailable::Batch.new(emails) -# you can optionally pass in a callback url that we'll POST to when the -# batch is complete. -batch = Emailable::Batch.new(emails, callback: 'https://emailable.com/') - # start verifying the batch batch.verify + +# you can optionally pass in a callback url that we'll POST to when the batch +# is complete. +batch.verify(url: 'https://emailable.com/') ``` #### Get the status / results of a batch -Calling `status` on a batch will return the status. It will contain the results as well once complete. You can also `results` to get just the results. +Calling `status` on a batch will return the status. It will contain the results +as well once complete. You can also `results` to get just the results. All +supported parameters for the status endpoint can be passed in as hash +arguments to the `status` method. ```ruby id = '5cfcbfdeede34200693c4319' @@ -85,6 +97,9 @@ batch = Emailable::Batch.new(id) # get status of batch batch.status +# get the status of a batch, with partial results if the batch is incomplete +batch.status(partial: true) + # gets the results batch.status.emails @@ -126,10 +141,17 @@ attr_accessor :email_verification_result ## Development -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +After checking out the repo, run `bin/setup` to install dependencies. Then, run +`rake test` to run the tests. You can also run `bin/console` for an interactive +prompt that will allow you to experiment. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install this gem onto your local machine, run `bundle exec rake install`. To +release a new version, update the version number in `version.rb`, and then run +`bundle exec rake release`, which will create a git tag for the version, push +git commits and tags, and push the `.gem` file to +[rubygems.org](https://rubygems.org). ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/emailable/emailable-ruby. +Bug reports and pull requests are welcome on GitHub at +https://github.com/emailable/emailable-ruby. diff --git a/lib/emailable.rb b/lib/emailable.rb index 577531a..0dabd90 100644 --- a/lib/emailable.rb +++ b/lib/emailable.rb @@ -28,13 +28,11 @@ class << self module_function - def verify(email, smtp: nil, accept_all: nil, timeout: nil) - opts = { - email: email, smtp: smtp, accept_all: accept_all, timeout: timeout - } + def verify(email, parameters = {}) + parameters[:email] = email client = Emailable::Client.new - response = client.request(:get, 'verify', opts) + response = client.request(:get, 'verify', parameters) if response.status == 249 raise Emailable::TimeoutError.new(response.body) diff --git a/lib/emailable/batch.rb b/lib/emailable/batch.rb index 54f4c6a..15ebbb8 100644 --- a/lib/emailable/batch.rb +++ b/lib/emailable/batch.rb @@ -2,15 +2,13 @@ module Emailable class Batch attr_accessor :id - def initialize(id_or_emails, callback: nil) + def initialize(id_or_emails) if id_or_emails.is_a?(Array) @id = nil @emails = id_or_emails - @callback = callback elsif id_or_emails.is_a?(String) @id = id_or_emails @emails = nil - @callback = nil else raise ArgumentError, 'expected an array of emails or batch id' end @@ -19,21 +17,21 @@ def initialize(id_or_emails, callback: nil) @status = nil end - def verify(simulate: nil) + def verify(parameters = {}) return @id unless @id.nil? - opts = { emails: @emails.join(','), url: @callback, simulate: simulate } - response = @client.request(:post, 'batch', opts) + parameters[:emails] = @emails.join(',') + response = @client.request(:post, 'batch', parameters) @id = response.body['id'] end - def status(simulate: nil, partial: nil) + def status(parameters = {}) return nil unless @id return @status if @status - body = { id: @id, simulate: simulate, partial: partial } - response = @client.request(:get, 'batch', body) + parameters[:id] = @id + response = @client.request(:get, 'batch', parameters) bs = BatchStatus.new(response.body) @status = bs if bs.complete? diff --git a/lib/emailable/email_validator.rb b/lib/emailable/email_validator.rb index 78c68e5..22e14e7 100644 --- a/lib/emailable/email_validator.rb +++ b/lib/emailable/email_validator.rb @@ -38,7 +38,7 @@ def validate_each(record, attribute, value) api_options = { timeout: timeout, smtp: smtp } api_options[:accept_all] = true unless accept_all - ev = Emailable.verify(value, **api_options) + ev = Emailable.verify(value, api_options) result_accessor = "#{attribute}_verification_result" if record.respond_to?(result_accessor) diff --git a/lib/emailable/version.rb b/lib/emailable/version.rb index 01388e1..9b3914d 100644 --- a/lib/emailable/version.rb +++ b/lib/emailable/version.rb @@ -1,3 +1,3 @@ module Emailable - VERSION = '3.1.1' + VERSION = '4.0.0' end From bd7797d2d1a28f68e3df20adec73891d2edb5316 Mon Sep 17 00:00:00 2001 From: Daniel Arnold Date: Tue, 8 Feb 2022 17:56:19 -0500 Subject: [PATCH 2/2] remove confusing sentence in README. --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ce7453..fb4e81f 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,8 @@ batch.verify(url: 'https://emailable.com/') #### Get the status / results of a batch Calling `status` on a batch will return the status. It will contain the results -as well once complete. You can also `results` to get just the results. All -supported parameters for the status endpoint can be passed in as hash -arguments to the `status` method. +as well once complete. All supported parameters for the status endpoint can be +passed in as hash arguments to the `status` method. ```ruby id = '5cfcbfdeede34200693c4319'