emailable 3.0.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/README.md +32 -11
- data/bin/console +4 -4
- data/lib/emailable/batch.rb +8 -9
- data/lib/emailable/client.rb +11 -16
- data/lib/emailable/email_validator.rb +1 -1
- data/lib/emailable/errors.rb +12 -0
- data/lib/emailable/resources/api_resource.rb +14 -6
- data/lib/emailable/resources/batch_status.rb +1 -1
- data/lib/emailable/resources/verification.rb +5 -0
- data/lib/emailable/version.rb +1 -1
- data/lib/emailable.rb +8 -26
- data/test/email_validator_test.rb +1 -0
- data/test/emailable/batch_test.rb +1 -2
- data/test/emailable/resources/api_resource_test.rb +49 -0
- data/test/test_helper.rb +0 -2
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e893db37f9960d70d4a0ed17f712ef1e02f13f707d57e7428c3f2b07e36b6d
|
4
|
+
data.tar.gz: 7ab4fc1440cc5cd172059f4d2bb53cc51f169f5f21cb7a9bb919d97f04b2b543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb96ef05631762f2e6fa53e13a621e6006f23af42dba60fa36a86adc978b8b537def118e7547c8af4da8925109a7b671e7cfba4c5eab031a4c874f2e15e64f1d
|
7
|
+
data.tar.gz: c1292e55f4ba32a80da7a30e9d9f401d51f0747d23ccac2f1e8cd336020b9cda45413e7f423eb0b00fee24bb618704e596d20203f8334f532a9d364b97df218f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
emailable (
|
4
|
+
emailable (4.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -17,20 +17,20 @@ GEM
|
|
17
17
|
ansi (1.5.0)
|
18
18
|
awesome_print (1.8.0)
|
19
19
|
builder (3.2.3)
|
20
|
-
coderay (1.1.
|
20
|
+
coderay (1.1.3)
|
21
21
|
concurrent-ruby (1.1.7)
|
22
22
|
i18n (1.8.5)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
|
-
method_source (0.
|
24
|
+
method_source (1.0.0)
|
25
25
|
minitest (5.11.3)
|
26
26
|
minitest-reporters (1.3.6)
|
27
27
|
ansi
|
28
28
|
builder
|
29
29
|
minitest (>= 5.0)
|
30
30
|
ruby-progressbar
|
31
|
-
pry (0.
|
32
|
-
coderay (~> 1.1
|
33
|
-
method_source (~>
|
31
|
+
pry (0.14.1)
|
32
|
+
coderay (~> 1.1)
|
33
|
+
method_source (~> 1.0)
|
34
34
|
rake (13.0.1)
|
35
35
|
ruby-progressbar (1.10.1)
|
36
36
|
thread_safe (0.3.6)
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Emailable Ruby Library
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.com/emailable/emailable-ruby.svg)](https://travis-ci.com/emailable/emailable-ruby)
|
4
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
3
|
+
[![Build Status](https://app.travis-ci.com/emailable/emailable-ruby.svg)](https://app.travis-ci.com/emailable/emailable-ruby)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/e7eef54e491adec95e6d/maintainability)](https://codeclimate.com/github/emailable/emailable-ruby/maintainability)
|
5
5
|
|
6
6
|
This is the official ruby wrapper for the Emailable API.
|
7
7
|
|
@@ -29,7 +29,9 @@ Or install it yourself as:
|
|
29
29
|
|
30
30
|
## Usage
|
31
31
|
|
32
|
-
The library needs to be configured with your account's API key which is
|
32
|
+
The library needs to be configured with your account's API key which is
|
33
|
+
available in your [Emailable Dashboard](https://app.emailable.com/api). Set
|
34
|
+
`Emailable.api_key` to its value:
|
33
35
|
|
34
36
|
### Setup
|
35
37
|
|
@@ -47,6 +49,9 @@ Emailable.api_key = 'live_...'
|
|
47
49
|
Emailable.verify('jarrett@emailable.com')
|
48
50
|
```
|
49
51
|
|
52
|
+
All supported parameters for the verify endpoint can be passed in as hash
|
53
|
+
arguments to the `verify` method.
|
54
|
+
|
50
55
|
#### Slow Email Server Handling
|
51
56
|
|
52
57
|
Some email servers are slow to respond. As a result, the timeout may be reached
|
@@ -60,23 +65,29 @@ email `slow@example.com`.
|
|
60
65
|
|
61
66
|
### Batch Verification
|
62
67
|
|
68
|
+
First, create an `Emailable::Batch` object. Then, call the `verify` method to
|
69
|
+
start the batch. All supported parameters for the batch verification endpoint
|
70
|
+
can be passed in as hash arguments to the `verify` method.
|
71
|
+
|
63
72
|
#### Start a batch
|
64
73
|
|
65
74
|
```ruby
|
66
75
|
emails = ['jarrett@emailable.com', 'support@emailable.com', ...]
|
67
76
|
batch = Emailable::Batch.new(emails)
|
68
77
|
|
69
|
-
# you can optionally pass in a callback url that we'll POST to when the
|
70
|
-
# batch is complete.
|
71
|
-
batch = Emailable::Batch.new(emails, callback: 'https://emailable.com/')
|
72
|
-
|
73
78
|
# start verifying the batch
|
74
79
|
batch.verify
|
80
|
+
|
81
|
+
# you can optionally pass in a callback url that we'll POST to when the batch
|
82
|
+
# is complete.
|
83
|
+
batch.verify(url: 'https://emailable.com/')
|
75
84
|
```
|
76
85
|
|
77
86
|
#### Get the status / results of a batch
|
78
87
|
|
79
|
-
Calling `status` on a batch will return the status. It will contain the results
|
88
|
+
Calling `status` on a batch will return the status. It will contain the results
|
89
|
+
as well once complete. All supported parameters for the status endpoint can be
|
90
|
+
passed in as hash arguments to the `status` method.
|
80
91
|
|
81
92
|
```ruby
|
82
93
|
id = '5cfcbfdeede34200693c4319'
|
@@ -85,6 +96,9 @@ batch = Emailable::Batch.new(id)
|
|
85
96
|
# get status of batch
|
86
97
|
batch.status
|
87
98
|
|
99
|
+
# get the status of a batch, with partial results if the batch is incomplete
|
100
|
+
batch.status(partial: true)
|
101
|
+
|
88
102
|
# gets the results
|
89
103
|
batch.status.emails
|
90
104
|
|
@@ -126,10 +140,17 @@ attr_accessor :email_verification_result
|
|
126
140
|
|
127
141
|
## Development
|
128
142
|
|
129
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
143
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
144
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
145
|
+
prompt that will allow you to experiment.
|
130
146
|
|
131
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
147
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
148
|
+
release a new version, update the version number in `version.rb`, and then run
|
149
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
150
|
+
git commits and tags, and push the `.gem` file to
|
151
|
+
[rubygems.org](https://rubygems.org).
|
132
152
|
|
133
153
|
## Contributing
|
134
154
|
|
135
|
-
Bug reports and pull requests are welcome on GitHub at
|
155
|
+
Bug reports and pull requests are welcome on GitHub at
|
156
|
+
https://github.com/emailable/emailable-ruby.
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'emailable'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
10
|
+
# require 'pry'
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/emailable/batch.rb
CHANGED
@@ -2,15 +2,13 @@ module Emailable
|
|
2
2
|
class Batch
|
3
3
|
attr_accessor :id
|
4
4
|
|
5
|
-
def initialize(id_or_emails
|
5
|
+
def initialize(id_or_emails)
|
6
6
|
if id_or_emails.is_a?(Array)
|
7
7
|
@id = nil
|
8
8
|
@emails = id_or_emails
|
9
|
-
@callback = callback
|
10
9
|
elsif id_or_emails.is_a?(String)
|
11
10
|
@id = id_or_emails
|
12
11
|
@emails = nil
|
13
|
-
@callback = nil
|
14
12
|
else
|
15
13
|
raise ArgumentError, 'expected an array of emails or batch id'
|
16
14
|
end
|
@@ -19,20 +17,21 @@ module Emailable
|
|
19
17
|
@status = nil
|
20
18
|
end
|
21
19
|
|
22
|
-
def verify
|
20
|
+
def verify(parameters = {})
|
23
21
|
return @id unless @id.nil?
|
24
22
|
|
25
|
-
|
26
|
-
response = @client.request(:post, 'batch',
|
23
|
+
parameters[:emails] = @emails.join(',')
|
24
|
+
response = @client.request(:post, 'batch', parameters)
|
27
25
|
|
28
26
|
@id = response.body['id']
|
29
27
|
end
|
30
28
|
|
31
|
-
def status
|
29
|
+
def status(parameters = {})
|
32
30
|
return nil unless @id
|
33
31
|
return @status if @status
|
34
32
|
|
35
|
-
|
33
|
+
parameters[:id] = @id
|
34
|
+
response = @client.request(:get, 'batch', parameters)
|
36
35
|
bs = BatchStatus.new(response.body)
|
37
36
|
@status = bs if bs.complete?
|
38
37
|
|
@@ -40,7 +39,7 @@ module Emailable
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def complete?
|
43
|
-
|
42
|
+
status.complete?
|
44
43
|
end
|
45
44
|
|
46
45
|
def inspect
|
data/lib/emailable/client.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
module Emailable
|
2
2
|
class Client
|
3
|
+
ERRORS = {
|
4
|
+
400 => BadRequestError,
|
5
|
+
401 => UnauthorizedError,
|
6
|
+
402 => PaymentRequiredError,
|
7
|
+
403 => ForbiddenError,
|
8
|
+
404 => NotFoundError,
|
9
|
+
429 => TooManyRequestsError,
|
10
|
+
500 => InternalServerError,
|
11
|
+
503 => ServiceUnavailableError
|
12
|
+
}.freeze
|
3
13
|
|
4
14
|
def initialize
|
5
15
|
@base_url = 'https://api.emailable.com/v1'
|
@@ -33,22 +43,7 @@ module Emailable
|
|
33
43
|
status = response.status
|
34
44
|
return response if status.between?(200, 299)
|
35
45
|
|
36
|
-
|
37
|
-
message: response.body['message'],
|
38
|
-
code: status
|
39
|
-
}
|
40
|
-
error_map = {
|
41
|
-
'400' => BadRequestError,
|
42
|
-
'401' => UnauthorizedError,
|
43
|
-
'402' => PaymentRequiredError,
|
44
|
-
'403' => ForbiddenError,
|
45
|
-
'404' => NotFoundError,
|
46
|
-
'429' => TooManyRequestsError,
|
47
|
-
'500' => InternalServerError,
|
48
|
-
'503' => ServiceUnavailableError
|
49
|
-
}
|
50
|
-
|
51
|
-
raise error_map[status.to_s].new(error_attributes)
|
46
|
+
raise ERRORS[status].new(response.body['message'])
|
52
47
|
end
|
53
48
|
|
54
49
|
private
|
@@ -38,7 +38,7 @@ class EmailValidator < ActiveModel::EachValidator
|
|
38
38
|
|
39
39
|
api_options = { timeout: timeout, smtp: smtp }
|
40
40
|
api_options[:accept_all] = true unless accept_all
|
41
|
-
ev = Emailable.verify(value,
|
41
|
+
ev = Emailable.verify(value, api_options)
|
42
42
|
|
43
43
|
result_accessor = "#{attribute}_verification_result"
|
44
44
|
if record.respond_to?(result_accessor)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Emailable
|
2
|
+
class Error < StandardError; end
|
3
|
+
class BadRequestError < Error; end
|
4
|
+
class UnauthorizedError < Error; end
|
5
|
+
class PaymentRequiredError < Error; end
|
6
|
+
class ForbiddenError < Error; end
|
7
|
+
class NotFoundError < Error; end
|
8
|
+
class TooManyRequestsError < Error; end
|
9
|
+
class InternalServerError < Error; end
|
10
|
+
class ServiceUnavailableError < Error; end
|
11
|
+
class TimeoutError < Error; end
|
12
|
+
end
|
@@ -7,13 +7,21 @@ module Emailable
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
[e.to_s.delete('@'), instance_variable_get(e)]
|
10
|
+
def to_h
|
11
|
+
instance_variables.map do |e|
|
12
|
+
[e.to_s.delete('@').to_sym, instance_variable_get(e)]
|
13
13
|
end.to_h
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :to_hash, :to_h
|
17
|
+
|
18
|
+
def to_json
|
19
|
+
JSON.generate(to_h)
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
"#<#{self.class}:0x#{(object_id << 1).to_s(16)}> JSON: " +
|
24
|
+
JSON.pretty_generate(to_h)
|
17
25
|
end
|
18
26
|
|
19
27
|
end
|
data/lib/emailable/version.rb
CHANGED
data/lib/emailable.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
require 'emailable/version'
|
5
|
+
require 'emailable/errors'
|
2
6
|
require 'emailable/client'
|
3
7
|
require 'emailable/response'
|
4
8
|
require 'emailable/batch'
|
@@ -24,18 +28,14 @@ module Emailable
|
|
24
28
|
|
25
29
|
module_function
|
26
30
|
|
27
|
-
def verify(email,
|
28
|
-
|
29
|
-
email: email, smtp: smtp, accept_all: accept_all, timeout: timeout
|
30
|
-
}
|
31
|
+
def verify(email, parameters = {})
|
32
|
+
parameters[:email] = email
|
31
33
|
|
32
34
|
client = Emailable::Client.new
|
33
|
-
response = client.request(:get, 'verify',
|
35
|
+
response = client.request(:get, 'verify', parameters)
|
34
36
|
|
35
37
|
if response.status == 249
|
36
|
-
raise Emailable::TimeoutError.new(
|
37
|
-
code: response.status, message: response.body
|
38
|
-
)
|
38
|
+
raise Emailable::TimeoutError.new(response.body)
|
39
39
|
else
|
40
40
|
Verification.new(response.body)
|
41
41
|
end
|
@@ -47,22 +47,4 @@ module Emailable
|
|
47
47
|
Account.new(response.body)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
class Error < StandardError
|
52
|
-
attr_accessor :code, :message
|
53
|
-
|
54
|
-
def initialize(code: nil, message: nil)
|
55
|
-
@code = code
|
56
|
-
@message = message
|
57
|
-
end
|
58
|
-
end
|
59
|
-
class BadRequestError < Error; end
|
60
|
-
class UnauthorizedError < Error; end
|
61
|
-
class PaymentRequiredError < Error; end
|
62
|
-
class ForbiddenError < Error; end
|
63
|
-
class NotFoundError < Error; end
|
64
|
-
class TooManyRequestsError < Error; end
|
65
|
-
class InternalServerError < Error; end
|
66
|
-
class ServiceUnavailableError < Error; end
|
67
|
-
class TimeoutError < Error; end
|
68
50
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Emailable
|
4
|
+
module Resources
|
5
|
+
class APIResourceTest < Minitest::Test
|
6
|
+
class Example < APIResource
|
7
|
+
attr_accessor :foo, :bar, :baz
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@e = Example.new(foo: 'abc', bar: 123, baz: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_init
|
15
|
+
assert_equal 'abc', @e.foo
|
16
|
+
assert_equal 123, @e.bar
|
17
|
+
assert_equal true, @e.baz
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_to_h
|
21
|
+
correct = {
|
22
|
+
foo: 'abc',
|
23
|
+
bar: 123,
|
24
|
+
baz: true,
|
25
|
+
}
|
26
|
+
assert_equal correct, @e.to_h
|
27
|
+
assert_equal correct, @e.to_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_to_json
|
31
|
+
correct = %q|{"foo":"abc","bar":123,"baz":true}|
|
32
|
+
assert_equal correct, @e.to_json
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_inspect
|
36
|
+
correct = <<~STR.chomp
|
37
|
+
#<> JSON: {
|
38
|
+
"foo": "abc",
|
39
|
+
"bar": 123,
|
40
|
+
"baz": true
|
41
|
+
}
|
42
|
+
STR
|
43
|
+
output = @e.inspect.gsub(/<.*>/, '<>')
|
44
|
+
assert_equal correct, output
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emailable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emailable
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/emailable/batch.rb
|
135
135
|
- lib/emailable/client.rb
|
136
136
|
- lib/emailable/email_validator.rb
|
137
|
+
- lib/emailable/errors.rb
|
137
138
|
- lib/emailable/resources/account.rb
|
138
139
|
- lib/emailable/resources/api_resource.rb
|
139
140
|
- lib/emailable/resources/batch_status.rb
|
@@ -142,6 +143,7 @@ files:
|
|
142
143
|
- lib/emailable/version.rb
|
143
144
|
- test/email_validator_test.rb
|
144
145
|
- test/emailable/batch_test.rb
|
146
|
+
- test/emailable/resources/api_resource_test.rb
|
145
147
|
- test/emailable_test.rb
|
146
148
|
- test/test_helper.rb
|
147
149
|
homepage: https://emailable.com
|
@@ -151,7 +153,7 @@ metadata:
|
|
151
153
|
bug_tracker_uri: https://github.com/emailable/emailable-ruby/issues
|
152
154
|
documentation_uri: https://docs.emailable.com/?ruby
|
153
155
|
source_code_uri: https://github.com/emailable/emailable-ruby
|
154
|
-
post_install_message:
|
156
|
+
post_install_message:
|
155
157
|
rdoc_options: []
|
156
158
|
require_paths:
|
157
159
|
- lib
|
@@ -167,11 +169,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
169
|
version: '0'
|
168
170
|
requirements: []
|
169
171
|
rubygems_version: 3.1.6
|
170
|
-
signing_key:
|
172
|
+
signing_key:
|
171
173
|
specification_version: 4
|
172
174
|
summary: Ruby bindings for the Emailable API
|
173
175
|
test_files:
|
174
176
|
- test/email_validator_test.rb
|
175
177
|
- test/emailable/batch_test.rb
|
178
|
+
- test/emailable/resources/api_resource_test.rb
|
176
179
|
- test/emailable_test.rb
|
177
180
|
- test/test_helper.rb
|