Class: MailboxValidator::MBV
- Inherits:
-
Object
- Object
- MailboxValidator::MBV
- Defined in:
- lib/mailboxvalidator_ruby.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
Returns the value of attribute apikey.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(apikey = "") ⇒ MBV
constructor
A new instance of MBV.
- #query_single(email) ⇒ Object
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
#apikey ⇒ Object
Returns the value of attribute apikey.
9 10 11 |
# File 'lib/mailboxvalidator_ruby.rb', line 9 def apikey @apikey end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
10 11 12 |
# File 'lib/mailboxvalidator_ruby.rb', line 10 def error @error end |
#result ⇒ Object (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.}" @result = nil end end rescue Exception => e @error = e. @result = nil end end |