Class: MailboxLayer::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/email_address_validation.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_key) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
# File 'lib/email_address_validation.rb', line 13

def initialize(access_key)

  if access_key.nil?
    raise MailboxLayer::MissingArgumentException.new 'access_key'
  end

  @access_key = access_key

end

Instance Method Details

#check(email, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/email_address_validation.rb', line 24

def check(email, options = {})

  if email.nil?
    raise MailboxLayer::MissingArgumentException.new 'email'
    return
  end

  # Create a shallow copy so we don't manipulate the original reference
  query = options.dup

  # Populate the Query
  query.access_key = @access_key
  query.email = email

  # We then create the Request
  req = CheckRequest.new(query)

  #  We create a Hash of the request so we can send it via HTTP
  req_dto = req.to_dh

  begin

    # We make the actual request
    res = self.class.get('/check', req_dto)

    # We ensure that we tap the response so we can use the results
    res.inspect

    # We just return the parsed binary response
    return res.parsed_response

  rescue => e
    puts e.inspect
    return

  end
end