zerobounce 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5073bd0edd03b300161b3b85ea16ef52af8695e
4
+ data.tar.gz: 1527033d9b898a7355fb3427a2de216159f51711
5
+ SHA512:
6
+ metadata.gz: 78ce4fbae3708ad80bb1688f892143a7580f36a67d97ff77f21853aa1c3d2bc3cc4aa49434a99cadbf9b728ec1eaa63cb91a45b04588a709bfb7e73d76be5b21
7
+ data.tar.gz: 0661ffd922bb6d9e17491d92066c4b865cb6c3855dc427716d683cfe325a10aaf11406684082bd69f61c5dc7df39c8e8a81dfa407469f135cc22a6d279bdaadc
@@ -0,0 +1,15 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.{sh,md}]
13
+ indent_size = 4
14
+ max_line_length = 0
15
+ trim_trailing_whitespace = false
@@ -0,0 +1,16 @@
1
+ # Rubymine
2
+ .idea/
3
+
4
+ /.bundle/
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ .DS_Store
13
+ Gemfile.lock
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,38 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+
6
+ Exclude:
7
+ - 'bin/*'
8
+ - 'vendor/**/*'
9
+
10
+ Style/ClassAndModuleChildren:
11
+ Enabled: false
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Metrics/AbcSize:
17
+ Max: 18
18
+
19
+ Metrics/LineLength:
20
+ Max: 120
21
+ Exclude:
22
+ - 'spec/**/*'
23
+
24
+ Metrics/MethodLength:
25
+ Max: 20
26
+
27
+ Metrics/BlockLength:
28
+ Exclude:
29
+ - 'spec/**/*'
30
+
31
+ Layout/SpaceAroundEqualsInParameterDefault:
32
+ EnforcedStyle: no_space
33
+
34
+ Style/SymbolArray:
35
+ Enabled: true
36
+
37
+ RSpec/NestedGroups:
38
+ Max: 5
@@ -0,0 +1 @@
1
+ zerobounce
@@ -0,0 +1 @@
1
+ ruby-2.4.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at afrase91@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in zerobounce.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Aaron Frase
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # Zerobounce
2
+
3
+ A ruby client for Zerobounce.net API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'zerobounce'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install zerobounce
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ Zerobounce.configure do |config|
25
+ config.api_key = 'key'
26
+ end
27
+
28
+ Zerobounce.validate(email: 'example@example.com')
29
+ resp = Zerobounce.validate(email: 'example@example.com', ip_address: '127.0.0.1')
30
+ resp.valid? # => true
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies.
36
+ Then, run `rake spec` to run the tests. You can also run `bin/console`
37
+ for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`.
40
+ To release a new version, update the version number in `version.rb`,
41
+ and then run `bundle exec rake release`, which will create a git tag for
42
+ the version, push git commits and tags, and push the `.gem` file to
43
+ [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at
48
+ https://github.com/afrase/zerobounce. This project is intended to be a safe,
49
+ welcoming space for collaboration, and contributors are expected to adhere
50
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the
55
+ [MIT License](https://opensource.org/licenses/MIT).
56
+
57
+ ## Code of Conduct
58
+
59
+ Everyone interacting in the Zerobounce project’s codebases, issue trackers,
60
+ chat rooms and mailing lists is expected to follow the
61
+ [code of conduct](https://github.com/afrase/zerobounce/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yard'
4
+ require 'bundler/gem_tasks'
5
+ require 'rspec/core/rake_task'
6
+ require 'rubocop/rake_task'
7
+ require 'zerobounce/version'
8
+
9
+ RSpec::Core::RakeTask.new
10
+
11
+ RuboCop::RakeTask.new do |task|
12
+ task.requires << 'rubocop-rspec'
13
+ end
14
+
15
+ YARD::Rake::YardocTask.new do |task|
16
+ task.options += ['--title', "Zerobounce #{Zerobounce::VERSION} Documentation"]
17
+ task.options += ['--protected']
18
+ task.options += ['--no-private']
19
+ task.stats_options = ['--list-undoc']
20
+
21
+ # has to be last
22
+ extra_files = %w[CODE_OF_CONDUCT.md LICENSE.txt]
23
+ task.options += ['-'] + extra_files
24
+ end
25
+
26
+ task default: %i[rubocop spec]
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1 || ">= 0.a"
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||= begin
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version || "#{Gem::Requirement.default}.a"
67
+ end
68
+ end
69
+
70
+ def load_bundler!
71
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+ # must dup string for RG < 1.8 compatibility
74
+ activate_bundler(bundler_version.dup)
75
+ end
76
+
77
+ def activate_bundler(bundler_version)
78
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+ bundler_version = "< 2"
80
+ end
81
+ gem_error = activation_error_handling do
82
+ gem "bundler", bundler_version
83
+ end
84
+ return if gem_error.nil?
85
+ require_error = activation_error_handling do
86
+ require "bundler/version"
87
+ end
88
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+ exit 42
91
+ end
92
+
93
+ def activation_error_handling
94
+ yield
95
+ nil
96
+ rescue StandardError, LoadError => e
97
+ e
98
+ end
99
+ end
100
+
101
+ m.load_bundler!
102
+
103
+ if m.invoked_as_script?
104
+ load Gem.bin_path("bundler", "bundle")
105
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'zerobounce'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zerobounce/error'
4
+ require 'zerobounce/version'
5
+ require 'zerobounce/request'
6
+ require 'zerobounce/response'
7
+ require 'zerobounce/configuration'
8
+
9
+ # Validate an email address with Zerobounce.net
10
+ module Zerobounce
11
+ class << self
12
+ attr_writer :configuration
13
+
14
+ # Zerobounce configuration
15
+ #
16
+ # @return [Zerobounce::Configuration]
17
+ def configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+ alias config configuration
21
+
22
+ # Configure Zerobounce inside a block.
23
+ #
24
+ # @example
25
+ # Zerobounce.configure do |config|
26
+ # config.api_key = 'api-key'
27
+ # end
28
+ #
29
+ # @yieldparam [Zerobounce::Configuration] config
30
+ def configure
31
+ yield configuration
32
+ end
33
+
34
+ # Validate an email address and/or IP address.
35
+ #
36
+ # @param [Hash] params
37
+ # @return [Zerobounce::Response]
38
+ def validate(params)
39
+ Request.new(params).get(params)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'zerobounce/middleware/raise_error'
6
+
7
+ module Zerobounce
8
+ # Configuration object for Zerobounce.
9
+ class Configuration
10
+ attr_accessor :host
11
+ attr_accessor :headers
12
+ attr_accessor :api_key
13
+ attr_accessor :middleware
14
+ attr_accessor :valid_statuses
15
+
16
+ def initialize
17
+ self.host = 'https://api.zerobounce.net'
18
+ self.api_key = ENV['ZEROBOUNCE_API_KEY']
19
+ self.valid_statuses = %i[valid catch_all]
20
+ self.headers = { user_agent: "ZerobounceRubyGem/#{Zerobounce::VERSION}" }
21
+
22
+ self.middleware = proc do |builder|
23
+ builder.response(:json, content_type: /\bjson$/, parser_options: { symbolize_names: true })
24
+ builder.use(Zerobounce::Middleware::RaiseError)
25
+ builder.adapter(Faraday.default_adapter)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Zerobounce
6
+ # The base Zerobounce error.
7
+ class Error < StandardError
8
+ def initialize(env=nil)
9
+ @env = env
10
+ end
11
+
12
+ # Message for the error.
13
+ def message
14
+ @env[:body]
15
+ end
16
+
17
+ class << self
18
+ # @param [Hash] env
19
+ # @return [Error]
20
+ def from_response(env)
21
+ case env[:status]
22
+ when 500
23
+ parse_500(env)
24
+ when 200
25
+ parse_200(env)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def parse_500(env)
32
+ if env[:body].start_with?('Missing parameter')
33
+ MissingParameter.new(env)
34
+ else
35
+ InternalServerError.new(env)
36
+ end
37
+ end
38
+
39
+ def parse_200(env)
40
+ # The body hasn't been parsed yet and to avoid potentially parsing the body twice
41
+ # we just use String#start_with?
42
+ ApiError.new(env) if env[:body].start_with?('{"error":"')
43
+ end
44
+ end
45
+ end
46
+
47
+ # Server returned a 500 error.
48
+ class InternalServerError < Error
49
+ end
50
+
51
+ # A parameter was missing, usually the apiKey.
52
+ class MissingParameter < Error
53
+ end
54
+
55
+ # General API error, the response code was 200 but an error still occurred.
56
+ class ApiError < Error
57
+ # @see #message
58
+ def message
59
+ JSON.parse(@env[:body])['error']
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zerobounce/error'
4
+
5
+ module Zerobounce
6
+ # Faraday middleware.
7
+ module Middleware
8
+ # Raises an error if the response wasn't successful.
9
+ class RaiseError < Faraday::Response::Middleware
10
+ # Check for errors after the response has finished.
11
+ def on_complete(env)
12
+ if (error = Zerobounce::Error.from_response(env)) # rubocop:disable GuardClause
13
+ raise error
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Zerobounce
6
+ # Sends the HTTP request.
7
+ #
8
+ # @author Aaron Frase
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.
14
+ class Request
15
+ attr_reader :url
16
+ attr_reader :host
17
+ attr_reader :headers
18
+ attr_reader :middleware
19
+
20
+ # @param [Hash] params
21
+ # @option params [String] :middleware default: {Configuration#middleware} {include:#middleware}
22
+ # @option params [String] :headers default: {Configuration#headers} {include:#headers}
23
+ # @option params [String] :host default: {Configuration#host} {include:#host}
24
+ def initialize(params)
25
+ @middleware = params[:middleware] || Zerobounce.config.middleware
26
+ @headers = params[:headers] || Zerobounce.config.headers
27
+ @host = params[:host] || Zerobounce.config.host
28
+ @url = params.key?(:ipaddress) || params.key?(:ip_address) ? '/v1/validatewithip' : '/v1/validate'
29
+ end
30
+
31
+ # Sends a GET request.
32
+ #
33
+ # @param [Hash] params
34
+ # @return [Zerobounce::Response]
35
+ def get(params={})
36
+ Response.new(conn.get(url, get_params(params)), self)
37
+ end
38
+
39
+ private
40
+
41
+ # @return [Faraday::Connection]
42
+ def conn
43
+ @conn ||= Faraday.new(server, headers: headers, &middleware)
44
+ end
45
+
46
+ # @param [Hash] params
47
+ # @return [Hash]
48
+ def get_params(params)
49
+ valid_params = %i[apiKey ipaddress email]
50
+ params[:ipaddress] = params.delete(:ip_address) if params.key?(:ip_address) # normalize ipaddress key
51
+ { apiKey: Zerobounce.config.api_key }.merge(params.select { |k, _| valid_params.include?(k) })
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,199 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Zerobounce
6
+ # A Zerobounce response
7
+ #
8
+ # @attr_reader [Zerobounce::Request] request
9
+ # @attr_reader [Faraday::Response] response
10
+ class Response
11
+ attr_reader :response
12
+ attr_reader :request
13
+
14
+ # @param [Faraday::Response] response
15
+ # @param [Zerobounce::Request] request
16
+ def initialize(response, request)
17
+ @response = response
18
+ @request = request
19
+ @body = response.body
20
+ end
21
+
22
+ # Deliverability status
23
+ #
24
+ # Possible values:
25
+ # :valid
26
+ # :invalid
27
+ # :catch_all
28
+ # :unknown
29
+ # :spamtrap
30
+ # :abuse
31
+ # :do_not_mail
32
+ #
33
+ # @return [Symbol]
34
+ def status
35
+ @status ||= underscore(@body[:status])&.to_sym
36
+ end
37
+
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
42
+ #
43
+ # @return [Symbol]
44
+ def sub_status
45
+ @sub_status ||= underscore(@body[:sub_status])&.to_sym
46
+ end
47
+
48
+ # The email address you are validating.
49
+ #
50
+ # @return [String]
51
+ def address
52
+ @address ||= @body[:address]
53
+ end
54
+
55
+ # The portion of the email address before the "@" symbol.
56
+ #
57
+ # @return [String]
58
+ def account
59
+ @account ||= @body[:account]
60
+ end
61
+
62
+ # The portion of the email address after the "@" symbol.
63
+ #
64
+ # @return [String]
65
+ def domain
66
+ @domain ||= @body[:domain]
67
+ end
68
+
69
+ # The first name of the owner of the email when available.
70
+ #
71
+ # @return [String, nil]
72
+ def firstname
73
+ @firstname ||= @body[:firstname]
74
+ end
75
+
76
+ # The last name of the owner of the email when available.
77
+ #
78
+ # @return [String, nil]
79
+ def lastname
80
+ @lastname ||= @body[:lastname]
81
+ end
82
+
83
+ # The gender of the owner of the email when available.
84
+ #
85
+ # @return [String, nil]
86
+ def gender
87
+ @gender ||= @body[:gender]
88
+ end
89
+
90
+ # The location of the owner of the email when available.
91
+ #
92
+ # @return [String, nil]
93
+ def location
94
+ @location ||= @body[:location]
95
+ end
96
+
97
+ # The country of the IP passed in.
98
+ #
99
+ # @return [String, nil]
100
+ def country
101
+ @country ||= @body[:country]
102
+ end
103
+
104
+ # The region/state of the IP passed in.
105
+ #
106
+ # @return [String, nil]
107
+ def region
108
+ @region ||= @body[:region]
109
+ end
110
+
111
+ # The city of the IP passed in.
112
+ #
113
+ # @return [String, nil]
114
+ def city
115
+ @city ||= @body[:city]
116
+ end
117
+
118
+ # The zipcode of the IP passed in.
119
+ #
120
+ # @return [String, nil]
121
+ def zipcode
122
+ @zipcode ||= @body[:zipcode]
123
+ end
124
+
125
+ # Is this email considered valid?
126
+ #
127
+ # @return [Boolean]
128
+ def valid?
129
+ @valid ||= Zerobounce.config.valid_statuses.include?(status)
130
+ end
131
+
132
+ # The opposite of #valid?
133
+ #
134
+ # @return [Boolean]
135
+ def invalid?
136
+ !valid?
137
+ end
138
+
139
+ # If the email domain is disposable, which are usually temporary email addresses.
140
+ #
141
+ # These are temporary emails created for the sole purpose to sign up to websites without giving their real
142
+ # email address. These emails are short lived from 15 minutes to around 6 months.
143
+ #
144
+ # @note If you have valid emails with this flag set to `true`, you shouldn't email them.
145
+ #
146
+ # @return [Boolean]
147
+ def disposable?
148
+ @disposable ||= @body[:disposable] || false
149
+ end
150
+
151
+ # These domains are known for abuse, spam, or are bot created.
152
+ #
153
+ # @note If you have a valid email with this flag set to +true+, you shouldn't email them.
154
+ #
155
+ # @return [Boolean]
156
+ def toxic?
157
+ @toxic ||= @body[:toxic] || false
158
+ end
159
+
160
+ # The UTC time the email was validated.
161
+ #
162
+ # @return [Time, nil]
163
+ def process_date
164
+ @process_date ||= @body[:processedat] && Time.parse(@body[:processedat])
165
+ end
166
+
167
+ # The creation date of the email when available.
168
+ #
169
+ # @return [Time, nil]
170
+ def creation_date
171
+ @creation_date ||= @body[:creationdate] && Time.parse(@body[:creationdate])
172
+ end
173
+
174
+ # @return [String]
175
+ def inspect
176
+ # Overriding inspect to hide the @request/@response instance variables
177
+ "#<#{self.class.name}:#{object_id}>"
178
+ end
179
+
180
+ # @return [Hash]
181
+ def to_h
182
+ public_methods(false).each_with_object({}) do |meth, memo|
183
+ next if %i[request response inspect to_json to_h].include?(meth)
184
+ memo[meth] = send(meth)
185
+ end
186
+ end
187
+
188
+ private
189
+
190
+ # @param [String, nil] word
191
+ # @return [String, nil]
192
+ def underscore(word)
193
+ 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('-', '_')
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zerobounce
4
+ # The version of the gem.
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'zerobounce/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'zerobounce'
9
+ spec.version = Zerobounce::VERSION
10
+ spec.authors = ['Aaron Frase']
11
+ spec.email = ['afrase91@gmail.com']
12
+
13
+ spec.summary = 'A Ruby client for Zerobounce.net.'
14
+ spec.description = 'A Ruby client for Zerobounce.net.'
15
+ spec.homepage = 'https://github.com/afrase/zerobounce'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'faraday', '~> 0.14'
26
+ spec.add_dependency 'faraday_middleware', '~> 0.12'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'pry', '~> 0.11.3'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.52'
33
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.22', '>= 1.22.2'
34
+ spec.add_development_dependency 'yard', '~> 0.9.12'
35
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zerobounce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Frase
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-23 00:00:00.000000000 Z
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.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
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.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.52'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.52'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.22'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.22.2
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '1.22'
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 1.22.2
131
+ - !ruby/object:Gem::Dependency
132
+ name: yard
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.9.12
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.9.12
145
+ description: A Ruby client for Zerobounce.net.
146
+ email:
147
+ - afrase91@gmail.com
148
+ executables: []
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - ".editorconfig"
153
+ - ".gitignore"
154
+ - ".rspec"
155
+ - ".rubocop.yml"
156
+ - ".ruby-gemset"
157
+ - ".ruby-version"
158
+ - CODE_OF_CONDUCT.md
159
+ - Gemfile
160
+ - LICENSE.txt
161
+ - README.md
162
+ - Rakefile
163
+ - bin/bundle
164
+ - bin/console
165
+ - bin/setup
166
+ - lib/zerobounce.rb
167
+ - lib/zerobounce/configuration.rb
168
+ - lib/zerobounce/error.rb
169
+ - lib/zerobounce/middleware/raise_error.rb
170
+ - lib/zerobounce/request.rb
171
+ - lib/zerobounce/response.rb
172
+ - lib/zerobounce/version.rb
173
+ - zerobounce.gemspec
174
+ homepage: https://github.com/afrase/zerobounce
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.6.14
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: A Ruby client for Zerobounce.net.
198
+ test_files: []