Skip to content

Commit dfa2c22

Browse files
new commit
0 parents  commit dfa2c22

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
MailboxValidator Ruby Module
2+
============================
3+
4+
This Ruby module provides an easy way to call the MailboxValidator API which validates if an email address is a valid one.
5+
6+
This module can be used in many types of projects such as:
7+
8+
- validating a user's email during sign up
9+
- cleaning your mailing list prior to an email marketing campaign
10+
- a form of fraud check
11+
12+
Installation
13+
============
14+
15+
To install this module type the following:
16+
17+
gem install mailboxvalidator-ruby
18+
19+
Dependencies
20+
============
21+
22+
An api key is required for this module to function.
23+
24+
Go to http://www.mailboxvalidator.com/plans to sign up for a trial plan or a paid plan and you'll be given an API key.
25+
26+
Copyright
27+
=========
28+
29+
Copyright (C) 2015 by MailboxValidator.com, [email protected]

README.rdoc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
= MailboxValidator
2+
3+
== Usage
4+
5+
require "mailboxvalidator_ruby"
6+
7+
apikey = "MY_API_KEY"
8+
9+
10+
mbv = MailboxValidator::MBV.new()
11+
mbv.apikey = apikey
12+
mbv.query_single(email)
13+
14+
if mbv.error != nil
15+
puts "Error: #{mbv.error}"
16+
elsif mbv.result != nil
17+
puts "email_address: #{mbv.result.email_address}"
18+
puts "domain: #{mbv.result.domain}"
19+
puts "is_free: #{mbv.result.is_free}"
20+
puts "is_syntax: #{mbv.result.is_syntax}"
21+
puts "is_domain: #{mbv.result.is_domain}"
22+
puts "is_smtp: #{mbv.result.is_smtp}"
23+
puts "is_verified: #{mbv.result.is_verified}"
24+
puts "is_server_down: #{mbv.result.is_server_down}"
25+
puts "is_greylisted: #{mbv.result.is_greylisted}"
26+
puts "is_disposable: #{mbv.result.is_disposable}"
27+
puts "is_suppressed: #{mbv.result.is_suppressed}"
28+
puts "is_role: #{mbv.result.is_role}"
29+
puts "is_high_risk: #{mbv.result.is_high_risk}"
30+
puts "status: #{mbv.result.status}"
31+
puts "credits_available: #{mbv.result.credits_available}"
32+
puts "error_code: #{mbv.result.error_code}"
33+
puts "error_message: #{mbv.result.error_message}"
34+
end
35+
36+
== Dependencies
37+
38+
* Go to http://www.mailboxvalidator.com/plans to sign up for a trial plan or a paid plan and you'll be given an API key.
39+
40+
== Copyright
41+
42+
Copyright (c) 2015 MailboxValidator.com
43+

lib/mailboxvalidator_ruby.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/ruby
2+
require 'cgi'
3+
require 'net/http'
4+
require 'json'
5+
require 'ostruct'
6+
7+
module MailboxValidator
8+
class MBV
9+
attr_accessor :apikey
10+
attr_reader :result, :error
11+
12+
def initialize(apikey = "")
13+
@apikey = apikey
14+
@error = nil
15+
end
16+
17+
def query_single(email)
18+
@email = CGI.escape(email)
19+
uri = URI("https://api.mailboxvalidator.com?key=#{@apikey}&email=#{@email}")
20+
21+
begin
22+
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
23+
request = Net::HTTP::Get.new uri
24+
response = http.request request
25+
26+
if response.code == "200"
27+
@result = JSON.parse(response.body, object_class: OpenStruct)
28+
@error = nil
29+
else
30+
@error = "#{response.code} - #{response.message}"
31+
@result = nil
32+
end
33+
end
34+
rescue Exception => e
35+
@error = e.message
36+
@result = nil
37+
end
38+
end
39+
end
40+
end

mailboxvalidator_ruby.gemspec

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Gem::Specification.new do |s|
2+
s.name = 'mailboxvalidator_ruby'
3+
s.version = '1.0.0'
4+
s.required_ruby_version = '>= 2.0.0'
5+
s.date = '2015-11-19'
6+
s.summary = "MailboxValidator API wrapper"
7+
s.description = "MailboxValidator API wrapper"
8+
s.author = "MailboxValidator"
9+
s.email = 'support@mailboxvalidator'
10+
s.files = ["lib/mailboxvalidator_ruby.rb","test/test.rb","README.rdoc"]
11+
s.homepage = 'http://www.mailboxvalidator.com/ruby'
12+
s.license = 'LGPL-3.0+'
13+
end

test/test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require "mailboxvalidator_ruby"
2+
3+
apikey = "MY_API_KEY"
4+
5+
6+
mbv = MailboxValidator::MBV.new()
7+
mbv.apikey = apikey
8+
mbv.query_single(email)
9+
10+
if mbv.error != nil
11+
puts "Error: #{mbv.error}"
12+
elsif mbv.result != nil
13+
puts "email_address: #{mbv.result.email_address}"
14+
puts "domain: #{mbv.result.domain}"
15+
puts "is_free: #{mbv.result.is_free}"
16+
puts "is_syntax: #{mbv.result.is_syntax}"
17+
puts "is_domain: #{mbv.result.is_domain}"
18+
puts "is_smtp: #{mbv.result.is_smtp}"
19+
puts "is_verified: #{mbv.result.is_verified}"
20+
puts "is_server_down: #{mbv.result.is_server_down}"
21+
puts "is_greylisted: #{mbv.result.is_greylisted}"
22+
puts "is_disposable: #{mbv.result.is_disposable}"
23+
puts "is_suppressed: #{mbv.result.is_suppressed}"
24+
puts "is_role: #{mbv.result.is_role}"
25+
puts "is_high_risk: #{mbv.result.is_high_risk}"
26+
puts "status: #{mbv.result.status}"
27+
puts "credits_available: #{mbv.result.credits_available}"
28+
puts "error_code: #{mbv.result.error_code}"
29+
puts "error_message: #{mbv.result.error_message}"
30+
end

0 commit comments

Comments
 (0)