zerobounce 0.0.6 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/dependabot.yml +10 -0
- data/.github/pull_request_template.md +22 -0
- data/.github/workflows/gem-push.yml +44 -0
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +1 -0
- data/README.md +1 -3
- data/bin/console +1 -4
- data/bin/setup +0 -2
- data/lib/zerobounce.rb +1 -5
- data/lib/zerobounce/configuration.rb +6 -0
- data/lib/zerobounce/error.rb +18 -14
- data/lib/zerobounce/middleware/raise_error.rb +1 -1
- data/lib/zerobounce/request.rb +15 -37
- data/lib/zerobounce/request/v1_request.rb +47 -0
- data/lib/zerobounce/request/v2_request.rb +32 -0
- data/lib/zerobounce/response.rb +12 -98
- data/lib/zerobounce/response/v1_response.rb +104 -0
- data/lib/zerobounce/response/v2_response.rb +97 -0
- data/lib/zerobounce/version.rb +1 -1
- data/zerobounce.gemspec +15 -11
- metadata +73 -29
- data/.circleci/config.yml +0 -136
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9317c9c0d5ce41ca5c3d27d9d71706383b9687d65b58eed217a786e1c4d1ab9a
|
4
|
+
data.tar.gz: 9924d6348aec8c24c470384569f183bc107746ac16d67c699b455c68e70b4b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa9a4f46f860bb9352e71ed50017cf6df96426a52d44b1f2c3ebdfa9f467a74b353bcbcd6ced03e19264034d141272f438763f2e8c0f098c901cf7cafed5532
|
7
|
+
data.tar.gz: eb17307f8b3bd194abfac75e20fa18c56856d3c421f4a98e294ba98114dcf80edf652d849b6cb56a39238f0a08ba02ac6866d4619286ab16ee157ac3bc41d4d2
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
2. Click on '....'
|
17
|
+
3. Scroll down to '....'
|
18
|
+
4. See error
|
19
|
+
|
20
|
+
**Expected behavior**
|
21
|
+
A clear and concise description of what you expected to happen.
|
22
|
+
|
23
|
+
**Screenshots**
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
25
|
+
|
26
|
+
**Additional context**
|
27
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: enhancement
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context or screenshots about the feature request here.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<!--- Provide a general summary of your changes in the Title above -->
|
2
|
+
|
3
|
+
## Description
|
4
|
+
<!--- Describe your changes in detail -->
|
5
|
+
|
6
|
+
## Related Issue
|
7
|
+
<!--- This project only accepts pull requests related to open issues -->
|
8
|
+
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
|
9
|
+
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
|
10
|
+
<!--- Please link to the issue here: -->
|
11
|
+
|
12
|
+
## Motivation and Context
|
13
|
+
<!--- Why is this change required? What problem does it solve? -->
|
14
|
+
|
15
|
+
## Checklist:
|
16
|
+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
17
|
+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
18
|
+
- [ ] My code follows the code style of this project.
|
19
|
+
- [ ] My change requires a change to the documentation.
|
20
|
+
- [ ] I have updated the documentation accordingly.
|
21
|
+
- [ ] I have added tests to cover my changes.
|
22
|
+
- [ ] All new and existing tests passed.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- v*
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Build + Publish
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
permissions:
|
13
|
+
contents: read
|
14
|
+
packages: write
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby 2.6
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.6.x
|
22
|
+
|
23
|
+
- name: Publish to GPR
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
31
|
+
env:
|
32
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
33
|
+
OWNER: ${{ github.repository_owner }}
|
34
|
+
|
35
|
+
- name: Publish to RubyGems
|
36
|
+
run: |
|
37
|
+
mkdir -p $HOME/.gem
|
38
|
+
touch $HOME/.gem/credentials
|
39
|
+
chmod 0600 $HOME/.gem/credentials
|
40
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
41
|
+
gem build *.gemspec
|
42
|
+
gem push *.gem
|
43
|
+
env:
|
44
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
name: Ruby
|
8
|
+
|
9
|
+
on:
|
10
|
+
push:
|
11
|
+
branches:
|
12
|
+
- master
|
13
|
+
- main
|
14
|
+
pull_request:
|
15
|
+
branches:
|
16
|
+
- master
|
17
|
+
- main
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
test:
|
21
|
+
runs-on: ubuntu-latest
|
22
|
+
strategy:
|
23
|
+
matrix:
|
24
|
+
ruby-version: [ '2.5', '2.6', '2.7', '3.0' ]
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
|
+
- name: Run tests
|
34
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require: rubocop-rspec
|
2
2
|
|
3
3
|
AllCops:
|
4
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.5
|
5
|
+
NewCops: enable
|
5
6
|
|
6
7
|
Exclude:
|
7
8
|
- 'bin/*'
|
@@ -16,7 +17,7 @@ Style/Documentation:
|
|
16
17
|
Metrics/AbcSize:
|
17
18
|
Max: 18
|
18
19
|
|
19
|
-
|
20
|
+
Layout/LineLength:
|
20
21
|
Max: 120
|
21
22
|
Exclude:
|
22
23
|
- 'spec/**/*'
|
@@ -36,3 +37,6 @@ Style/SymbolArray:
|
|
36
37
|
|
37
38
|
RSpec/NestedGroups:
|
38
39
|
Max: 5
|
40
|
+
|
41
|
+
Style/AccessorGrouping:
|
42
|
+
EnforcedStyle: separated
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# 0.2.0
|
2
|
+
|
3
|
+
* Update faraday and faraday_middleware dependency requirements.
|
4
|
+
* Update rubocop dev dependencies and fixed failures.
|
5
|
+
* Updated minimum ruby version to 2.5.
|
6
|
+
|
7
|
+
# 0.1.2
|
8
|
+
|
9
|
+
* Removed the double quote from the body check since it appears a space is added after the colon.
|
10
|
+
* Added changelog file.
|
11
|
+
|
12
|
+
# 0.1.1
|
13
|
+
|
14
|
+
* Removed safe accessor usage to work with older versions of Ruby.
|
15
|
+
|
16
|
+
# 0.1.0
|
17
|
+
|
18
|
+
* Added support for V2 of Zerobounce API.
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
TODO fill this out
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Zerobounce
|
2
|
-
[](https://codeclimate.com/github/afrase/zerobounce/test_coverage)
|
4
|
-
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fafrase%2Fzerobounce?ref=badge_shield)
|
2
|
+
[](https://github.com/afrase/zerobounce/actions/workflows/ruby.yml)
|
5
3
|
[](https://badge.fury.io/rb/zerobounce)
|
6
4
|
|
7
5
|
A ruby client for Zerobounce.net API.
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/lib/zerobounce.rb
CHANGED
@@ -43,11 +43,7 @@ module Zerobounce
|
|
43
43
|
# @option params [Proc] :middleware Use different middleware for this request.
|
44
44
|
# @return [Zerobounce::Response]
|
45
45
|
def validate(params)
|
46
|
-
|
47
|
-
Request.new(params).validate_with_ip(params)
|
48
|
-
else
|
49
|
-
Request.new(params).validate(params)
|
50
|
-
end
|
46
|
+
Request.new(params).validate(params)
|
51
47
|
end
|
52
48
|
|
53
49
|
# Get the number of remaining credits on the account.
|
@@ -24,6 +24,9 @@ module Zerobounce
|
|
24
24
|
# @note If you modify the default make sure to add middleware to parse
|
25
25
|
# the response as json and symbolize the keys.
|
26
26
|
#
|
27
|
+
# @attr [String] api_version
|
28
|
+
# The version of the API to use.
|
29
|
+
#
|
27
30
|
# @attr [Array<Symbol>] valid_statues
|
28
31
|
# The statuses that are considered valid by {Response#valid?}.
|
29
32
|
class Configuration
|
@@ -31,16 +34,19 @@ module Zerobounce
|
|
31
34
|
attr_accessor :headers
|
32
35
|
attr_accessor :apikey
|
33
36
|
attr_accessor :middleware
|
37
|
+
attr_accessor :api_version
|
34
38
|
attr_accessor :valid_statuses
|
35
39
|
|
36
40
|
def initialize
|
37
41
|
self.host = 'https://api.zerobounce.net'
|
38
42
|
self.apikey = ENV['ZEROBOUNCE_API_KEY']
|
43
|
+
self.api_version = 'v2'
|
39
44
|
self.valid_statuses = %i[valid catch_all]
|
40
45
|
self.headers = { user_agent: "ZerobounceRubyGem/#{Zerobounce::VERSION}" }
|
41
46
|
|
42
47
|
self.middleware = proc do |builder|
|
43
48
|
builder.response(:json, content_type: /\bjson$/, parser_options: { symbolize_names: true })
|
49
|
+
builder.response(:logger) { |l| l.filter(/(api_?key=)(\w+)/, '\1[REMOVED]') } if ENV['ZEROBOUNCE_API_DEBUG']
|
44
50
|
builder.use(Zerobounce::Middleware::RaiseError)
|
45
51
|
builder.adapter(Faraday.default_adapter)
|
46
52
|
end
|
data/lib/zerobounce/error.rb
CHANGED
@@ -7,28 +7,26 @@ module Zerobounce
|
|
7
7
|
#
|
8
8
|
# @author Aaron Frase
|
9
9
|
class Error < StandardError
|
10
|
+
attr_reader :env
|
11
|
+
|
10
12
|
def initialize(env={})
|
11
13
|
@env = env
|
12
|
-
|
13
|
-
|
14
|
-
# Message for the error.
|
15
|
-
#
|
16
|
-
# @return [String]
|
17
|
-
def message
|
18
|
-
@env[:body]
|
14
|
+
super(env[:body])
|
19
15
|
end
|
20
16
|
|
21
17
|
class << self
|
22
18
|
# Parse the response for errors.
|
23
19
|
#
|
24
20
|
# @param [Hash] env
|
25
|
-
# @return [Error]
|
21
|
+
# @return [Error, nil]
|
26
22
|
def from_response(env)
|
27
23
|
case env[:status]
|
28
24
|
when 500
|
29
|
-
|
25
|
+
parse500(env)
|
30
26
|
when 200
|
31
|
-
|
27
|
+
parse200(env)
|
28
|
+
else
|
29
|
+
UnknownError.new(env)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -36,8 +34,8 @@ module Zerobounce
|
|
36
34
|
|
37
35
|
# @param [Hash] env
|
38
36
|
# @return [Error]
|
39
|
-
def
|
40
|
-
if env[:body]
|
37
|
+
def parse500(env)
|
38
|
+
if env[:body].to_s.start_with?('Missing parameter')
|
41
39
|
MissingParameter.new(env)
|
42
40
|
else
|
43
41
|
InternalServerError.new(env)
|
@@ -46,10 +44,10 @@ module Zerobounce
|
|
46
44
|
|
47
45
|
# @param [Hash] env
|
48
46
|
# @return [Error, nil]
|
49
|
-
def
|
47
|
+
def parse200(env)
|
50
48
|
# The body hasn't been parsed yet and to avoid potentially parsing the body twice
|
51
49
|
# we just use String#start_with?
|
52
|
-
ApiError.new(env) if env[:body]
|
50
|
+
ApiError.new(env) if env[:body].to_s.start_with?('{"error":')
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
@@ -66,6 +64,12 @@ module Zerobounce
|
|
66
64
|
class MissingParameter < Error
|
67
65
|
end
|
68
66
|
|
67
|
+
# When the status code isn't in the defined codes to parse.
|
68
|
+
#
|
69
|
+
# @author Aaron Frase
|
70
|
+
class UnknownError < Error
|
71
|
+
end
|
72
|
+
|
69
73
|
# General API error, the response code was 200 but an error still occurred.
|
70
74
|
#
|
71
75
|
# @author Aaron Frase
|
@@ -14,7 +14,7 @@ module Zerobounce
|
|
14
14
|
# @param [Hash] env
|
15
15
|
# @raise [Error]
|
16
16
|
def on_complete(env)
|
17
|
-
if (error = Zerobounce::Error.from_response(env)) # rubocop:disable GuardClause
|
17
|
+
if (error = Zerobounce::Error.from_response(env)) # rubocop:disable Style/GuardClause
|
18
18
|
raise error
|
19
19
|
end
|
20
20
|
end
|
data/lib/zerobounce/request.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
+
require 'zerobounce/request/v1_request'
|
5
|
+
require 'zerobounce/request/v2_request'
|
4
6
|
|
5
7
|
module Zerobounce
|
6
8
|
# Sends the HTTP request.
|
@@ -16,46 +18,30 @@ module Zerobounce
|
|
16
18
|
# @attr_reader [Proc] middleware
|
17
19
|
# Faraday middleware used for the request.
|
18
20
|
class Request
|
19
|
-
# The normal email validation endpoint.
|
20
|
-
VALIDATE_PATH = '/v1/validate'
|
21
|
-
# The validation endpoint for email and IP validation.
|
22
|
-
VALIDATE_WITH_IP_PATH = '/v1/validatewithip'
|
23
|
-
# The path to get number number of credits remaining on the account.
|
24
|
-
GET_CREDITS_PATH = '/v1/getcredits'
|
25
|
-
|
26
21
|
attr_reader :host
|
27
22
|
attr_reader :headers
|
28
23
|
attr_reader :middleware
|
24
|
+
attr_reader :api_version
|
29
25
|
|
26
|
+
# Set instance variables and extends the correct Zerobounce::Request
|
27
|
+
#
|
30
28
|
# @param [Hash] params
|
31
29
|
# @option params [String] :middleware default: {Configuration#middleware} {include:#middleware}
|
32
30
|
# @option params [String] :headers default: {Configuration#headers} {include:#headers}
|
33
31
|
# @option params [String] :host default: {Configuration#host} {include:#host}
|
32
|
+
# @option params [String] :api_version default: {Configuration#api_version} {include:#api_version}
|
34
33
|
def initialize(params={})
|
35
34
|
@middleware = params[:middleware] || Zerobounce.config.middleware
|
36
35
|
@headers = params[:headers] || Zerobounce.config.headers
|
37
36
|
@host = params[:host] || Zerobounce.config.host
|
38
|
-
|
39
|
-
|
40
|
-
# Validate the email address.
|
41
|
-
#
|
42
|
-
# @param [Hash] params
|
43
|
-
# @option params [String] :email
|
44
|
-
# @option params [String] :apikey
|
45
|
-
# @return [Zerobounce::Response]
|
46
|
-
def validate(params)
|
47
|
-
Response.new(get(VALIDATE_PATH, params), self)
|
48
|
-
end
|
37
|
+
@api_version = params[:api_version] || Zerobounce.config.api_version
|
49
38
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# @return [Zerobounce::Response]
|
57
|
-
def validate_with_ip(params)
|
58
|
-
Response.new(get(VALIDATE_WITH_IP_PATH, params), self)
|
39
|
+
case api_version
|
40
|
+
when 'v2'
|
41
|
+
extend(V2Request)
|
42
|
+
else
|
43
|
+
extend(V1Request)
|
44
|
+
end
|
59
45
|
end
|
60
46
|
|
61
47
|
# Get the number of remaining credits on the account.
|
@@ -64,7 +50,7 @@ module Zerobounce
|
|
64
50
|
# @option params [String] :apikey
|
65
51
|
# @return [Integer] A value of -1 can mean the API is invalid.
|
66
52
|
def credits(params={})
|
67
|
-
get(
|
53
|
+
get('getcredits', params).body[:Credits].to_i
|
68
54
|
end
|
69
55
|
|
70
56
|
private
|
@@ -80,15 +66,7 @@ module Zerobounce
|
|
80
66
|
|
81
67
|
# @return [Faraday::Connection]
|
82
68
|
def conn
|
83
|
-
@conn ||= Faraday.new(host, headers: headers, &middleware)
|
84
|
-
end
|
85
|
-
|
86
|
-
# @param [Hash] params
|
87
|
-
# @return [Hash]
|
88
|
-
def get_params(params)
|
89
|
-
valid_params = %i[apikey ipaddress email]
|
90
|
-
params[:ipaddress] = params.delete(:ip_address) if params.key?(:ip_address) # normalize ipaddress key
|
91
|
-
{ apikey: Zerobounce.config.apikey }.merge(params.select { |k, _| valid_params.include?(k) })
|
69
|
+
@conn ||= Faraday.new("#{host}/#{api_version}", headers: headers, &middleware)
|
92
70
|
end
|
93
71
|
end
|
94
72
|
end
|