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.
48 49 50 51 52 53 54 55 56 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 48 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.
28 29 30 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 28 def api_config @api_config end |
#api_tracker ⇒ Hash
Defines the api_tracker to be added in request header having parameters.
38 39 40 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 38 def api_tracker @api_tracker end |
#config ⇒ Object
The Configuration object holding settings to be used in the API client.
25 26 27 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 25 def config @config end |
#default_headers ⇒ Hash
Defines the headers to be used in HTTP requests of all API calls by default.
33 34 35 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 33 def default_headers @default_headers end |
#error_handler ⇒ Object
Defines the object that would handle error for all the requests.
41 42 43 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 41 def error_handler @error_handler end |
#mastercard_authenticator ⇒ Object
Adds the authorization header, tracking headers and also logs the request/response.
44 45 46 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 44 def mastercard_authenticator @mastercard_authenticator end |
Class Method Details
Instance Method Details
#call(path, service_request, http_method, return_type) ⇒ String
Execute Typhoeus request.
68 69 70 71 72 73 74 |
# File 'lib/mastercard_core_sdk/client/api_client.rb', line 68 def call(path, service_request, http_method, return_type) request = build_request(http_method, path, service_request, @api_config) Jose.api_config = @api_config response_body, response_code, response_headers = call_api(request, return_type) return response_body end |