Skip to content

Commit cf8ecfe

Browse files
Updated to call MailboxValidator v2 APIs
1 parent 707950d commit cf8ecfe

File tree

6 files changed

+74
-66
lines changed

6 files changed

+74
-66
lines changed

LICENSE.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 MailboxValidator.com
3+
Copyright (c) 2023 MailboxValidator.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@ Performs email validation on the supplied email address.
4343
| ------------- | ------------------------------------------------------------ |
4444
| email_address | The input email address. |
4545
| domain | The domain of the email address. |
46-
| is_free | Whether the email address is from a free email provider like Gmail or Hotmail. Return values: True, False |
47-
| is_syntax | Whether the email address is syntactically correct. Return values: True, False |
48-
| is_domain | Whether the email address has a valid MX record in its DNS entries. Return values: True, False, - (- means not applicable) |
49-
| is_smtp | Whether the mail servers specified in the MX records are responding to connections. Return values: True, False, - (- means not applicable) |
50-
| is_verified | Whether the mail server confirms that the email address actually exist. Return values: True, False, - (- means not applicable) |
51-
| is_server_down | Whether the mail server is currently down or unresponsive. Return values: True, False, -   (- means not applicable) |
52-
| is_greylisted | Whether the mail server employs greylisting where an email has to be sent a second time at a later time. Return values: True, False, -   (- means not applicable) |
53-
| is_disposable | Whether the email address is a temporary one from a disposable email provider. Return values: True, False, -   (- means not applicable) |
54-
| is_suppressed | Whether the email address is in our blacklist. Return values: True, False, -   (- means not applicable) |
55-
| is_role | Whether the email address is a role-based email address like admin@example.net or webmaster@example.net. Return values: True, False, -   (- means not applicable) |
56-
| is_high_risk | Whether the email address contains high risk keywords. Return values: True, False, -   (- means not applicable) |
57-
| is_catchall | Whether the email address is a catch-all address. Return values: True, False, Unknown, -   (- means not applicable) |
46+
| is_free | Whether the email address is from a free email provider like Gmail or Hotmail. Return values: true, false, null (null means not applicable) |
47+
| is_syntax | Whether the email address is syntactically correct. Return values: true, false |
48+
| is_domain | Whether the email address has a valid MX record in its DNS entries. Return values: true, false, null (null means not applicable) |
49+
| is_smtp | Whether the mail servers specified in the MX records are responding to connections. Return values: true, false, null (null means not applicable) |
50+
| is_verified | Whether the mail server confirms that the email address actually exist. Return values: true, false, null (null means not applicable) |
51+
| is_server_down | Whether the mail server is currently down or unresponsive. Return values: true, false, null (null means not applicable) |
52+
| is_greylisted | Whether the mail server employs greylisting where an email has to be sent a second time at a later time. Return values: true, false, null (null means not applicable) |
53+
| is_disposable | Whether the email address is a temporary one from a disposable email provider. Return values: true, false, null (null means not applicable) |
54+
| is_suppressed | Whether the email address is in our blacklist. Return values: true, false, null (null means not applicable) |
55+
| is_role | Whether the email address is a role-based email address like admin@example.net or webmaster@example.net. Return values: true, false, null (null means not applicable) |
56+
| is_high_risk | Whether the email address contains high risk keywords. Return values: true, false, null (null means not applicable) |
57+
| is_catchall | Whether the email address is a catch-all address. Return values: true, false, null (null means not applicable) |
5858
| mailboxvalidator_score | Email address reputation score. Score > 0.70 means good; score > 0.40 means fair; score <= 0.40 means poor. |
5959
| time_taken | The time taken to get the results in seconds. |
60-
| status | Whether our system think the email address is valid based on all the previous fields. Return values: True, False |
60+
| status | Whether our system think the email address is valid based on all the previous fields. Return values: true, false |
6161
| credits_available | The number of credits left to perform validations. |
62-
| error_code | The error code if there is any error. See error table in the below section. |
63-
| error_message | The error message if there is any error. See error table in the below section. |
62+
| error.error_code | The error code if there is any error. See error table in the below section. |
63+
| error.error_message | The error message if there is any error. See error table in the below section. |
6464

6565
## disposable_email(email_address)
6666

@@ -71,10 +71,10 @@ Checks if the supplied email address is from a disposable email provider.
7171
| Field Name | Description |
7272
|-----------|------------|
7373
| email_address | The input email address. |
74-
| is_disposable | Whether the email address is a temporary one from a disposable email provider. Return values: True, False |
74+
| is_disposable | Whether the email address is a temporary one from a disposable email provider. Return values: true, false |
7575
| credits_available | The number of credits left to perform validations. |
76-
| error_code | The error code if there is any error. See error table in the below section. |
77-
| error_message | The error message if there is any error. See error table in the below section. |
76+
| error.error_code | The error code if there is any error. See error table in the below section. |
77+
| error.error_message | The error message if there is any error. See error table in the below section. |
7878

7979
## free_email(email_address)
8080

@@ -85,10 +85,10 @@ Checks if the supplied email address is from a free email provider.
8585
| Field Name | Description |
8686
|-----------|------------|
8787
| email_address | The input email address. |
88-
| is_free | Whether the email address is from a free email provider like Gmail or Hotmail. Return values: True, False |
88+
| is_free | Whether the email address is from a free email provider like Gmail or Hotmail. Return values: true, false |
8989
| credits_available | The number of credits left to perform validations. |
90-
| error_code | The error code if there is any error. See error table in the below section. |
91-
| error_message | The error message if there is any error. See error table below. |
90+
| error.error_code | The error code if there is any error. See error table in the below section. |
91+
| error.error_message | The error message if there is any error. See error table below. |
9292

9393
# Sample Code
9494

@@ -106,7 +106,10 @@ mbv.apikey = apikey
106106

107107
mbv.query_single(email)
108108

109-
if mbv.error != nil
109+
if mbv.error != nil && mbv.result != nil
110+
puts "error_code: #{mbv.result.error.error_code}"
111+
puts "error_message: #{mbv.result.error.error_message}"
112+
elsif mbv.error != nil
110113
puts "Error: #{mbv.error}"
111114
elsif mbv.result != nil
112115
puts "email_address: #{mbv.result.email_address}"
@@ -127,8 +130,6 @@ elsif mbv.result != nil
127130
puts "time_taken: #{mbv.result.time_taken}"
128131
puts "status: #{mbv.result.status}"
129132
puts "credits_available: #{mbv.result.credits_available}"
130-
puts "error_code: #{mbv.result.error_code}"
131-
puts "error_message: #{mbv.result.error_message}"
132133
end
133134

134135
```
@@ -147,14 +148,15 @@ mbv.apikey = apikey
147148

148149
mbv.disposable_email(email)
149150

150-
if mbv.error != nil
151+
if mbv.error != nil && mbv.result != nil
152+
puts "error_code: #{mbv.result.error.error_code}"
153+
puts "error_message: #{mbv.result.error.error_message}"
154+
elsif mbv.error != nil
151155
puts "Error: #{mbv.error}"
152156
elsif mbv.result != nil
153157
puts "email_address: #{mbv.result.email_address}"
154158
puts "is_disposable: #{mbv.result.is_disposable}"
155159
puts "credits_available: #{mbv.result.credits_available}"
156-
puts "error_code: #{mbv.result.error_code}"
157-
puts "error_message: #{mbv.result.error_message}"
158160
end
159161

160162
```
@@ -173,14 +175,15 @@ mbv.apikey = apikey
173175

174176
mbv.free_email(email)
175177

176-
if mbv.error != nil
178+
if mbv.error != nil && mbv.result != nil
179+
puts "error_code: #{mbv.result.error.error_code}"
180+
puts "error_message: #{mbv.result.error.error_message}"
181+
elsif mbv.error != nil
177182
puts "Error: #{mbv.error}"
178183
elsif mbv.result != nil
179184
puts "email_address: #{mbv.result.email_address}"
180185
puts "is_free: #{mbv.result.is_free}"
181186
puts "credits_available: #{mbv.result.credits_available}"
182-
puts "error_code: #{mbv.result.error_code}"
183-
puts "error_message: #{mbv.result.error_message}"
184187
end
185188

186189
```
@@ -191,14 +194,15 @@ Errors
191194

192195
| error_code | error_message |
193196
| ---------- | ------------- |
194-
| 100 | Missing parameter. |
195-
| 101 | API key not found. |
196-
| 102 | API key disabled. |
197-
| 103 | API key expired. |
198-
| 104 | Insufficient credits. |
199-
| 105 | Unknown error. |
197+
| 10000 | Missing parameter. |
198+
| 10001 | API key not found. |
199+
| 10002 | API key disabled. |
200+
| 10003 | API key expired. |
201+
| 10004 | Insufficient credits. |
202+
| 10005 | Unknown error. |
203+
| 10006 | Invalid email syntax. |
200204

201205
Copyright
202206
=========
203207

204-
Copyright (C) 2018-2020 by MailboxValidator.com, support@mailboxvalidator.com
208+
Copyright (C) 2023 by MailboxValidator.com, support@mailboxvalidator.com

README.rdoc

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ mbv.apikey = apikey
1212

1313
mbv.query_single(email)
1414

15-
if mbv.error != nil
15+
if mbv.error != nil && mbv.result != nil
16+
puts "error_code: #{mbv.result.error.error_code}"
17+
puts "error_message: #{mbv.result.error.error_message}"
18+
elsif mbv.error != nil
1619
puts "Error: #{mbv.error}"
1720
elsif mbv.result != nil
1821
puts "email_address: #{mbv.result.email_address}"
@@ -33,32 +36,32 @@ elsif mbv.result != nil
3336
puts "time_taken: #{mbv.result.time_taken}"
3437
puts "status: #{mbv.result.status}"
3538
puts "credits_available: #{mbv.result.credits_available}"
36-
puts "error_code: #{mbv.result.error_code}"
37-
puts "error_message: #{mbv.result.error_message}"
3839
end
3940

4041
mbv.disposable_email(email)
4142

42-
if mbv.error != nil
43+
if mbv.error != nil && mbv.result != nil
44+
puts "error_code: #{mbv.result.error.error_code}"
45+
puts "error_message: #{mbv.result.error.error_message}"
46+
elsif mbv.error != nil
4347
puts "Error: #{mbv.error}"
4448
elsif mbv.result != nil
4549
puts "email_address: #{mbv.result.email_address}"
4650
puts "is_disposable: #{mbv.result.is_disposable}"
4751
puts "credits_available: #{mbv.result.credits_available}"
48-
puts "error_code: #{mbv.result.error_code}"
49-
puts "error_message: #{mbv.result.error_message}"
5052
end
5153

5254
mbv.free_email(email)
5355

54-
if mbv.error != nil
56+
if mbv.error != nil && mbv.result != nil
57+
puts "error_code: #{mbv.result.error.error_code}"
58+
puts "error_message: #{mbv.result.error.error_message}"
59+
elsif mbv.error != nil
5560
puts "Error: #{mbv.error}"
5661
elsif mbv.result != nil
5762
puts "email_address: #{mbv.result.email_address}"
5863
puts "is_free: #{mbv.result.is_free}"
5964
puts "credits_available: #{mbv.result.credits_available}"
60-
puts "error_code: #{mbv.result.error_code}"
61-
puts "error_message: #{mbv.result.error_message}"
6265
end
6366

6467
== Dependencies
@@ -67,5 +70,5 @@ end
6770

6871
== Copyright
6972

70-
Copyright (c) 2020 MailboxValidator.com
73+
Copyright (c) 2023 MailboxValidator.com
7174

lib/mailboxvalidator_ruby.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def initialize(apikey = "")
1616

1717
def query_single(email)
1818
@email = CGI.escape(email)
19-
uri = URI("https://api.mailboxvalidator.com/v1/validation/single?key=#{@apikey}&email=#{@email}")
19+
uri = URI("https://api.mailboxvalidator.com/v2/validation/single?key=#{@apikey}&email=#{@email}")
2020

2121
begin
2222
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
@@ -28,7 +28,7 @@ def query_single(email)
2828
@error = nil
2929
else
3030
@error = "#{response.code} - #{response.message}"
31-
@result = nil
31+
@result = JSON.parse(response.body, object_class: OpenStruct)
3232
end
3333
end
3434
rescue Exception => e
@@ -39,7 +39,7 @@ def query_single(email)
3939

4040
def disposable_email(email)
4141
@email = CGI.escape(email)
42-
uri = URI("https://api.mailboxvalidator.com/v1/email/disposable?key=#{@apikey}&email=#{@email}")
42+
uri = URI("https://api.mailboxvalidator.com/v2/email/disposable?key=#{@apikey}&email=#{@email}")
4343

4444
begin
4545
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
@@ -51,7 +51,7 @@ def disposable_email(email)
5151
@error = nil
5252
else
5353
@error = "#{response.code} - #{response.message}"
54-
@result = nil
54+
@result = JSON.parse(response.body, object_class: OpenStruct)
5555
end
5656
end
5757
rescue Exception => e
@@ -62,7 +62,7 @@ def disposable_email(email)
6262

6363
def free_email(email)
6464
@email = CGI.escape(email)
65-
uri = URI("https://api.mailboxvalidator.com/v1/email/free?key=#{@apikey}&email=#{@email}")
65+
uri = URI("https://api.mailboxvalidator.com/v2/email/free?key=#{@apikey}&email=#{@email}")
6666

6767
begin
6868
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
@@ -74,7 +74,7 @@ def free_email(email)
7474
@error = nil
7575
else
7676
@error = "#{response.code} - #{response.message}"
77-
@result = nil
77+
@result = JSON.parse(response.body, object_class: OpenStruct)
7878
end
7979
end
8080
rescue Exception => e

mailboxvalidator_ruby.gemspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
Gem::Specification.new do |s|
22
s.name = 'mailboxvalidator_ruby'
3-
s.version = '1.2.1'
3+
s.version = '2.0.0'
44
s.required_ruby_version = '>= 2.0.0'
5-
s.date = '2018-09-13'
65
s.summary = "MailboxValidator API wrapper"
76
s.description = "Enable users to block disposal email, detect free email and validate if an email is valid"
87
s.author = "MailboxValidator"

spec/mailboxvalidator_ruby_webservice_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
describe "MailboxvalidatorRuby" do
44
it "work correctly with invalid api key" do
5-
mbv = MailboxValidator::MBV.new()
6-
mbv.apikey = $api_key
7-
mbv.query_single('example@example.com')
8-
expect(mbv.result.error_message).to eq 'API key not found.'
5+
if $api_key == 'YOUR_API_KEY'
6+
mbv = MailboxValidator::MBV.new()
7+
mbv.apikey = $api_key
8+
mbv.query_single('example@example.com')
9+
expect(mbv.result.error.error_message).to eq 'API key not found.'
10+
end
911
end
1012

1113
it "work correctly with api key exists" do
@@ -28,9 +30,9 @@
2830
mbv.apikey = $api_key
2931
mbv.query_single('example@example.com')
3032
if $api_key == 'YOUR_API_KEY'
31-
expect(mbv.result.error_code).to eq '101'
33+
expect(mbv.result.error.error_code).to eq 10001
3234
else
33-
expect(mbv.result.status).to eq 'False'
35+
expect(mbv.result.status).to eq false
3436
end
3537
end
3638

@@ -39,9 +41,9 @@
3941
mbv.apikey = $api_key
4042
mbv.disposable_email('example@example.com')
4143
if $api_key == 'YOUR_API_KEY'
42-
expect(mbv.result.error_code).to eq '101'
44+
expect(mbv.result.error.error_code).to eq 10001
4345
else
44-
expect(mbv.result.status).to eq 'True'
46+
expect(mbv.result.is_disposable).to eq false
4547
end
4648
end
4749

@@ -50,9 +52,9 @@
5052
mbv.apikey = $api_key
5153
mbv.free_email('example@example.com')
5254
if $api_key == 'YOUR_API_KEY'
53-
expect(mbv.result.error_code).to eq '101'
55+
expect(mbv.result.error.error_code).to eq 10001
5456
else
55-
expect(mbv.result.status).to eq 'False'
57+
expect(mbv.result.is_free).to eq false
5658
end
5759
end
5860

0 commit comments

Comments
 (0)