Class: OnlinePayments::SDK::ProxyConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/onlinepayments/sdk/proxy_configuration.rb

Overview

Contains the URL, username and password of a proxy.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ ProxyConfiguration

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

Parameters:

  • args (Hash)

    the parameters to initialize the proxy configuration with

Options Hash (args):

  • :host (String)

    host part of the URL to the proxy.

  • :port (Integer)

    port the proxy will be accessed through.

  • :scheme (String)

    HTTP scheme used to communicate with the proxy (http or https).

  • :address (String)

    full URI to the proxy excluding username and password. If given this uri takes precedence over individual host, port and scheme.

  • :username (String)

    username used in authentication to the proxy.

  • :password (String)

    password used to authenticate to the proxy.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/onlinepayments/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

Instance Attribute Details

#hostString

Proxy hostname

Returns:

  • (String)

    the current value of host



10
11
12
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 10

def host
  @host
end

#passwordString

Proxy authentication password

Returns:

  • (String)

    the current value of password



10
11
12
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 10

def password
  @password
end

#portInteger

Proxy port

Returns:

  • (Integer)

    the current value of port



10
11
12
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 10

def port
  @port
end

#schemeString

Proxy scheme (http or https)

Returns:

  • (String)

    the current value of scheme



10
11
12
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 10

def scheme
  @scheme
end

#usernameString

Proxy authentication username

Returns:

  • (String)

    the current value of username



10
11
12
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 10

def username
  @username
end

Instance Method Details

#proxy_uriString

Returns a URL string representation of the proxy, excluding authentication.

Returns:

  • (String)

    a URL string representation of the proxy, excluding authentication.



56
57
58
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 56

def proxy_uri
  "#{scheme}://#{host}:#{port}"
end

#to_sObject



60
61
62
# File 'lib/onlinepayments/sdk/proxy_configuration.rb', line 60

def to_s
  proxy_uri
end