Class: MultiAuthSample::Client

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

Overview

multi_auth_sample 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::TESTING, port: '80', suites: SuiteCodeEnum::HEARTS, basic_auth_credentials: nil, api_key_credentials: nil, api_header_credentials: nil, o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil, o_auth_ropcg_credentials: nil, o_auth_bearer_token_credentials: nil, custom_auth_credentials: nil, access_token: '', config: nil) ⇒ Client

Returns a new instance of Client.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/multi_auth_sample/client.rb', line 38

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::TESTING, port: '80',
  suites: SuiteCodeEnum::HEARTS, basic_auth_credentials: nil,
  api_key_credentials: nil, api_header_credentials: nil,
  o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil,
  o_auth_ropcg_credentials: nil, o_auth_bearer_token_credentials: nil,
  custom_auth_credentials: nil, 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, port: port, suites: suites,
                basic_auth_credentials: basic_auth_credentials,
                api_key_credentials: api_key_credentials,
                api_header_credentials: api_header_credentials,
                o_auth_ccg_credentials: o_auth_ccg_credentials,
                o_auth_acg_credentials: o_auth_acg_credentials,
                o_auth_ropcg_credentials: o_auth_ropcg_credentials,
                o_auth_bearer_token_credentials: o_auth_bearer_token_credentials,
                custom_auth_credentials: custom_auth_credentials,
                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)
                                             .global_header('accessToken', @config.access_token)

  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/multi_auth_sample/client.rb', line 9

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#authenticationAuthenticationController

Access to authentication controller.

Returns:



28
29
30
# File 'lib/multi_auth_sample/client.rb', line 28

def authentication
  @authentication ||= AuthenticationController.new @global_configuration
end

#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)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/multi_auth_sample/client.rb', line 84

def initialize_auth_managers(global_config)
  @auth_managers = {}
  http_client_config = global_config.client_configuration
  %w[basicAuth apiKey apiHeader OAuthCCG OAuthACG OAuthROPCG OAuthBearerToken CustomAuth].each do |auth|
    @auth_managers[auth] = nil
  end
  @auth_managers['basicAuth'] = BasicAuth.new(http_client_config.basic_auth_credentials)
  @auth_managers['apiKey'] = ApiKey.new(http_client_config.api_key_credentials)
  @auth_managers['apiHeader'] = ApiHeader.new(http_client_config.api_header_credentials)
  @auth_managers['OAuthCCG'] = OAuthCCG.new(http_client_config.o_auth_ccg_credentials,
                                            global_config)
  @auth_managers['OAuthACG'] = OAuthACG.new(http_client_config.o_auth_acg_credentials,
                                            global_config)
  @auth_managers['OAuthROPCG'] = OAuthROPCG.new(http_client_config.o_auth_ropcg_credentials,
                                                global_config)
  @auth_managers['OAuthBearerToken'] = OAuthBearerToken.new(
    http_client_config.o_auth_bearer_token_credentials
  )
  @auth_managers['CustomAuth'] = CustomAuth.new(http_client_config)
end

#o_auth_acgObject

Returns the configured authentication OAuthACG instance.



17
18
19
# File 'lib/multi_auth_sample/client.rb', line 17

def o_auth_acg
  @auth_managers['OAuthACG']
end

#o_auth_authorizationOAuthAuthorizationController

Access to o_auth_authorization controller.

Returns:



34
35
36
# File 'lib/multi_auth_sample/client.rb', line 34

def o_auth_authorization
  @o_auth_authorization ||= OAuthAuthorizationController.new @global_configuration
end

#o_auth_ccgObject

Returns the configured authentication OAuthCCG instance.



12
13
14
# File 'lib/multi_auth_sample/client.rb', line 12

def o_auth_ccg
  @auth_managers['OAuthCCG']
end

#o_auth_ropcgObject

Returns the configured authentication OAuthROPCG instance.



22
23
24
# File 'lib/multi_auth_sample/client.rb', line 22

def o_auth_ropcg
  @auth_managers['OAuthROPCG']
end