Class: Worldline::Connect::SDK::Factory

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

Overview

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

Class Method Summary collapse

Class Method Details

.create_client_from_communicator(communicator) ⇒ Worldline::Connect::SDK::Client

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

Examples:

Providing a code block

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

Parameters:

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/worldline/connect/sdk/factory.rb', line 124

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, metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil) ⇒ Worldline::Connect::SDK::Client

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

Examples:

Providing a code block

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

Parameters:

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/worldline/connect/sdk/factory.rb', line 98

def self.create_client_from_configuration(configuration, metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil)
  communicator = create_communicator_from_configuration(configuration, metadata_provider: , connection: connection,
                                                        authenticator: authenticator, marshaller: marshaller)
  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, authorization_id, authorization_secret, metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil) ⇒ Worldline::Connect::SDK::Client

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

Examples:

Providing a code block

Factory.create_client_from_file(configuration_file_name, authorization_id, authorization_secret) do |client|
  client.v1.merchant(merchant_id).services.testconnection
end
# client is closed here

Parameters:

  • configuration_file_name (String)

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

  • authorization_id (String)

    Authorization id, e.g. the key id for the Worldline Global Collect platform.

  • authorization_secret (String)

    Authorization secret, e.g. the secret key used for authentication to the Worldline Global Collect platform.

  • metadata_provider (Worldline::Connect::SDK::Communication::MetadataProvider) (defaults to: nil)

    stores the metadata for the communicating client.

  • connection (Worldline::Connect::SDK::Communication::Connection) (defaults to: nil)

    connection that can be used to communicate with the Worldline Global Collect platform.

  • authenticator (Worldline::Connect::SDK::Authentication::Authenticator) (defaults to: nil)

    authenticator that can authenticate messages sent to the Worldline Global Collect platform.

  • marshaller (Worldline::Connect::SDK::JSON::Marshaller) (defaults to: nil)

    marshaller that can marshal and unmarshal objects to and from JSON.

Returns:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/worldline/connect/sdk/factory.rb', line 154

def self.create_client_from_file(configuration_file_name, authorization_id, authorization_secret,
                                 metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil)
  communicator = create_communicator_from_file(configuration_file_name, authorization_id, authorization_secret,
                                               metadata_provider: , connection: connection,
                                               authenticator: authenticator, marshaller: marshaller)
  client = Client.new(communicator)
  if block_given?
    begin
      yield client
    ensure
      client.close
    end
  else
    return client
  end
end

.create_communicator_from_configuration(configuration, metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil) ⇒ Worldline::Connect::SDK::Communicator

Parameters:

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/worldline/connect/sdk/factory.rb', line 43

def self.create_communicator_from_configuration(configuration, metadata_provider: nil,
                                                connection: nil, authenticator: nil, marshaller: nil)
  unless 
     = MetadataProvider.new(configuration.integrator,
                                              shopping_cart_extension: configuration.shopping_cart_extension)
  end
  unless connection
    connection = Communication::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 = get_authenticator(configuration)
  end
  unless marshaller
    marshaller = DefaultMarshaller.instance
  end
  Communicator.new(configuration.api_endpoint, connection, authenticator, , marshaller)
end

.create_communicator_from_file(configuration_file_name, authorization_id, authorization_secret, metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil) ⇒ Worldline::Connect::SDK::Communicator

Creates and returns a Communicator from a file containing the communicator configuration, authorization_id, authorization_secret, a Communication::MetadataProvider, a Communication::Connection. an Authentication::Authenticator and a JSON::Marshaller.

Parameters:

  • configuration_file_name (String)

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

  • authorization_id (String)

    Authorization id, e.g. the key id for the Worldline Global Collect platform.

  • authorization_secret (String)

    Authorization secret, e.g. the secret key used for authentication to the Worldline Global Collect platform.

  • metadata_provider (Worldline::Connect::SDK::Communication::MetadataProvider) (defaults to: nil)

    stores the metadata for the communicating client.

  • connection (Worldline::Connect::SDK::Communication::Connection) (defaults to: nil)

    connection that can be used to communicate with the Worldline Global Collect platform.

  • authenticator (Worldline::Connect::SDK::Authentication::Authenticator) (defaults to: nil)

    authenticator that can authenticate messages sent to the Worldline Global Collect platform.

  • marshaller (Worldline::Connect::SDK::JSON::Marshaller) (defaults to: nil)

    marshaller that can marshal and unmarshal objects to and from JSON.

Returns:



76
77
78
79
80
81
# File 'lib/worldline/connect/sdk/factory.rb', line 76

def self.create_communicator_from_file(configuration_file_name, authorization_id, authorization_secret,
                                       metadata_provider: nil, connection: nil, authenticator: nil, marshaller: nil)
  configuration = create_configuration(configuration_file_name, authorization_id, authorization_secret)
  create_communicator_from_configuration(configuration, metadata_provider: , connection: connection,
                                         authenticator: authenticator, marshaller: marshaller)
end

.create_configuration(configuration_file_name, authorization_id, authorization_secret) ⇒ Worldline::Connect::SDK::CommunicatorConfiguration

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

Parameters:

  • configuration_file_name (String)

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

  • authorization_id (String)

    Authorization id, e.g. the key id for the Worldline Global Collect platform.

  • authorization_secret (String)

    Authorization secret, e.g. the secret key used for authentication to the Worldline Global Collect platform.

Returns:



26
27
28
29
30
31
# File 'lib/worldline/connect/sdk/factory.rb', line 26

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