Class: Truemail::Validate::Smtp::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/truemail/validate/smtp/request.rb

Defined Under Namespace

Classes: Configuration, Session

Constant Summary collapse

CONNECTION_TIMEOUT_ERROR =
'connection timed out'
RESPONSE_TIMEOUT_ERROR =
'server response timeout'
CONNECTION_DROPPED =
'server dropped connection after response'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration:, host:, email:, attempts: nil, port_open_status: proc { true }) ⇒ Request

Returns a new instance of Request.



13
14
15
16
17
18
19
20
# File 'lib/truemail/validate/smtp/request.rb', line 13

def initialize(configuration:, host:, email:, attempts: nil, port_open_status: proc { true })
  @configuration = Truemail::Validate::Smtp::Request::Configuration.new(configuration)
  @response = Truemail::Validate::Smtp::Response.new
  @host = host
  @email = email
  @attempts = attempts
  @port_open_status = port_open_status
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



11
12
13
# File 'lib/truemail/validate/smtp/request.rb', line 11

def configuration
  @configuration
end

#emailObject (readonly)

Returns the value of attribute email.



11
12
13
# File 'lib/truemail/validate/smtp/request.rb', line 11

def email
  @email
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/truemail/validate/smtp/request.rb', line 11

def host
  @host
end

#responseObject (readonly)

Returns the value of attribute response.



11
12
13
# File 'lib/truemail/validate/smtp/request.rb', line 11

def response
  @response
end

Instance Method Details

#check_portObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/truemail/validate/smtp/request.rb', line 22

def check_port
  response.port_opened = ::Socket.tcp(
    host,
    configuration.smtp_port,
    connect_timeout: configuration.connection_timeout,
    &port_open_status
  )
rescue => error
  retry if attempts_exist? && error.is_a?(::Errno::ETIMEDOUT)
  response.port_opened = false
end

#runObject



34
35
36
37
38
39
# File 'lib/truemail/validate/smtp/request.rb', line 34

def run
  session.start(verifier_domain, &session_actions)
rescue => error
  retry if attempts_exist?
  assign_error(attribute: :connection, message: compose_from(error))
end