Class: MailboxValidator::MBV

Inherits:
Object
  • Object
show all
Defined in:
lib/mailboxvalidator_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey = "") ⇒ MBV

Returns a new instance of MBV.



12
13
14
15
# File 'lib/mailboxvalidator_ruby.rb', line 12

def initialize(apikey = "")
	@apikey = apikey
	@error = nil
end

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



9
10
11
# File 'lib/mailboxvalidator_ruby.rb', line 9

def apikey
  @apikey
end

#errorObject (readonly)

Returns the value of attribute error.



10
11
12
# File 'lib/mailboxvalidator_ruby.rb', line 10

def error
  @error
end

#resultObject (readonly)

Returns the value of attribute result.



10
11
12
# File 'lib/mailboxvalidator_ruby.rb', line 10

def result
  @result
end

Instance Method Details

#query_single(email) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mailboxvalidator_ruby.rb', line 17

def query_single(email)
	@email = CGI.escape(email)
	uri = URI("https://api.mailboxvalidator.com/v1/validation/single?key=#{@apikey}&email=#{@email}")
	
	begin
		Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
			request = Net::HTTP::Get.new uri
			response = http.request request
			
			if response.code == "200"
				@result = JSON.parse(response.body, object_class: OpenStruct)
				@error = nil
			else
				@error = "#{response.code} - #{response.message}"
				@result = nil
			end
		end
	rescue Exception => e
		@error = e.message
		@result = nil
	end
end