Class: OnlinePayments::SDK::Communication::MetadataProvider
- Inherits:
-
Object
- Object
- OnlinePayments::SDK::Communication::MetadataProvider
- Defined in:
- lib/onlinepayments/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<OnlinePayments::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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 72 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 = 'OnlinePayments' .integrator = integrator .shopping_cart_extension = shopping_cart_extension unless shopping_cart_extension.nil? = OnlinePayments::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<OnlinePayments::SDK::Communication::RequestHeader> (readonly)
List of headers that should be used in all requests.
13 14 15 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 13 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.
152 153 154 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 152 def self.prohibited_headers PROHIBITED_HEADERS end |
.sdk_version ⇒ Object
Version of this SDK being used
140 141 142 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 140 def self.sdk_version SDK_VERSION end |
.server_meta_info_header ⇒ Object
A RequestHeader that contains serialized and encoded ServerMetaInfo.
146 147 148 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 146 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: ‘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.
110 111 112 113 114 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 110 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: ‘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.
98 99 100 101 102 103 104 |
# File 'lib/onlinepayments/sdk/communication/metadata_provider.rb', line 98 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 |