class Ingenico::Direct::SDK::MetaDataProvider
Manages metadata about the server using the SDK
@attr_reader [Array<Ingenico::Direct::SDK::RequestHeader>] meta_data_headers
List of headers that should be used in all requests.
Constants
- CHARSET
- PROHIBITED_HEADERS
- SDK_VERSION
- SERVER_META_INFO_HEADER
Attributes
Public Class Methods
A list of header names that should not be used by any added headers. These headers are reserved for specific purposes.
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 144 def self.PROHIBITED_HEADERS PROHIBITED_HEADERS end
Version of this SDK
being used
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 133 def self.SDK_VERSION SDK_VERSION end
A {Ingenico::Direct::SDK::RequestHeader} that contains serialized and encoded {Ingenico::Direct::SDK::MetaDataProvider::ServerMetaInfo}.
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 138 def self.SERVER_META_INFO_HEADER SERVER_META_INFO_HEADER end
Create a new MetaDataProvider
instance that can be used to access platform-related information
@param integrator [String] Name of the integrator @param shopping_cart_extension [Ingenico::Direct::SDK::Domain::ShoppingCartExtension] shopping cart-related metadata. @param additional_request_headers [Array<Ingenico::Direct::SDK::RequestHeader>] list of additional headers to include in all requests made.
The following headers are not allowed due to conflicts with already added headers: 'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization' and 'X-GCS-ServerMetaInfo'
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 65 def initialize(integrator, shopping_cart_extension: nil, additional_request_headers: [].freeze) MetaDataProvider.validate_additional_request_headers(additional_request_headers) server_meta_info = ServerMetaInfo.new server_meta_info.platform_identifier = get_platform_identifier server_meta_info.sdk_identifier = get_sdk_identifier server_meta_info.sdk_creator = 'Ingenico' server_meta_info.integrator = integrator server_meta_info.shopping_cart_extension = shopping_cart_extension if shopping_cart_extension server_meta_info_string = DefaultImpl::DefaultMarshaller.INSTANCE.marshal(server_meta_info) server_meta_info_header = RequestHeader.new( SERVER_META_INFO_HEADER, Base64.strict_encode64(server_meta_info_string.force_encoding('iso-8859-1').encode(CHARSET))) if additional_request_headers.nil? || additional_request_headers.empty? @meta_data_headers = [server_meta_info_header].freeze else request_headers = [server_meta_info_header] request_headers += additional_request_headers @meta_data_headers = request_headers.freeze end end
Checks that the {Ingenico::Direct::SDK::RequestHeaders} _additional_request_header_ is equal to any of the forbidden headers. The forbidden headers are:
'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization' and 'X-GCS-ServerMetaInfo'
If the header is equal to one of the forbidden headers an ArgumentError is raised.
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 103 def self.validate_additional_request_header(additional_request_header) if MetaDataProvider.PROHIBITED_HEADERS.include? additional_request_header.name raise ArgumentError, "request header '#{additional_request_header.name}' not allowed" end end
Checks that none of the {Ingenico::Direct::SDK::RequestHeaders} in _additional_request_headers_ is equal to any of the forbidden headers. The forbidden headers are:
'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization' and 'X-GCS-ServerMetaInfo'
If a header is found that is equal to one of the forbidden headers an ArgumentError is raised.
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 91 def self.validate_additional_request_headers(additional_request_headers) if additional_request_headers additional_request_headers.each { |additional_request_header| validate_additional_request_header(additional_request_header) } end end
Protected Instance Methods
String containing information of the system using the SDK
. It contains data like Operating System version and Ruby version
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 113 def get_platform_identifier os_host = RbConfig::CONFIG['host_os'] if os_host.include? 'mingw' s = 'Windows' elsif os_host.include? 'linux' s = 'Linux' else s = 'Mac OS X' end "#{s}/#{RUBY_DESCRIPTION}" end
String describing the version of the SDK
being used
# File lib/ingenico/direct/sdk/meta_data_provider.rb, line 126 def get_sdk_identifier "RubyServerSDK/v#{SDK_VERSION}" end