class Ingenico::Direct::SDK::ProxyConfiguration

Contains the URL, username and password of a proxy.

@attr [String] scheme Proxy scheme (http or https) @attr [String] host Proxy hostname @attr [Integer] port Proxy port @attr [String] username Proxy authentication username @attr [String] password Proxy authentication password

Attributes

host[RW]
password[RW]
port[RW]
scheme[RW]
username[RW]

Public Class Methods

new(args) click to toggle source

Initialize a new ProxyConfiguration from the parameter hash. In order to be complete either host, port and scheme, or an address is required.

@param args [Hash] the parameters to initialize the proxy configuration with @option args [String] :host host part of the URL to the proxy. @option args [Integer] :port port the proxy will be accessed through. @option args [String] :scheme HTTP scheme used to communicate with the proxy (http or https). @option args [String] :address full URI to the proxy excluding username and password.

If given this uri takes precedence over individual host, port and scheme.

@option args [String] :username username used in authentication to the proxy. @option args [String] :password password used to authenticate to the proxy.

# File lib/ingenico/direct/sdk/proxy_configuration.rb, line 23
def initialize(args)

  host = args[:host]
  port = args[:port]
  username = args[:username]
  password = args[:password]
  scheme = args[:scheme] || 'http'

  # Don't switch the order, a given address overrides host, port and username
  address = args[:address]
  host = address.host if address
  port = address.port if address
  scheme = address.scheme if address

  raise ArgumentError, 'scheme is required' unless scheme && !scheme.strip.empty?
  raise ArgumentError, 'host is required' unless host && !host.strip.empty?
  raise ArgumentError, 'port is required' unless port&.positive? && port <= 65535

  @host = host
  @port = port
  @username = username
  @password = password
  @scheme = scheme
end

Private Class Methods

get_port(address) click to toggle source
# File lib/ingenico/direct/sdk/proxy_configuration.rb, line 66
def self.get_port(address)
  port = address.port
  return port if port != -1
  return 80 if address.scheme.casecmp('http') == 0
  return 443 if address.scheme.casecmp('https') == 0
  raise ArgumentError, "unsupported scheme: #{address.scheme}"
end

Public Instance Methods

proxy_uri() click to toggle source

@return [String] a URL string representation of the proxy, excluding authentication.

# File lib/ingenico/direct/sdk/proxy_configuration.rb, line 56
def proxy_uri
   "#{scheme}://#{host}:#{port}"
end
to_s() click to toggle source
# File lib/ingenico/direct/sdk/proxy_configuration.rb, line 60
def to_s
  proxy_uri
end