emailable 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e7635cc0f814700d29137678bd7b53fd91f07f042ff5435b8777cc269a51fb6
4
- data.tar.gz: 808f71d2c343495ad48143230d1daa11ba59e334d75a242d25df637abd446b51
3
+ metadata.gz: 569f2990e697b4682c76a2d659760562572c175f8649e273bf821965fd2df76f
4
+ data.tar.gz: cc16ed03e3a287e558a2d681f4c9d08ecadcc56a2bb5ec0242ad05ec4ed4a931
5
5
  SHA512:
6
- metadata.gz: 8a78fd0ab06eca710c67e2e8c01142d0a4bfdfa19f7357c9f54b7a8d53eddaf7b29f32ded7ad85145f414e95782a61dd4774d0a39821f2194f0228b9b402b6c4
7
- data.tar.gz: 99f27b66dc848815689fe3a0869b2b47a0f412c3305b910a044488b65598161a8349f690b5772d4e5181e97a4c55fa794f9593d3fa4b60bca5d5ad9a99b84530
6
+ metadata.gz: c8d2241faf3fc8b8bfce8a6f1bef348558b109800f428d67edcc3744c0daac4cd9a5c47b490d4622ff0dbcdf22b09efff69167ccc50b315b90212633b1ef67c5
7
+ data.tar.gz: 1300dc96e81a82de3ac19bfd392ecafd1f22751fbf261d5528e775f1b9bfab88b224dcbe2da9e3534ed9898b30b022cbc6bf64ae9a2e89cc3df3c5b518168851
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 2.7.4
data/.travis.yml CHANGED
@@ -3,5 +3,5 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 1.17.3
6
+ - 2.7.4
7
+ before_install: gem install bundler -v 2.2.15
data/Gemfile.lock CHANGED
@@ -1,10 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- emailable (3.0.0)
5
- faraday
6
- faraday_middleware
7
- net-http-persistent
4
+ emailable (3.0.2)
8
5
 
9
6
  GEM
10
7
  remote: https://rubygems.org/
@@ -22,14 +19,6 @@ GEM
22
19
  builder (3.2.3)
23
20
  coderay (1.1.2)
24
21
  concurrent-ruby (1.1.7)
25
- connection_pool (2.2.3)
26
- faraday (1.3.0)
27
- faraday-net_http (~> 1.0)
28
- multipart-post (>= 1.2, < 3)
29
- ruby2_keywords
30
- faraday-net_http (1.0.1)
31
- faraday_middleware (1.0.0)
32
- faraday (~> 1.0)
33
22
  i18n (1.8.5)
34
23
  concurrent-ruby (~> 1.0)
35
24
  method_source (0.9.2)
@@ -39,15 +28,11 @@ GEM
39
28
  builder
40
29
  minitest (>= 5.0)
41
30
  ruby-progressbar
42
- multipart-post (2.1.1)
43
- net-http-persistent (4.0.1)
44
- connection_pool (~> 2.2)
45
31
  pry (0.12.2)
46
32
  coderay (~> 1.1.0)
47
33
  method_source (~> 0.9.0)
48
34
  rake (13.0.1)
49
35
  ruby-progressbar (1.10.1)
50
- ruby2_keywords (0.0.4)
51
36
  thread_safe (0.3.6)
52
37
  tzinfo (1.2.8)
53
38
  thread_safe (~> 0.1)
@@ -67,4 +52,4 @@ DEPENDENCIES
67
52
  rake (~> 13.0)
68
53
 
69
54
  BUNDLED WITH
70
- 1.17.3
55
+ 2.1.4
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Emailable. https://emailable.com
3
+ Copyright (c) 2021 Emailable. https://emailable.com
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/emailable.gemspec CHANGED
@@ -27,9 +27,6 @@ Gem::Specification.new do |s|
27
27
  end
28
28
  s.require_paths = ['lib']
29
29
 
30
- s.add_dependency 'faraday'
31
- s.add_dependency 'faraday_middleware'
32
- s.add_dependency 'net-http-persistent'
33
30
  s.add_development_dependency 'bundler'
34
31
  s.add_development_dependency 'rake', '~> 13.0'
35
32
  s.add_development_dependency 'pry'
data/lib/emailable.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'faraday'
2
- require 'faraday_middleware'
3
1
  require 'emailable/version'
4
2
  require 'emailable/client'
3
+ require 'emailable/response'
5
4
  require 'emailable/batch'
6
5
  require 'emailable/resources/api_resource'
7
6
  require 'emailable/resources/account'
@@ -14,9 +13,13 @@ end
14
13
 
15
14
  module Emailable
16
15
  @max_network_retries = 1
16
+ @open_timeout = 30
17
+ @read_timeout = 60
18
+ @write_timeout = 30
17
19
 
18
20
  class << self
19
- attr_accessor :api_key, :max_network_retries
21
+ attr_accessor :api_key, :max_network_retries, :open_timeout, :read_timeout,
22
+ :write_timeout
20
23
  end
21
24
 
22
25
  module_function
@@ -4,15 +4,19 @@ module Emailable
4
4
 
5
5
  def initialize(id_or_emails, callback: nil)
6
6
  if id_or_emails.is_a?(Array)
7
+ @id = nil
7
8
  @emails = id_or_emails
8
9
  @callback = callback
9
10
  elsif id_or_emails.is_a?(String)
10
11
  @id = id_or_emails
12
+ @emails = nil
13
+ @callback = nil
11
14
  else
12
15
  raise ArgumentError, 'expected an array of emails or batch id'
13
16
  end
14
17
 
15
18
  @client = Emailable::Client.new
19
+ @status = nil
16
20
  end
17
21
 
18
22
  def verify
@@ -2,27 +2,30 @@ module Emailable
2
2
  class Client
3
3
 
4
4
  def initialize
5
- @client = Faraday.new('https://api.emailable.com/v1') do |f|
6
- f.request :url_encoded
7
- f.response :json, content_type: /\bjson$/
8
- f.adapter :net_http_persistent
9
- end
5
+ @base_url = 'https://api.emailable.com/v1'
6
+ @connection = create_connection(URI(@base_url))
10
7
  end
11
8
 
12
- def request(method, endpoint, opts = {})
9
+ def request(method, endpoint, params = {})
13
10
  begin
14
- tries ||= 0
11
+ tries ||= 3
15
12
 
16
- @client.params[:api_key] = Emailable.api_key
13
+ uri = URI("#{@base_url}/#{endpoint}")
14
+ params[:api_key] = Emailable.api_key
17
15
 
18
- response =
16
+ http_response =
19
17
  if method == :get
20
- @client.get(endpoint, opts)
18
+ uri.query = URI.encode_www_form(params)
19
+ @connection.get(uri)
21
20
  elsif method == :post
22
- @client.post(endpoint, opts)
21
+ request = Net::HTTP::Post.new(uri, 'Content-Type': 'application/json')
22
+ request.body = params.to_json
23
+ @connection.request(request)
23
24
  end
25
+
26
+ response = Response.new(http_response)
24
27
  rescue => e
25
- retry if self.class.should_retry?(e, tries)
28
+ retry if (tries -= 1) > 0 && self.class.should_retry?(e, tries)
26
29
 
27
30
  raise e
28
31
  end
@@ -48,23 +51,59 @@ module Emailable
48
51
  raise error_map[status.to_s].new(error_attributes)
49
52
  end
50
53
 
54
+ private
55
+
56
+ def create_connection(uri)
57
+ connection = Net::HTTP.new(uri.host, uri.port)
58
+
59
+ # Time in seconds within which Net::HTTP will try to reuse an already
60
+ # open connection when issuing a new operation. Outside this window, Ruby
61
+ # will transparently close and re-open the connection without trying to
62
+ # reuse it.
63
+ #
64
+ # Ruby's default of 2 seconds is almost certainly too short. Here I've
65
+ # reused Go's default for `DefaultTransport`.
66
+ connection.keep_alive_timeout = 30
67
+
68
+ connection.open_timeout = Emailable.open_timeout
69
+ connection.read_timeout = Emailable.read_timeout
70
+ if connection.respond_to?(:write_timeout=)
71
+ connection.write_timeout = Emailable.write_timeout
72
+ end
73
+ connection.use_ssl = uri.scheme == "https"
74
+
75
+ connection
76
+ end
77
+
51
78
  def self.should_retry?(error, num_retries)
52
79
  return false if num_retries >= Emailable.max_network_retries
53
80
 
54
- # Retry on timeout-related problems (either on open or read).
55
- return true if error.is_a?(Faraday::TimeoutError)
81
+ case error
82
+ when Net::OpenTimeout, Net::ReadTimeout
83
+ # Retry on timeout-related problems (either on open or read).
84
+ true
85
+ when EOFError, Errno::ECONNREFUSED, Errno::ECONNRESET,
86
+ Errno::EHOSTUNREACH, Errno::ETIMEDOUT, SocketError
87
+ # Destination refused the connection, the connection was reset, or a
88
+ # variety of other connection failures. This could occur from a single
89
+ # saturated server, so retry in case it's intermittent.
90
+ true
91
+ when Net::HTTPError
92
+ # 409 Conflict
93
+ return true if error.http_status == 409
56
94
 
57
- # Destination refused the connection, the connection was reset, or a
58
- # variety of other connection failures. This could occur from a single
59
- # saturated server, so retry in case it's intermittent.
60
- return true if error.is_a?(Faraday::ConnectionFailed)
95
+ # 429 Too Many Requests
96
+ return true if error.http_status == 429
61
97
 
62
- if error.is_a?(Faraday::ClientError) && error.response
63
- # 409 conflict
64
- return true if error.response[:status] == 409
65
- end
98
+ # 500 Internal Server Error
99
+ return true if error.http_status == 500
66
100
 
67
- false
101
+ # 503 Service Unavailable
102
+ error.http_status == 503
103
+ else
104
+ false
105
+ end
68
106
  end
107
+
69
108
  end
70
109
  end
@@ -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, api_options)
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 Response
3
+
4
+ attr_accessor :status, :body
5
+
6
+ def initialize(response)
7
+ @status = response.code.to_i
8
+ @body = JSON.parse(response.body)
9
+ end
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Emailable
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.2'
3
3
  end
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emailable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emailable
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: net-http-persistent
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
13
  - !ruby/object:Gem::Dependency
56
14
  name: bundler
57
15
  requirement: !ruby/object:Gem::Requirement
@@ -180,6 +138,7 @@ files:
180
138
  - lib/emailable/resources/api_resource.rb
181
139
  - lib/emailable/resources/batch_status.rb
182
140
  - lib/emailable/resources/verification.rb
141
+ - lib/emailable/response.rb
183
142
  - lib/emailable/version.rb
184
143
  - test/email_validator_test.rb
185
144
  - test/emailable/batch_test.rb
@@ -207,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
166
  - !ruby/object:Gem::Version
208
167
  version: '0'
209
168
  requirements: []
210
- rubygems_version: 3.0.9
169
+ rubygems_version: 3.1.6
211
170
  signing_key:
212
171
  specification_version: 4
213
172
  summary: Ruby bindings for the Emailable API