class CheckMail::Client

Attributes

options[RW]

Public Class Methods

new(_account_sid, _auth_token) click to toggle source
# File lib/checkmail/client.rb, line 10
def initialize _account_sid, _auth_token

    #
    # verify the values
    #
    if (!_account_sid =~ /^[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        => 'https://api.checkmail.io/',
        :account_sid    => _account_sid,
        :auth_token     => _auth_token
    }

end

Public Instance Methods

verify(_address, _timeout=8000) click to toggle source

process a verification

# 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