zerobounce 0.0.1 → 0.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
  SHA1:
3
- metadata.gz: d5073bd0edd03b300161b3b85ea16ef52af8695e
4
- data.tar.gz: 1527033d9b898a7355fb3427a2de216159f51711
3
+ metadata.gz: 9c89aae3611e01d420af253c1e3b60a09a5e2903
4
+ data.tar.gz: 6082f7d46074773f1c8b98cf79c0c1a65a9ba8ee
5
5
  SHA512:
6
- metadata.gz: 78ce4fbae3708ad80bb1688f892143a7580f36a67d97ff77f21853aa1c3d2bc3cc4aa49434a99cadbf9b728ec1eaa63cb91a45b04588a709bfb7e73d76be5b21
7
- data.tar.gz: 0661ffd922bb6d9e17491d92066c4b865cb6c3855dc427716d683cfe325a10aaf11406684082bd69f61c5dc7df39c8e8a81dfa407469f135cc22a6d279bdaadc
6
+ metadata.gz: 0733544edd82e48f24bab8ecb1880039d8289d7c62a939250c2e5e571a2c906921ac17bbf3b3df2d5e1c4190598c29bb4b78f808aeeed6847a85d18e8da2a713
7
+ data.tar.gz: d091198164aef11b24ee69f3efa4daf1795e78c769b50352cad5d94cef7947a91847b6d433635f8ef3e94ae2c6610360019954199a3319e64c4cb6100684f000
@@ -0,0 +1,136 @@
1
+ version: 2
2
+
3
+ workspace_root: &workspace_root
4
+ ~/zerobounce
5
+
6
+ defaults: &defaults
7
+ working_directory: *workspace_root
8
+ docker:
9
+ - image: circleci/ruby:2.4
10
+
11
+ attach_workspace: &attach_workspace
12
+ attach_workspace:
13
+ at: *workspace_root
14
+
15
+ restore_repo: &restore_repo
16
+ restore_cache:
17
+ name: Restore repository
18
+ keys:
19
+ - v1-repo-{{ .Branch }}-{{ .Revision }}
20
+
21
+ restore_gems: &restore_gems
22
+ restore_cache:
23
+ name: Restore gems
24
+ keys:
25
+ - v1-zerobounce-{{ checksum "Gemfile.lock" }}
26
+
27
+ jobs:
28
+ checkout-code:
29
+ <<: *defaults
30
+ steps:
31
+ - checkout
32
+ - save_cache:
33
+ key: v1-repo-{{ .Branch }}-{{ .Revision }}
34
+ paths:
35
+ - *workspace_root
36
+
37
+ bundle-dependencies:
38
+ <<: *defaults
39
+ steps:
40
+ - *restore_repo
41
+ - *restore_gems
42
+ - run:
43
+ name: Install Bundler dependencies
44
+ command: |
45
+ bin/bundle install --path=vendor/bundle \
46
+ --jobs=4 \
47
+ --retry=3
48
+ - run:
49
+ name: Setup Code Climate test-reporter
50
+ command: |
51
+ mkdir -p tmp/
52
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
53
+ chmod +x ./tmp/cc-test-reporter
54
+ - save_cache:
55
+ key: v1-zerobounce-{{ checksum "Gemfile.lock" }}
56
+ paths:
57
+ - vendor/bundle
58
+ - persist_to_workspace:
59
+ root: *workspace_root
60
+ paths:
61
+ - vendor/bundle
62
+ - tmp/cc-test-reporter
63
+
64
+ run-specs:
65
+ <<: *defaults
66
+ parallelism: 2
67
+ steps:
68
+ - *restore_repo
69
+ - *attach_workspace
70
+ - run:
71
+ name: Set bundler path
72
+ command: bin/bundle --path vendor/bundle
73
+ - run:
74
+ name: Run tests
75
+ command: |
76
+ bin/bundle exec rspec --profile 10 \
77
+ --format RspecJunitFormatter \
78
+ --out test_results/rspec.xml \
79
+ --format progress \
80
+ $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
81
+ ./tmp/cc-test-reporter format-coverage \
82
+ -t simplecov \
83
+ -o tmp/codeclimate.${CIRCLE_NODE_INDEX}.json \
84
+ ${CIRCLE_ARTIFACTS}/coverage/.resultset.json
85
+ - persist_to_workspace:
86
+ root: *workspace_root
87
+ paths:
88
+ - tmp
89
+ - store_test_results:
90
+ path: test_results
91
+ - store_artifacts:
92
+ path: test_results
93
+ destination: test-results
94
+ - store_artifacts:
95
+ path: coverage
96
+ destination: test-coverage
97
+
98
+ upload-coverage:
99
+ <<: *defaults
100
+ steps:
101
+ - *attach_workspace
102
+ - run:
103
+ name: Upload coverage results to Code Climate
104
+ command: |
105
+ ./tmp/cc-test-reporter sum-coverage tmp/codeclimate.*.json -p 2 -o tmp/codeclimate.total.json
106
+ ./tmp/cc-test-reporter upload-coverage -i tmp/codeclimate.total.json
107
+
108
+ run-rubocop:
109
+ <<: *defaults
110
+ steps:
111
+ - *restore_repo
112
+ - *attach_workspace
113
+ - run:
114
+ name: Set bundler path
115
+ command: bin/bundle --path vendor/bundle
116
+ - run:
117
+ name: Run rubocop
118
+ command: bin/bundle exec rubocop
119
+
120
+ workflows:
121
+ version: 2
122
+ build-test:
123
+ jobs:
124
+ - checkout-code
125
+ - bundle-dependencies:
126
+ requires:
127
+ - checkout-code
128
+ - run-rubocop:
129
+ requires:
130
+ - bundle-dependencies
131
+ - run-specs:
132
+ requires:
133
+ - bundle-dependencies
134
+ - upload-coverage:
135
+ requires:
136
+ - run-specs
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # Zerobounce
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/35879ed0fe903e15175e/maintainability)](https://codeclimate.com/github/afrase/zerobounce/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/35879ed0fe903e15175e/test_coverage)](https://codeclimate.com/github/afrase/zerobounce/test_coverage)
4
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fafrase%2Fzerobounce.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fafrase%2Fzerobounce?ref=badge_shield)
5
+ [![Gem Version](https://badge.fury.io/rb/zerobounce.svg)](https://badge.fury.io/rb/zerobounce)
2
6
 
3
7
  A ruby client for Zerobounce.net API.
4
8
 
@@ -54,6 +58,8 @@ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
58
  The gem is available as open source under the terms of the
55
59
  [MIT License](https://opensource.org/licenses/MIT).
56
60
 
61
+ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fafrase%2Fzerobounce.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fafrase%2Fzerobounce?ref=badge_large)
62
+
57
63
  ## Code of Conduct
58
64
 
59
65
  Everyone interacting in the Zerobounce project’s codebases, issue trackers,
@@ -8,6 +8,7 @@ require 'zerobounce/configuration'
8
8
 
9
9
  # Validate an email address with Zerobounce.net
10
10
  module Zerobounce
11
+ # @author Aaron Frase
11
12
  class << self
12
13
  attr_writer :configuration
13
14
 
@@ -6,6 +6,26 @@ require 'zerobounce/middleware/raise_error'
6
6
 
7
7
  module Zerobounce
8
8
  # Configuration object for Zerobounce.
9
+ #
10
+ # @author Aaron Frase
11
+ #
12
+ # @attr [String] host
13
+ # The Zerobounce API host.
14
+ #
15
+ # @attr [Hash] headers
16
+ # Headers to use in all requests.
17
+ #
18
+ # @attr [String] api_key
19
+ # A Zerobounce API key.
20
+ #
21
+ # @attr [Proc] middleware
22
+ # The middleware used by Faraday for each request.
23
+ #
24
+ # @note If you modify the default make sure to add middleware to parse
25
+ # the response as json and symbolize the keys.
26
+ #
27
+ # @attr [Array<Symbol>] valid_statues
28
+ # The statuses that are considered valid by {Response#valid?}.
9
29
  class Configuration
10
30
  attr_accessor :host
11
31
  attr_accessor :headers
@@ -4,17 +4,23 @@ require 'json'
4
4
 
5
5
  module Zerobounce
6
6
  # The base Zerobounce error.
7
+ #
8
+ # @author Aaron Frase
7
9
  class Error < StandardError
8
- def initialize(env=nil)
10
+ def initialize(env={})
9
11
  @env = env
10
12
  end
11
13
 
12
14
  # Message for the error.
15
+ #
16
+ # @return [String]
13
17
  def message
14
18
  @env[:body]
15
19
  end
16
20
 
17
21
  class << self
22
+ # Parse the response for errors.
23
+ #
18
24
  # @param [Hash] env
19
25
  # @return [Error]
20
26
  def from_response(env)
@@ -28,31 +34,41 @@ module Zerobounce
28
34
 
29
35
  private
30
36
 
37
+ # @param [Hash] env
38
+ # @return [Error]
31
39
  def parse_500(env)
32
- if env[:body].start_with?('Missing parameter')
40
+ if env[:body]&.start_with?('Missing parameter')
33
41
  MissingParameter.new(env)
34
42
  else
35
43
  InternalServerError.new(env)
36
44
  end
37
45
  end
38
46
 
47
+ # @param [Hash] env
48
+ # @return [Error, nil]
39
49
  def parse_200(env)
40
50
  # The body hasn't been parsed yet and to avoid potentially parsing the body twice
41
51
  # we just use String#start_with?
42
- ApiError.new(env) if env[:body].start_with?('{"error":"')
52
+ ApiError.new(env) if env[:body]&.start_with?('{"error":"')
43
53
  end
44
54
  end
45
55
  end
46
56
 
47
57
  # Server returned a 500 error.
58
+ #
59
+ # @author Aaron Frase
48
60
  class InternalServerError < Error
49
61
  end
50
62
 
51
63
  # A parameter was missing, usually the apiKey.
64
+ #
65
+ # @author Aaron Frase
52
66
  class MissingParameter < Error
53
67
  end
54
68
 
55
69
  # General API error, the response code was 200 but an error still occurred.
70
+ #
71
+ # @author Aaron Frase
56
72
  class ApiError < Error
57
73
  # @see #message
58
74
  def message
@@ -6,8 +6,13 @@ module Zerobounce
6
6
  # Faraday middleware.
7
7
  module Middleware
8
8
  # Raises an error if the response wasn't successful.
9
+ #
10
+ # @author Aaron Frase
9
11
  class RaiseError < Faraday::Response::Middleware
10
12
  # Check for errors after the response has finished.
13
+ #
14
+ # @param [Hash] env
15
+ # @raise [Error]
11
16
  def on_complete(env)
12
17
  if (error = Zerobounce::Error.from_response(env)) # rubocop:disable GuardClause
13
18
  raise error
@@ -7,11 +7,23 @@ module Zerobounce
7
7
  #
8
8
  # @author Aaron Frase
9
9
  #
10
- # @attr_reader [String] url The path of the request.
11
- # @attr_reader [String] host The host to send the request to.
12
- # @attr_reader [Hash] headers The headers used for the request.
13
- # @attr_reader [Proc] middleware Faraday middleware used for the request.
10
+ # @attr_reader [String] url
11
+ # The path of the request.
12
+ #
13
+ # @attr_reader [String] host
14
+ # The host to send the request to.
15
+ #
16
+ # @attr_reader [Hash] headers
17
+ # The headers used for the request.
18
+ #
19
+ # @attr_reader [Proc] middleware
20
+ # Faraday middleware used for the request.
14
21
  class Request
22
+ # The normal email validation endpoint.
23
+ VALIDATE_PATH = '/v1/validate'
24
+ # The validation endpoint for email and IP validation.
25
+ VALIDATE_WITH_IP_PATH = '/v1/validatewithip'
26
+
15
27
  attr_reader :url
16
28
  attr_reader :host
17
29
  attr_reader :headers
@@ -21,11 +33,11 @@ module Zerobounce
21
33
  # @option params [String] :middleware default: {Configuration#middleware} {include:#middleware}
22
34
  # @option params [String] :headers default: {Configuration#headers} {include:#headers}
23
35
  # @option params [String] :host default: {Configuration#host} {include:#host}
24
- def initialize(params)
36
+ def initialize(params={})
25
37
  @middleware = params[:middleware] || Zerobounce.config.middleware
26
38
  @headers = params[:headers] || Zerobounce.config.headers
27
39
  @host = params[:host] || Zerobounce.config.host
28
- @url = params.key?(:ipaddress) || params.key?(:ip_address) ? '/v1/validatewithip' : '/v1/validate'
40
+ @url = params.key?(:ipaddress) || params.key?(:ip_address) ? VALIDATE_WITH_IP_PATH : VALIDATE_PATH
29
41
  end
30
42
 
31
43
  # Sends a GET request.
@@ -40,7 +52,7 @@ module Zerobounce
40
52
 
41
53
  # @return [Faraday::Connection]
42
54
  def conn
43
- @conn ||= Faraday.new(server, headers: headers, &middleware)
55
+ @conn ||= Faraday.new(host, headers: headers, &middleware)
44
56
  end
45
57
 
46
58
  # @param [Hash] params
@@ -5,8 +5,13 @@ require 'time'
5
5
  module Zerobounce
6
6
  # A Zerobounce response
7
7
  #
8
+ # @author Aaron Frase
9
+ #
8
10
  # @attr_reader [Zerobounce::Request] request
11
+ # The request instance.
12
+ #
9
13
  # @attr_reader [Faraday::Response] response
14
+ # The original {https://www.rubydoc.info/gems/faraday/0.15.2/Faraday/Response Faraday::Response}
10
15
  class Response
11
16
  attr_reader :response
12
17
  attr_reader :request
@@ -30,17 +35,36 @@ module Zerobounce
30
35
  # :abuse
31
36
  # :do_not_mail
32
37
  #
33
- # @return [Symbol]
38
+ # @return [Symbol] The status as a +Symbol+.
34
39
  def status
35
40
  @status ||= underscore(@body[:status])&.to_sym
36
41
  end
37
42
 
38
- # antispam_system | greylisted | mail_server_temporary_error | forcible_disconnect | mail_server_did_not_respond |
39
- # timeout_exceeded | failed_smtp_connection | mailbox_quota_exceeded | exception_occurred | possible_traps |
40
- # role_based | global_suppression | mailbox_not_found | no_dns_entries | failed_syntax_check | possible_typo |
41
- # unroutable_ip_address | leading_period_removed | does_not_accept_mail | alias_address
43
+ # A more detailed status
42
44
  #
43
- # @return [Symbol]
45
+ # Possible values:
46
+ # :antispam_system
47
+ # :greylisted
48
+ # :mail_server_temporary_error
49
+ # :forcible_disconnect
50
+ # :mail_server_did_not_respond
51
+ # :timeout_exceeded
52
+ # :failed_smtp_connection
53
+ # :mailbox_quota_exceeded
54
+ # :exception_occurred
55
+ # :possible_traps
56
+ # :role_based
57
+ # :global_suppression
58
+ # :mailbox_not_found
59
+ # :no_dns_entries
60
+ # :failed_syntax_check
61
+ # :possible_typo
62
+ # :unroutable_ip_address
63
+ # :leading_period_removed
64
+ # :does_not_accept_mail
65
+ # :alias_address
66
+ #
67
+ # @return [Symbol] The sub_status as a +Symbol+.
44
68
  def sub_status
45
69
  @sub_status ||= underscore(@body[:sub_status])&.to_sym
46
70
  end
@@ -124,12 +148,14 @@ module Zerobounce
124
148
 
125
149
  # Is this email considered valid?
126
150
  #
151
+ # @note Uses the values from {Zerobounce::Configuration#valid_statuses}
152
+ #
127
153
  # @return [Boolean]
128
154
  def valid?
129
155
  @valid ||= Zerobounce.config.valid_statuses.include?(status)
130
156
  end
131
157
 
132
- # The opposite of #valid?
158
+ # The opposite of {#valid?}
133
159
  #
134
160
  # @return [Boolean]
135
161
  def invalid?
@@ -141,7 +167,7 @@ module Zerobounce
141
167
  # These are temporary emails created for the sole purpose to sign up to websites without giving their real
142
168
  # email address. These emails are short lived from 15 minutes to around 6 months.
143
169
  #
144
- # @note If you have valid emails with this flag set to `true`, you shouldn't email them.
170
+ # @note If you have valid emails with this flag set to +true+, you shouldn't email them.
145
171
  #
146
172
  # @return [Boolean]
147
173
  def disposable?
@@ -171,16 +197,21 @@ module Zerobounce
171
197
  @creation_date ||= @body[:creationdate] && Time.parse(@body[:creationdate])
172
198
  end
173
199
 
200
+ # Returns a string containing a human-readable representation.
201
+ #
202
+ # @note Overriding inspect to hide the {#request}/{#response} instance variables
203
+ #
174
204
  # @return [String]
175
205
  def inspect
176
- # Overriding inspect to hide the @request/@response instance variables
177
206
  "#<#{self.class.name}:#{object_id}>"
178
207
  end
179
208
 
209
+ # Convert to a hash.
210
+ #
180
211
  # @return [Hash]
181
212
  def to_h
182
213
  public_methods(false).each_with_object({}) do |meth, memo|
183
- next if %i[request response inspect to_json to_h].include?(meth)
214
+ next if %i[request response inspect to_h].include?(meth)
184
215
  memo[meth] = send(meth)
185
216
  end
186
217
  end
@@ -191,9 +222,7 @@ module Zerobounce
191
222
  # @return [String, nil]
192
223
  def underscore(word)
193
224
  return if word.nil? || word.empty?
194
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') # for words like HTTPResponse => HTTP_Response
195
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') # for words like ResponseCode Response_Code
196
- word.downcase.tr('-', '_')
225
+ word.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.tr('-', '_')
197
226
  end
198
227
  end
199
228
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Zerobounce
4
4
  # The version of the gem.
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -4,7 +4,7 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'zerobounce/version'
6
6
 
7
- Gem::Specification.new do |spec|
7
+ Gem::Specification.new do |spec| # rubocop:disable BlockLength
8
8
  spec.name = 'zerobounce'
9
9
  spec.version = Zerobounce::VERSION
10
10
  spec.authors = ['Aaron Frase']
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
+ spec.metadata['yard.run'] = 'yri' # use "yard" to build full HTML docs.
26
+
25
27
  spec.add_dependency 'faraday', '~> 0.14'
26
28
  spec.add_dependency 'faraday_middleware', '~> 0.12'
27
29
 
@@ -29,7 +31,9 @@ Gem::Specification.new do |spec|
29
31
  spec.add_development_dependency 'pry', '~> 0.11.3'
30
32
  spec.add_development_dependency 'rake', '~> 10.0'
31
33
  spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3.0'
32
35
  spec.add_development_dependency 'rubocop', '~> 0.52'
33
36
  spec.add_development_dependency 'rubocop-rspec', '~> 1.22', '>= 1.22.2'
37
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
34
38
  spec.add_development_dependency 'yard', '~> 0.9.12'
35
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zerobounce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Frase
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.3.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.3.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +142,20 @@ dependencies:
128
142
  - - ">="
129
143
  - !ruby/object:Gem::Version
130
144
  version: 1.22.2
145
+ - !ruby/object:Gem::Dependency
146
+ name: simplecov
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: 0.16.1
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: 0.16.1
131
159
  - !ruby/object:Gem::Dependency
132
160
  name: yard
133
161
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +177,7 @@ executables: []
149
177
  extensions: []
150
178
  extra_rdoc_files: []
151
179
  files:
180
+ - ".circleci/config.yml"
152
181
  - ".editorconfig"
153
182
  - ".gitignore"
154
183
  - ".rspec"
@@ -174,7 +203,8 @@ files:
174
203
  homepage: https://github.com/afrase/zerobounce
175
204
  licenses:
176
205
  - MIT
177
- metadata: {}
206
+ metadata:
207
+ yard.run: yri
178
208
  post_install_message:
179
209
  rdoc_options: []
180
210
  require_paths: