Class: Ingenico::Connect::SDK::MetaDataProvider
- Inherits:
-
Object
- Object
- Ingenico::Connect::SDK::MetaDataProvider
- Defined in:
- lib/ingenico/connect/sdk/meta_data_provider.rb
Overview
Manages metadata about the server using the SDK
Defined Under Namespace
Classes: ServerMetaInfo
Constant Summary collapse
- @@SDK_VERSION =
'2.47.1'- @@SERVER_META_INFO_HEADER =
'X-GCS-ServerMetaInfo'- @@PROHIBITED_HEADERS =
[@@SERVER_META_INFO_HEADER, 'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization'].sort!.freeze
- @@CHARSET =
'utf-8'
Instance Attribute Summary collapse
-
#meta_data_headers ⇒ Array<Ingenico::Connect::SDK::RequestHeader>
readonly
List of headers that should be used in all requests.
Class Method Summary collapse
-
.PROHIBITED_HEADERS ⇒ Object
A list of header names that should not be used by any added headers.
-
.SDK_VERSION ⇒ Object
Version of this SDK being used.
-
.SERVER_META_INFO_HEADER ⇒ Object
A RequestHeader that contains serialized and encoded ServerMetaInfo.
-
.validate_additional_request_header(additional_request_header) ⇒ Object
Checks that the RequestHeaders additional_request_header is equal to any of the forbidden headers.
-
.validate_additional_request_headers(additional_request_headers) ⇒ Object
Checks that none of the RequestHeaders in additional_request_headers is equal to any of the forbidden headers.
Instance Method Summary collapse
-
#initialize(integrator, shopping_cart_extension: nil, additional_request_headers: [].freeze) ⇒ MetaDataProvider
constructor
Create a new MetaDataProvider instance that can be used to access platform-related information.
Constructor Details
#initialize(integrator, shopping_cart_extension: nil, additional_request_headers: [].freeze) ⇒ MetaDataProvider
Create a new MetaDataProvider instance that can be used to access platform-related information
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 69 def initialize(integrator, shopping_cart_extension: nil, additional_request_headers: [].freeze) MetaDataProvider.validate_additional_request_headers(additional_request_headers) = ServerMetaInfo.new .platform_identifier = get_platform_identifier .sdk_identifier = get_sdk_identifier .sdk_creator = 'Ingenico' .integrator = integrator .shopping_cart_extension = shopping_cart_extension unless shopping_cart_extension.nil? = DefaultImpl::DefaultMarshaller.INSTANCE.marshal() = RequestHeader.new( @@SERVER_META_INFO_HEADER, Base64.strict_encode64( .force_encoding('iso-8859-1').encode(@@CHARSET))) if additional_request_headers.nil? || additional_request_headers.empty? = [].freeze else request_headers = [] request_headers += additional_request_headers = request_headers.freeze end end |
Instance Attribute Details
#meta_data_headers ⇒ Array<Ingenico::Connect::SDK::RequestHeader> (readonly)
List of headers that should be used in all requests.
13 14 15 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 13 def end |
Class Method Details
.PROHIBITED_HEADERS ⇒ Object
A list of header names that should not be used by any added headers. These headers are reserved for specific purposes.
148 149 150 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 148 def self.PROHIBITED_HEADERS @@PROHIBITED_HEADERS end |
.SDK_VERSION ⇒ Object
Version of this SDK being used
137 138 139 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 137 def self.SDK_VERSION @@SDK_VERSION end |
.SERVER_META_INFO_HEADER ⇒ Object
A RequestHeader that contains serialized and encoded ServerMetaInfo.
142 143 144 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 142 def self.SERVER_META_INFO_HEADER @@SERVER_META_INFO_HEADER end |
.validate_additional_request_header(additional_request_header) ⇒ Object
Checks that the 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.
107 108 109 110 111 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 107 def self.validate_additional_request_header(additional_request_header) if MetaDataProvider.PROHIBITED_HEADERS.include? additional_request_header.name raise ArgumentError.new('request header not allowed' + additional_request_header.name) end end |
.validate_additional_request_headers(additional_request_headers) ⇒ Object
Checks that none of the 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.
95 96 97 98 99 100 101 |
# File 'lib/ingenico/connect/sdk/meta_data_provider.rb', line 95 def self.validate_additional_request_headers(additional_request_headers) unless additional_request_headers.nil? additional_request_headers.each { |additional_request_header| validate_additional_request_header(additional_request_header) } end end |