zerobounce 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/zerobounce.rb +36 -4
- data/lib/zerobounce/request.rb +36 -8
- data/lib/zerobounce/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ada25c0d24b88fdce7947569fc15212b44d07e9
|
4
|
+
data.tar.gz: 797bd934fc6cad5ac9e1c86272877086d06b490b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: '
|
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
|
data/lib/zerobounce.rb
CHANGED
@@ -32,20 +32,52 @@ module Zerobounce
|
|
32
32
|
yield configuration
|
33
33
|
end
|
34
34
|
|
35
|
-
#
|
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
|
-
|
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
|
48
|
-
validate(email: email).
|
79
|
+
def invalid?(email, params={})
|
80
|
+
validate(params.merge(email: email)).invalid?
|
49
81
|
end
|
50
82
|
end
|
51
83
|
end
|
data/lib/zerobounce/request.rb
CHANGED
@@ -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
|
-
#
|
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
|
48
|
-
Response.new(
|
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)
|
data/lib/zerobounce/version.rb
CHANGED