Class: ApimaticCalculator::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic_calculator/client.rb

Overview

apimatic_calculator client class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: :net_http_persistent, timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, environment: Environment::PRODUCTION, access_token: '', config: nil) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/apimatic_calculator/client.rb', line 17

def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
               max_retries: 0, retry_interval: 1, backoff_factor: 2,
               retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
               retry_methods: %i[get put], http_callback: nil,
               environment: Environment::PRODUCTION, access_token: '',
               config: nil)
  @config = if config.nil?
              Configuration.new(connection: connection, adapter: adapter,
                                timeout: timeout, max_retries: max_retries,
                                retry_interval: retry_interval,
                                backoff_factor: backoff_factor,
                                retry_statuses: retry_statuses,
                                retry_methods: retry_methods,
                                http_callback: http_callback,
                                environment: environment,
                                access_token: access_token)
            else
              config
            end

  @global_configuration = GlobalConfiguration.new(client_configuration: @config)
                                             .base_uri_executor(@config.method(:get_base_uri))
                                             .global_errors(BaseController::GLOBAL_ERRORS)
                                             .user_agent(BaseController.user_agent)
                                             .sdk_module(ApimaticCalculator)

  initialize_auth_managers(@global_configuration)
  @global_configuration = @global_configuration.auth_managers(@auth_managers)
end

Instance Attribute Details

#auth_managersObject (readonly)

Returns the value of attribute auth_managers.



9
10
11
# File 'lib/apimatic_calculator/client.rb', line 9

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/apimatic_calculator/client.rb', line 9

def config
  @config
end

Instance Method Details

#initialize_auth_managers(global_config) ⇒ Object

Initializes the auth managers hash used for authenticating API calls.

Parameters:

  • global_config (GlobalConfiguration)

    The global configuration of the SDK)



49
50
51
52
53
54
# File 'lib/apimatic_calculator/client.rb', line 49

def initialize_auth_managers(global_config)
  @auth_managers = {}
  http_client_config = global_config.client_configuration
  ['global'].each { |auth| @auth_managers[auth] = nil }
  @auth_managers['global'] = OAuth2.new(http_client_config.access_token)
end

#simple_calculatorSimpleCalculatorController

Access to simple_calculator controller.

Returns:



13
14
15
# File 'lib/apimatic_calculator/client.rb', line 13

def simple_calculator
  @simple_calculator ||= SimpleCalculatorController.new @global_configuration
end