zerobounce 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c26d8ef84543260f1c12b728f44ab9c25f9ddd12
4
- data.tar.gz: 23e8dd446e127532d5da39d7394b48cfb342d663
3
+ metadata.gz: 8ada25c0d24b88fdce7947569fc15212b44d07e9
4
+ data.tar.gz: 797bd934fc6cad5ac9e1c86272877086d06b490b
5
5
  SHA512:
6
- metadata.gz: 6141f44171fbe3a7589a1a02ef6c60df3b0d4dd9fe20e9b574d702670c7a445079081691c66b03938f40a3a4915e7af610b2745e9460804e19e6cfa8b88143d7
7
- data.tar.gz: a473b7a08f5eb680f07d71e33f5f3d5898593a8f001df15166c7dcdcadb02c1c133d40242a9ce5092ad5557e3e5de7a9f5033a0f69107859cf1e2ec5d410d73b
6
+ metadata.gz: 9a0b0757b6de2e2d1568f953d41483d9264427f42e624b080edd95faec250076fd7db344c451bc6a0cea76086f7ae5fed1487e214b931327a72e0184b598f094
7
+ data.tar.gz: 24c9e0940c90d06e41ebcc5a46af2948eeeca2919b6387733da473cf3d06990239487f050e32a46f9f08d792f0dffff9553cca703d0ed331c62b9c4f0482d879
data/README.md CHANGED
@@ -25,13 +25,22 @@ Or install it yourself as:
25
25
  ## Usage
26
26
 
27
27
  ```ruby
28
+ # Configure the client
28
29
  Zerobounce.configure do |config|
29
30
  config.api_key = 'key'
31
+ config.valid_statuses = [:valid, :catch_all, :unknown]
30
32
  end
31
33
 
32
- Zerobounce.validate(email: 'example@example.com')
33
- resp = Zerobounce.validate(email: 'example@example.com', ip_address: '127.0.0.1')
34
+ resp = Zerobounce.validate(email: 'valid@example.com')
34
35
  resp.valid? # => true
36
+
37
+ # Change what is considered a valid status
38
+ Zerobounce.valid?('invalid@example.com') # => false
39
+ Zerobounce.config.valid_statuses = [:invalid]
40
+ Zerobounce.valid?('invalid@example.com') # => true
41
+
42
+ # Use a different API key for one request
43
+ Zerobounce.validate(email: 'valid@example.com', apikey: 'different-api-key')
35
44
  ```
36
45
 
37
46
  ## Development
@@ -32,20 +32,52 @@ module Zerobounce
32
32
  yield configuration
33
33
  end
34
34
 
35
- # Validate an email address and/or IP address.
35
+ # Validates the email address and gets geoip information for an IP if provided.
36
36
  #
37
37
  # @param [Hash] params
38
+ # @option params [String] :email The email address to validate.
39
+ # @option params [String] :ip_address An IP address, :ipaddress also works.
40
+ # @option params [String] :apikey Use a different API key for this request.
41
+ # @option params [String] :host Use a different host for this request.
42
+ # @option params [String] :headers Use different headers for this request.
43
+ # @option params [Proc] :middleware Use different middleware for this request.
38
44
  # @return [Zerobounce::Response]
39
45
  def validate(params)
40
- Request.new(params).get(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
51
+ end
52
+
53
+ # Get the number of remaining credits on the account.
54
+ #
55
+ # @param [Hash] params
56
+ # @option params [String] :apikey Use a different API key for this request.
57
+ # @option params [String] :host Use a different host for this request.
58
+ # @option params [String] :headers Use different headers for this request.
59
+ # @option params [Proc] :middleware Use different middleware for this request.
60
+ # @return [Integer]
61
+ def credits(params={})
62
+ Request.new(params).credits(params)
41
63
  end
42
64
 
43
65
  # Convenience method for checking if an email address is valid.
44
66
  #
45
67
  # @param [String] email
68
+ # @param [Hash] params
69
+ # @return [Boolean]
70
+ def valid?(email, params={})
71
+ validate(params.merge(email: email)).valid?
72
+ end
73
+
74
+ # Convenience method for checking if an email address is invalid.
75
+ #
76
+ # @param [String] email
77
+ # @param [Hash] params
46
78
  # @return [Boolean]
47
- def valid?(email)
48
- validate(email: email).valid?
79
+ def invalid?(email, params={})
80
+ validate(params.merge(email: email)).invalid?
49
81
  end
50
82
  end
51
83
  end
@@ -7,9 +7,6 @@ module Zerobounce
7
7
  #
8
8
  # @author Aaron Frase
9
9
  #
10
- # @attr_reader [String] url
11
- # The path of the request.
12
- #
13
10
  # @attr_reader [String] host
14
11
  # The host to send the request to.
15
12
  #
@@ -23,8 +20,9 @@ module Zerobounce
23
20
  VALIDATE_PATH = '/v1/validate'
24
21
  # The validation endpoint for email and IP validation.
25
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'
26
25
 
27
- attr_reader :url
28
26
  attr_reader :host
29
27
  attr_reader :headers
30
28
  attr_reader :middleware
@@ -37,19 +35,49 @@ module Zerobounce
37
35
  @middleware = params[:middleware] || Zerobounce.config.middleware
38
36
  @headers = params[:headers] || Zerobounce.config.headers
39
37
  @host = params[:host] || Zerobounce.config.host
40
- @url = params.key?(:ipaddress) || params.key?(:ip_address) ? VALIDATE_WITH_IP_PATH : VALIDATE_PATH
41
38
  end
42
39
 
43
- # Sends a GET request.
40
+ # Validate the email address.
44
41
  #
45
42
  # @param [Hash] params
43
+ # @option params [String] :email
44
+ # @option params [String] :apikey
46
45
  # @return [Zerobounce::Response]
47
- def get(params={})
48
- Response.new(conn.get(url, get_params(params)), self)
46
+ def validate(params)
47
+ Response.new(get(VALIDATE_PATH, params), self)
48
+ end
49
+
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)
59
+ end
60
+
61
+ # Get the number of remaining credits on the account.
62
+ #
63
+ # @param [Hash] params
64
+ # @option params [String] :apikey
65
+ # @return [Integer] A value of -1 can mean the API is invalid.
66
+ def credits(params={})
67
+ get(GET_CREDITS_PATH, params).body[:Credits]&.to_i
49
68
  end
50
69
 
51
70
  private
52
71
 
72
+ # Sends a GET request.
73
+ #
74
+ # @param [Hash] params
75
+ # @param [String] path
76
+ # @return [Zerobounce::Response]
77
+ def get(path, params)
78
+ conn.get(path, get_params(params))
79
+ end
80
+
53
81
  # @return [Faraday::Connection]
54
82
  def conn
55
83
  @conn ||= Faraday.new(host, headers: headers, &middleware)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Zerobounce
4
4
  # The version of the gem.
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zerobounce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Frase