Class: MastercardCoreSdk::Client::ApiClient
- Inherits:
-
Object
- Object
- MastercardCoreSdk::Client::ApiClient
- Defined in:
- lib/mastercard_core_sdk/client/api_client.rb
Overview
ApiClient is the base class to invoke the API. It is responsible for to convert all request and response according to the content type.
Constant Summary collapse
- @@logger =
Logging.logger[self]
Instance Attribute Summary collapse
-
#api_config ⇒ Object
The ApiConfig object holding environment configurations.
-
#api_tracker ⇒ Hash
Defines the api_tracker to be added in request header having parameters.
-
#config ⇒ Object
The Configuration object holding settings to be used in the API client.
-
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
-
#error_handler ⇒ Object
Defines the object that would handle error for all the requests.
-
#mastercard_authenticator ⇒ Object
Adds the authorization header, tracking headers and also logs the request/response.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(path, service_request, http_method, return_type) ⇒ String
Execute Typhoeus request.
-
#initialize(api_config = nil) ⇒ ApiClient
constructor
Initializing Api Client with user-agent, configuration and default headers.
Constructor Details
#initialize(api_config = nil) ⇒ ApiClient
Initializing Api Client with user-agent, configuration and default headers. Validating MasterCardApiConfiguration and calling interceptor for Authorization signature and logger.
47 48 49 50 51 52 53 54 55 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 47 def initialize(api_config = nil) @config = Configuration.default @user_agent = @config.user_agent @default_headers = @config.default_headers @mastercard_authenticator = MastercardAuthenticator.new @api_config = api_config || MasterCardApiConfiguration.api_config MasterCardApiConfiguration.validate_config(@api_config) end |
Instance Attribute Details
#api_config ⇒ Object
The ApiConfig object holding environment configurations.
27 28 29 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 27 def api_config @api_config end |
#api_tracker ⇒ Hash
Defines the api_tracker to be added in request header having parameters.
37 38 39 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 37 def api_tracker @api_tracker end |
#config ⇒ Object
The Configuration object holding settings to be used in the API client.
24 25 26 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 24 def config @config end |
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
32 33 34 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 32 def default_headers @default_headers end |
#error_handler ⇒ Object
Defines the object that would handle error for all the requests.
40 41 42 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 40 def error_handler @error_handler end |
#mastercard_authenticator ⇒ Object
Adds the authorization header, tracking headers and also logs the request/response.
43 44 45 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 43 def mastercard_authenticator @mastercard_authenticator end |
Class Method Details
.default ⇒ Object
57 58 59 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 57 def self.default @@default ||= ApiClient.new end |
Instance Method Details
#call(path, service_request, http_method, return_type) ⇒ String
Execute Typhoeus request.
67 68 69 70 71 72 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 67 def call(path, service_request, http_method, return_type) request = build_request(http_method, path, service_request, @api_config) response_body, response_code, response_headers = call_api(request, return_type) return response_body end |