Class: CheckMail::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_account_sid, _auth_token) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/checkmail/client.rb', line 10

def initialize , _auth_token

    #
    # verify the values
    #
    if (! =~ /^[A-Z]{2}[0-9a-f]{32}$/)      
        raise 'invalid API acount sid provided.'
    end
    if (!_auth_token =~ /^[0-9a-f]{64}$/)
        raise 'invalid API access token provided.'
    end

    #
    # store them locally
    #
    @options = {
    
        :api_url        => 'http://10.10.0.1/',
        :account_sid    => ,
        :auth_token     => _auth_token
    }

end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/checkmail/client.rb', line 8

def options
  @options
end

Instance Method Details

#verify(_address, _timeout = 8000) ⇒ Object

process a verification



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/checkmail/client.rb', line 37

def verify(_address, _timeout=8000)

    #
    # verify we have an address
    #
    if (_address.length == 0)
        raise 'empty email address provided.'
    end

    #
    # build the URL
    #
    uri = URI(@options[:api_url] + 'verify')

    #
    # create the HTTP object
    #
    http = Net::HTTP.new(uri.host, uri.port)

    #
    # build the request object, with authentication
    #
    request = Net::HTTP::Post.new(uri.request_uri)

    request.set_form_data('address' => _address, 'timeout' => _timeout)
    request.basic_auth(@options[:account_sid], @options[:auth_token])

    #
    # execute the request
    #
    res = http.request(request);

    #
    # return a hash
    #
    JSON.parse(res.body)
end