123456789_123456789_123456789_123456789_123456789_

Class: Net::SMTP::Authenticator

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/net/smtp/authenticator.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(smtp) ⇒ Authenticator

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 29

def initialize(smtp)
  @smtp = smtp
end

Class Method Details

.auth_class(type)

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 13

def self.auth_class(type)
  type = type.to_s.upcase.tr(?_, ?-).to_sym
  Authenticator.auth_classes[type]
end

.auth_classes

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 4

def self.auth_classes
  @classes ||= {}
end

.auth_type(type)

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 8

def self.auth_type(type)
  type = type.to_s.upcase.tr(?_, ?-).to_sym
  Authenticator.auth_classes[type] = self
end

.check_args(user_arg = nil, secret_arg = nil)

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 18

def self.check_args(user_arg = nil, secret_arg = nil, *, **)
  unless user_arg
    raise ArgumentError, 'SMTP-AUTH requested but missing user name'
  end
  unless secret_arg
    raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
  end
end

Instance Attribute Details

#smtp (readonly)

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 27

attr_reader :smtp

Instance Method Details

#base64_encode(str) ⇒ String

Parameters:

  • str (String)

Returns:

  • (String)

    Base64 encoded string

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 51

def base64_encode(str)
  # expects "str" may not become too long
  [str].pack('m0')
end

#continue(arg) ⇒ String

Parameters:

  • arg (String)

    message to server

Returns:

  • (String)

    message from server

Raises:

  • (res.exception_class)
[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 35

def continue(arg)
  res = smtp.get_response arg
  raise res.exception_class.new(res) unless res.continue?
  res.string.split[1]
end

#finish(arg) ⇒ Net::SMTP::Response

Parameters:

  • arg (String)

    message to server

Returns:

Raises:

[ GitHub ]

  
# File 'lib/net/smtp/authenticator.rb', line 43

def finish(arg)
  res = smtp.get_response arg
  raise SMTPAuthenticationError.new(res) unless res.success?
  res
end