Class: Verifalia::Client

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

Overview

HTTPS-based REST client for Verifalia.

Constant Summary collapse

VERSION =

The version of the Verifalia SDK for Ruby.

'2.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authenticator: nil, username: nil, password: nil, ssl_client_cert: nil, ssl_client_key: nil, base_urls: nil, logger: nil) ⇒ Client

Initializes a new HTTPS-based REST client for Verifalia with the specified options.

While authenticating with your Verifalia main account credentials is possible, it is strongly advised to create one or more users (formerly known as sub-accounts) with just the required permissions, for improved security. To create a new user or manage existing ones, please visit ‘verifalia.com/client-area#/users

Parameters:

  • authenticator (nil) (defaults to: nil)

    A custom authenticator the client will use to authenticate against the Verifalia API.

  • username (nil) (defaults to: nil)

    The user-name used to authenticate against the Verifalia API using basic auth.

  • password (nil) (defaults to: nil)

    The password used to authenticate against the Verifalia API using basic auth.

  • ssl_client_cert (nil) (defaults to: nil)

    The X.509 client certificate used to authenticate against the Verifalia API using mutual TLS authentication. Available to premium Verifalia plans only.

  • ssl_client_key (nil) (defaults to: nil)

    The private key used to authenticate against the Verifalia API using mutual TLS authentication. Available to premium Verifalia plans only.

  • base_urls (nil) (defaults to: nil)

    Alternative base URLs to use while connecting against the Verifalia API.

  • logger (nil) (defaults to: nil)

    A logger where to write diagnostics messages, useful while debugging.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/verifalia/client.rb', line 60

def initialize(authenticator: nil, username: nil, password: nil, ssl_client_cert: nil, ssl_client_key: nil, base_urls: nil, logger: nil)
  @base_urls = base_urls

  # Initialize the authenticator this client will use while connecting to the Verifalia API

  if !authenticator.nil?
    @authenticator = authenticator
  elsif !username.nil?
    @authenticator = Verifalia::Security::UsernamePasswordAuthenticator.new(username, password)
  elsif !ssl_client_cert.nil?
    @authenticator = Verifalia::Security::CertificateAuthenticator.new(ssl_client_cert, ssl_client_key)
    @base_urls ||= Verifalia::Rest::BASE_CCA_URLS
  else
    raise ArgumentError, 'Username is nil and no other authentication method was specified: please visit https://verifalia.com/client-area to set up a new user, if you don\'t have one.'
  end

  @base_urls ||= Verifalia::Rest::BASE_URLS
  @rest_client = Verifalia::Rest::Client.new(@authenticator,
                                             "verifalia-rest-client/ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}/#{VERSION}",
                                             @base_urls)

  @rest_client.logger = logger

  # Initialize the underlying resource clients

  @email_validations = Verifalia::EmailValidations::Client.new(@rest_client)
  @credits = Verifalia::Credits::Client.new(@rest_client)
end

Instance Attribute Details

#creditsObject (readonly)

Manages credit packs, daily free credits and usage consumption for the Verifalia account.



45
46
47
# File 'lib/verifalia/client.rb', line 45

def credits
  @credits
end

#email_validationsObject (readonly)

Allows to verify email addresses and manage email verification jobs using the Verifalia service.



42
43
44
# File 'lib/verifalia/client.rb', line 42

def email_validations
  @email_validations
end