Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  remove confusing sentence in README.
  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.
  • Loading branch information
danarnold committed Feb 8, 2022
2 parents 3556c72 + bd7797d commit fa4a6ce
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
emailable (3.2.0)
emailable (4.0.0)

GEM
remote: https://rubygems.org/
Expand All @@ -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)
Expand Down
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -47,6 +49,9 @@ Emailable.api_key = 'live_...'
Emailable.verify('[email protected]')
```

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
Expand All @@ -60,23 +65,29 @@ email `[email protected]`.

### 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 = ['[email protected]', '[email protected]', ...]
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. All supported parameters for the status endpoint can be
passed in as hash arguments to the `status` method.

```ruby
id = '5cfcbfdeede34200693c4319'
Expand All @@ -85,6 +96,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

Expand Down Expand Up @@ -126,10 +140,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.
8 changes: 3 additions & 5 deletions lib/emailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions lib/emailable/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion lib/emailable/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/emailable/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Emailable
VERSION = '3.2.0'
VERSION = '4.0.0'
end

0 comments on commit fa4a6ce

Please sign in to comment.