zerobounce 0.0.5 → 0.2.0

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
- SHA1:
3
- metadata.gz: 8ada25c0d24b88fdce7947569fc15212b44d07e9
4
- data.tar.gz: 797bd934fc6cad5ac9e1c86272877086d06b490b
2
+ SHA256:
3
+ metadata.gz: f4bfc224ce092b8c62648cec52d26f94a80b501f75dad50dd035b91e3a46cbab
4
+ data.tar.gz: d9d93f3ac83d697f45676abd22b4281971229e0756d3e287e3e9150a67d4b13e
5
5
  SHA512:
6
- metadata.gz: 9a0b0757b6de2e2d1568f953d41483d9264427f42e624b080edd95faec250076fd7db344c451bc6a0cea76086f7ae5fed1487e214b931327a72e0184b598f094
7
- data.tar.gz: 24c9e0940c90d06e41ebcc5a46af2948eeeca2919b6387733da473cf3d06990239487f050e32a46f9f08d792f0dffff9553cca703d0ed331c62b9c4f0482d879
6
+ metadata.gz: 70876ead4ecad57b9fa09812c04ebb6bf6dee39d32c699a84e8735bd519b611fc8dc8a3e3c94b1483ae8bf407f6e2f665022fb9014bdb7424c06345af813c8db
7
+ data.tar.gz: a2a0a495b3fa207556427caed2ee411a1af9ead813ea4b68d9ff4d390f8ca77629bbbe9a89602c495a02f81b57a2b519fe466e21310a9eac610b1e65672c154e
@@ -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,43 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+ packages: write
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby 2.6
18
+ uses: actions/setup-ruby@v1
19
+ with:
20
+ ruby-version: 2.6.x
21
+
22
+ - name: Publish to GPR
23
+ run: |
24
+ mkdir -p $HOME/.gem
25
+ touch $HOME/.gem/credentials
26
+ chmod 0600 $HOME/.gem/credentials
27
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
+ gem build *.gemspec
29
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
30
+ env:
31
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
32
+ OWNER: ${{ github.repository_owner }}
33
+
34
+ - name: Publish to RubyGems
35
+ run: |
36
+ mkdir -p $HOME/.gem
37
+ touch $HOME/.gem/credentials
38
+ chmod 0600 $HOME/.gem/credentials
39
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
40
+ gem build *.gemspec
41
+ gem push *.gem
42
+ env:
43
+ 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: [ master ]
12
+ pull_request:
13
+ branches: [ master ]
14
+
15
+ jobs:
16
+ test:
17
+
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - name: Set up Ruby
26
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
27
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
28
+ # uses: ruby/setup-ruby@v1
29
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
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
@@ -14,3 +14,4 @@ Gemfile.lock
14
14
 
15
15
  # rspec failure tracking
16
16
  .rspec_status
17
+ .env
data/.rubocop.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  require: rubocop-rspec
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.4
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
- Metrics/LineLength:
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.4.3
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
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
  ```ruby
28
28
  # Configure the client
29
29
  Zerobounce.configure do |config|
30
- config.api_key = 'key'
30
+ config.apikey = 'key'
31
31
  config.valid_statuses = [:valid, :catch_all, :unknown]
32
32
  end
33
33
 
data/bin/console CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  require 'bundler/setup'
4
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
5
  require 'pry'
6
+
10
7
  Pry.start
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/zerobounce.rb CHANGED
@@ -24,7 +24,7 @@ module Zerobounce
24
24
  #
25
25
  # @example
26
26
  # Zerobounce.configure do |config|
27
- # config.api_key = 'api-key'
27
+ # config.apikey = 'api-key'
28
28
  # end
29
29
  #
30
30
  # @yieldparam [Zerobounce::Configuration] config
@@ -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
- if params.key?(:ipaddress) || params.key?(:ip_address)
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.
@@ -15,7 +15,7 @@ module Zerobounce
15
15
  # @attr [Hash] headers
16
16
  # Headers to use in all requests.
17
17
  #
18
- # @attr [String] api_key
18
+ # @attr [String] apikey
19
19
  # A Zerobounce API key.
20
20
  #
21
21
  # @attr [Proc] middleware
@@ -24,23 +24,29 @@ 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
30
33
  attr_accessor :host
31
34
  attr_accessor :headers
32
- attr_accessor :api_key
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
- self.api_key = ENV['ZEROBOUNCE_API_KEY']
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
@@ -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
- end
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
- parse_500(env)
25
+ parse500(env)
30
26
  when 200
31
- parse_200(env)
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 parse_500(env)
40
- if env[:body]&.start_with?('Missing parameter')
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 parse_200(env)
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]&.start_with?('{"error":"')
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
@@ -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
- end
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
- # Validate the email address and get geoip info for the IP.
51
- #
52
- # @param [Hash] params
53
- # @option params [String] :email
54
- # @option params [String] :ip_address
55
- # @option params [String] :apikey
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(GET_CREDITS_PATH, params).body[:Credits]&.to_i
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.api_key }.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