Class: Worldline::Connect::SDK::ProxyConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/worldline/connect/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)


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/worldline/connect/sdk/proxy_configuration.rb', line 24

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.new('scheme is required') unless scheme and not scheme.strip.empty?
  raise ArgumentError.new('host is required') unless host and not host.strip.empty?
  raise ArgumentError.new('port is required') unless port and port > 0 and 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



11
12
13
# File 'lib/worldline/connect/sdk/proxy_configuration.rb', line 11

def host
  @host
end

#passwordString

Proxy authentication password

Returns:

  • (String)

    the current value of password



11
12
13
# File 'lib/worldline/connect/sdk/proxy_configuration.rb', line 11

def password
  @password
end

#portInteger

Proxy port

Returns:

  • (Integer)

    the current value of port



11
12
13
# File 'lib/worldline/connect/sdk/proxy_configuration.rb', line 11

def port
  @port
end

#schemeString

Proxy scheme (http or https)

Returns:

  • (String)

    the current value of scheme



11
12
13
# File 'lib/worldline/connect/sdk/proxy_configuration.rb', line 11

def scheme
  @scheme
end

#usernameString

Proxy authentication username

Returns:

  • (String)

    the current value of username



11
12
13
# File 'lib/worldline/connect/sdk/proxy_configuration.rb', line 11

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/worldline/connect/sdk/proxy_configuration.rb', line 56

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

#to_sObject



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

def to_s
  proxy_uri
end