Class: Ingenico::Connect::SDK::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/ingenico/connect/sdk/factory.rb

Overview

Convenience class that constructs instances of several other classes in the SDK. Provides methods to construct CommunicatorConfiguration, Session, Communicator and Client instances.

Class Method Summary collapse

Class Method Details

.create_client_from_communicator(communicator) ⇒ Object

Creates and returns an Client that provides the a high-level interface with the GlobalCollect service. If a code block is given, the created client is returned to the code block and closed afterwards.

communicator

Communicator that provides network communication service for the Client

Examples:

Providing a code block

Factory.create_client_from_communicator(communicator) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here


136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/ingenico/connect/sdk/factory.rb', line 136

def self.create_client_from_communicator(communicator)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_client_from_configuration(configuration) ⇒ Object

Creates and returns an Client that provides the a high-level interface with the GlobalCollect service. If a code block is given, the created client is returned to the code block and closed afterwards.

configuration

CommunicatorConfiguration that contains configuration settings to be used by the client.

Examples:

Providing a code block

Factory.create_client_from_configuration(configuration) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here


112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ingenico/connect/sdk/factory.rb', line 112

def self.create_client_from_configuration(configuration)
  communicator = create_communicator_from_configuration(configuration)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_client_from_file(configuration_file_name, api_key_id, secret_api_key) ⇒ Object

Creates and returns an Client that provides the a high-level interface with the GlobalCollect service. If a code block is given, the created client is returned to the code block and closed afterwards.

configuration_file_name

Path to the configuration file to use for configuring the Client, should be in YAML format.

api_key_id

Key id for the GlobalCollect service.

secret_api_key

Secret key used for authentication to the GlobalCollect service.

Examples:

Providing a code block

Factory.create_client_from_file(configuration_file_name, api_key_id, secret_api_key) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here


186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/ingenico/connect/sdk/factory.rb', line 186

def self.create_client_from_file(configuration_file_name, api_key_id, secret_api_key)
  communicator = create_communicator_from_file(configuration_file_name, api_key_id, secret_api_key)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_client_from_session(session) ⇒ Object

Creates and returns an Client that provides the a high-level interface with the GlobalCollect service. If a code block is given, the created client is returned to the code block and closed afterwards.

session

Session that the Client will utilize for communication.

Examples:

Providing a code block

Factory.create_client_from_session(session) do |client|
  client.merchant(merchant_id).services.testconnection
end
# client is closed here


159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ingenico/connect/sdk/factory.rb', line 159

def self.create_client_from_session(session)
  communicator = create_communicator_from_session(session)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_communicator_from_configuration(configuration) ⇒ Object

Creates and returns an Communicator that can be used for communication with the GlobalCollect service.

configuration

CommunicatorConfiguration that contains configuration settings to be used by the client.



85
86
87
88
# File 'lib/ingenico/connect/sdk/factory.rb', line 85

def self.create_communicator_from_configuration(configuration)
  session = create_session_from_configuration(configuration)
  Communicator.new(session, DefaultImpl::DefaultMarshaller.INSTANCE)
end

.create_communicator_from_file(configuration_file_name, api_key_id, secret_api_key) ⇒ Object

Creates and returns an Communicator that is used for communication with the GlobalCollect service.

configuration_file_name

Path to the configuration file to use, should be in YAML format.

api_key_id

Key id for the GlobalCollect service.

secret_api_key

Secret key used for authentication to the GlobalCollect service.



95
96
97
98
99
# File 'lib/ingenico/connect/sdk/factory.rb', line 95

def self.create_communicator_from_file(configuration_file_name, api_key_id, secret_api_key)
  configuration = create_configuration(configuration_file_name, api_key_id, secret_api_key)
  session = create_session_from_configuration(configuration)
  Communicator.new(session, DefaultImpl::DefaultMarshaller.INSTANCE)
end

.create_communicator_from_session(session) ⇒ Object

Creates and returns an Communicator that is used for communication with the GlobalCollect service.

session

Session that the communicator will utilize for communication.



77
78
79
# File 'lib/ingenico/connect/sdk/factory.rb', line 77

def self.create_communicator_from_session(session)
  Communicator.new(session, DefaultImpl::DefaultMarshaller.INSTANCE)
end

.create_configuration(configuration_file_name, api_key_id, secret_api_key) ⇒ Object

Creates and returns a CommunicatorConfiguration based on the configuration in the file located at configuration_file_name.

configuration_file_name

Path to the configuration file to use, should be in YAML format.

api_key_id

Key id for the GlobalCollect service.

secret_api_key

Secret key used for authentication to the GlobalCollect service.



16
17
18
19
20
21
# File 'lib/ingenico/connect/sdk/factory.rb', line 16

def self.create_configuration(configuration_file_name, api_key_id, secret_api_key)
    properties = YAML::load_file(configuration_file_name)
    CommunicatorConfiguration.new(properties: properties,
                                         api_key_id: api_key_id,
                                         secret_api_key: secret_api_key)
end

.create_session_from_configuration(configuration, meta_data_provider: nil, connection: nil, authenticator: nil) ⇒ Object

Creates and returns a Session from an CommunicatorConfiguration, an MetaDataProvider, an Connection and an Authenticator. If an authenticator is not given, a DefaultImpl::DefaultAuthenticator is created using the api_key_id and secret_api_key in the CommunicatorConfiguration.

configuration

CommunicatorConfiguration that contains configuration settings to be used by the client.

meta_data_provider

MetaDataProvider that stores the metadata for the communicating client.

connection

Implementation of Connection that can be used to communicate with the Ingenico ePayments platform.

authenticator

Implementation of Authenticator that can authenticate messages sent to the Ingenico ePayments platform.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ingenico/connect/sdk/factory.rb', line 35

def self.create_session_from_configuration(configuration, meta_data_provider: nil,
                                           connection: nil, authenticator: nil)
  unless 
     = MetaDataProvider.new(configuration.integrator,
                                              shopping_cart_extension: configuration.shopping_cart_extension)
  end
  unless connection
    connection = DefaultImpl::DefaultConnection.new({connect_timeout: configuration.connect_timeout,
                                                    socket_timeout: configuration.socket_timeout,
                                                    max_connections: configuration.max_connections,
                                                    proxy_configuration: configuration.proxy_configuration})
  end
  unless authenticator
    authenticator = DefaultImpl::DefaultAuthenticator.new(configuration.authorization_type,
                                             configuration.api_key_id, configuration.secret_api_key)
  end
  Session.new(configuration.api_endpoint, connection, authenticator, )
end

.create_session_from_file(configuration_file_name, api_key_id, secret_api_key, meta_data_provider: nil, connection: nil, authenticator: nil) ⇒ Object

Creates and returns a Session from a file containing the communicator configuration, api_key_id, secret_api_key, an MetaDataProvider, an Connection and an Authenticator. If an authenticator is not given, a DefaultImpl::DefaultAuthenticator is created using the api_key_id and secret_api_key in the CommunicatorConfiguration.

configuration_file_name

Path to the configuration file to use, should be in YAML format.

api_key_id

Key id for the GlobalCollect service.

secret_api_key

Secret key used for authentication to the GlobalCollect service.

meta_data_provider

MetaDataProvider that stores the metadata for the communicating client.

connection

Implementation of Connection that can be used to communicate with the Ingenico ePayments platform.

authenticator

Implementation of Authenticator that can authenticate messages sent to the Ingenico ePayments platform.



67
68
69
70
71
72
# File 'lib/ingenico/connect/sdk/factory.rb', line 67

def self.create_session_from_file(configuration_file_name, api_key_id, secret_api_key,
                                  meta_data_provider: nil, connection: nil, authenticator: nil)
  configuration = create_configuration(configuration_file_name, api_key_id, secret_api_key)
  create_session_from_configuration(configuration, meta_data_provider: , connection: connection,
                                    authenticator: authenticator)
end