Class: OnlinePayments::SDK::MetaDataProvider
- Inherits:
-
Object
- Object
- OnlinePayments::SDK::MetaDataProvider
- Defined in:
- lib/onlinepayments/sdk/meta_data_provider.rb
Overview
Manages metadata about the server using the SDK
Defined Under Namespace
Classes: ServerMetaInfo
Constant Summary collapse
- SDK_VERSION =
'0.0.1'.freeze
- SERVER_META_INFO_HEADER =
'X-GCS-ServerMetaInfo'.freeze
- PROHIBITED_HEADERS =
[SERVER_META_INFO_HEADER, 'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization'].sort!.freeze
- CHARSET =
'utf-8'.freeze
Instance Attribute Summary collapse
-
#meta_data_headers ⇒ Array<OnlinePayments::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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/onlinepayments/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) = ServerMetaInfo.new .platform_identifier = get_platform_identifier .sdk_identifier = get_sdk_identifier .sdk_creator = 'OnlinePayments' .integrator = integrator .shopping_cart_extension = shopping_cart_extension if shopping_cart_extension = 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? @meta_data_headers = [].freeze else request_headers = [] request_headers += additional_request_headers @meta_data_headers = request_headers.freeze end end |
Instance Attribute Details
#meta_data_headers ⇒ Array<OnlinePayments::SDK::RequestHeader> (readonly)
List of headers that should be used in all requests.
9 10 11 |
# File 'lib/onlinepayments/sdk/meta_data_provider.rb', line 9 def @meta_data_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.
144 145 146 |
# File 'lib/onlinepayments/sdk/meta_data_provider.rb', line 144 def self.PROHIBITED_HEADERS PROHIBITED_HEADERS end |
.SDK_VERSION ⇒ Object
Version of this SDK being used
133 134 135 |
# File 'lib/onlinepayments/sdk/meta_data_provider.rb', line 133 def self.SDK_VERSION SDK_VERSION end |
.SERVER_META_INFO_HEADER ⇒ Object
A RequestHeader that contains serialized and encoded ServerMetaInfo.
138 139 140 |
# File 'lib/onlinepayments/sdk/meta_data_provider.rb', line 138 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.
103 104 105 106 107 |
# File 'lib/onlinepayments/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 |
.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.
91 92 93 94 95 96 97 |
# File 'lib/onlinepayments/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 |