class Ingenico::Direct::SDK::EndpointConfiguration

Base class for configuration classes in the SDK.

@attr [String] api_endpoint The base URL to the Ingenico ePayments platform. @attr [Integer] connect_timeout The number of seconds before a connection attempt with the Ingenico ePayments platform times out. @attr [Integer] socket_timeout The number of seconds before a timeout occurs when transmitting data to or from the Ingenico ePayments platform. @attr [Integer] max_connections The number of connections with the Ingenico ePayments platform that are kept alive in the connection pool.

These connections will be reused when possible.

@attr [Ingenico::Direct::SDK::ProxyConfiguration] proxy_configuration Proxy settings. @attr [String] integrator Name of the integrator @attr [Ingenico::Direct::SDK::Domain::ShoppingCartExtension] shopping_cart_extension Shopping cart-related metadata.

Constants

DEFAULT_CONNECT_TIMEOUT
DEFAULT_MAX_CONNECTIONS
DEFAULT_SOCKET_TIMEOUT

Attributes

api_endpoint[R]
connect_timeout[RW]
integrator[RW]
max_connections[RW]
proxy_configuration[RW]
shopping_cart_extension[RW]
socket_timeout[RW]

Public Class Methods

default_connect_timeout() click to toggle source

The default number of seconds before a connection attempt with the Ingenico ePayments platform times out. Used if connectTimeout is not present in the properties.

# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 22
def self.default_connect_timeout
  DEFAULT_CONNECT_TIMEOUT
end
default_max_connections() click to toggle source

The default number of connections that are kept alive in the connection pool. Used if maxConnections is not present in the properties.

# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 34
def self.default_max_connections
  DEFAULT_MAX_CONNECTIONS
end
default_socket_timeout() click to toggle source

The default number of seconds before a timeout occurs when transmitting data to or from the Ingenico ePayments platform. Used if socketTimeout is not present in the properties.

# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 28
def self.default_socket_timeout
  DEFAULT_SOCKET_TIMEOUT
end
new(properties = nil, prefix = nil) click to toggle source

Initializes a new EndpointConfiguration.

The given properties is searched for settings using properties[prefix + '.setting_name'] The following settings are searched:

endpoint

This property is searched for endpoint.host, endpoint.scheme and endpoint.port. The found host, scheme and port are used to construct the base URL to the Ingenico ePayments platform.

connectTimeout

The number of seconds before a connection attempt with the Ingenico ePayments platform times out.

socketTimeout

The number of seconds before a timeout occurs when transmitting data to or from the Ingenico ePayments platform.

maxConnections

The number of connections with the Ingenico ePayments platform that are kept alive in the connection pool. These connections will be reused when possible.

proxy

This property is searched for proxy.uri, proxy.username and proxy.password. The found URI, username and password are used for connecting to the Ingenico ePayments platform using a proxy.

integrator

Name of the integrator

shoppingCartExtension

Will be used to initialize a {Ingenico::Direct::SDK::Domain::ShoppingCartExtension}.

# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 54
def initialize(properties = nil, prefix = nil)
  return unless properties

  @api_endpoint = get_endpoint(properties, prefix)
  @connect_timeout = get_property(properties, "#{prefix}.connectTimeout", DEFAULT_CONNECT_TIMEOUT)
  @socket_timeout = get_property(properties, "#{prefix}.socketTimeout", DEFAULT_SOCKET_TIMEOUT)
  @max_connections = get_property(properties, "#{prefix}.maxConnections", DEFAULT_MAX_CONNECTIONS)

  proxy_uri = properties["#{prefix}.proxy.uri"]
  if proxy_uri
    proxy_user = properties["#{prefix}.proxy.username"]
    proxy_pass = properties["#{prefix}.proxy.password"]
    @proxy_configuration = ProxyConfiguration.new(address: URI(proxy_uri),
                                                  username: proxy_user,
                                                  password: proxy_pass)
  end
  @integrator = properties["#{prefix}.integrator"]
  @shopping_cart_extension = get_shopping_cart_extension(properties, prefix)
end

Protected Instance Methods

set_endpoint(endpoint) click to toggle source
# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 76
def set_endpoint(endpoint)
  if endpoint
    raise ArgumentError, 'endpoint should not contain a path' if endpoint.path
    if endpoint.userinfo || endpoint.query || endpoint.fragment
      raise ArgumentError('endpoint should not contain user info, query or fragment')
    end
  end
  @api_endpoint = endpoint
end

Private Instance Methods

create_uri(scheme, host, port) click to toggle source
# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 100
def create_uri(scheme, host, port)
  port == -1 ? "#{scheme}://#{host}" : "#{scheme}://#{host}:#{port}"
end
get_endpoint(properties, prefix) click to toggle source
# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 93
def get_endpoint(properties, prefix)
  host = properties["#{prefix}.endpoint.host"]
  scheme = properties["#{prefix}.endpoint.scheme"] || 'https'
  port = properties["#{prefix}.endpoint.port"] || -1
  create_uri(scheme, host, port)
end
get_property(properties, key, default_value) click to toggle source
# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 88
def get_property(properties, key, default_value)
  property_value = properties[key]
  property_value.nil? ? default_value : property_value
end
get_shopping_cart_extension(properties, prefix) click to toggle source
# File lib/ingenico/direct/sdk/endpoint_configuration.rb, line 104
def get_shopping_cart_extension(properties, prefix)
  creator = properties["#{prefix}.shoppingCartExtension.creator"]
  name = properties["#{prefix}.shoppingCartExtension.name"]
  version = properties["#{prefix}.shoppingCartExtension.version"]
  extension_id = properties["#{prefix}.shoppingCartExtension.extensionId"]
  (creator || name || version || extension_id) ?
      Domain::ShoppingCartExtension.new(creator, name, version, extension_id) :
      nil
end