Class: Worldline::Acquiring::SDK::Communication::MetadataProvider
- Inherits:
-
Object
- Object
- Worldline::Acquiring::SDK::Communication::MetadataProvider
- Defined in:
- lib/worldline/acquiring/sdk/communication/metadata_provider.rb
Overview
Manages metadata about the server using the SDK
Defined Under Namespace
Classes: ServerMetaInfo
Instance Attribute Summary collapse
-
#metadata_headers ⇒ Array<Worldline::Acquiring::SDK::Communication::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
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 73 def initialize(integrator, shopping_cart_extension: nil, additional_request_headers: [].freeze) raise ArgumentError.new('integrator is required') if integrator.nil? or integrator.strip.empty? MetadataProvider.validate_additional_request_headers(additional_request_headers) = ServerMetaInfo.new .platform_identifier = get_platform_identifier .sdk_identifier = get_sdk_identifier .sdk_creator = 'Worldline' .integrator = integrator .shopping_cart_extension = shopping_cart_extension unless shopping_cart_extension.nil? = Worldline::Acquiring::SDK::JSON::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? @metadata_headers = [].freeze else request_headers = [] request_headers += additional_request_headers @metadata_headers = request_headers.freeze end end |
Instance Attribute Details
#metadata_headers ⇒ Array<Worldline::Acquiring::SDK::Communication::RequestHeader> (readonly)
List of headers that should be used in all requests.
14 15 16 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 14 def @metadata_headers 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.
153 154 155 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 153 def self.prohibited_headers PROHIBITED_HEADERS end |
.sdk_version ⇒ Object
Version of this SDK being used
141 142 143 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 141 def self.sdk_version SDK_VERSION end |
.server_meta_info_header ⇒ Object
A RequestHeader that contains serialized and encoded ServerMetaInfo.
147 148 149 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 147 def self. 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: ‘Date’, ‘Content-Type’, ‘Authorization’ and ‘X-WL-ServerMetaInfo’ If the header is equal to one of the forbidden headers an ArgumentError is raised.
111 112 113 114 115 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 111 def self.validate_additional_request_header(additional_request_header) if 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: ‘Date’, ‘Content-Type’, ‘Authorization’ and ‘X-WL-ServerMetaInfo’ If a header is found that is equal to one of the forbidden headers an ArgumentError is raised.
99 100 101 102 103 104 105 |
# File 'lib/worldline/acquiring/sdk/communication/metadata_provider.rb', line 99 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 |