Class: CoreLibrary::GlobalConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic-core/configurations/global_configuration.rb

Overview

A class to hold the global configurations for the core library. This class is initiated from the SDK.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_configuration: HttpClientConfiguration.new) ⇒ GlobalConfiguration

Initializes a new instance of GlobalConfiguration.

Parameters:

  • client_configuration (HttpClientConfiguration) (defaults to: HttpClientConfiguration.new)

    Current HttpClientConfiguration.



8
9
10
11
12
13
14
15
16
17
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 8

def initialize(client_configuration: HttpClientConfiguration.new)
  @client_configuration = client_configuration
  @global_errors = {}
  @global_headers = {}
  @additional_headers = {}
  @auth_managers = {}
  @base_uri_executor = nil
  @sdk_module = nil
  @symbolize_hash = false
end

Instance Attribute Details

#client_configurationObject (readonly)

Returns the value of attribute client_configuration.



4
5
6
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 4

def client_configuration
  @client_configuration
end

Instance Method Details

#add_useragent_in_headers(user_agent, agent_parameters) ⇒ Object

Updates the user agent template with the provided parameters and adds user agent in the global_headers.

Parameters:

  • user_agent (String)

    The user agent template string.

  • agent_parameters (Hash, Optional)

    The agent configurations to be replaced in the actual user agent value.



146
147
148
149
150
151
152
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 146

def add_useragent_in_headers(user_agent, agent_parameters)
  if !agent_parameters.nil? && agent_parameters.any?
    user_agent = ApiHelper.update_user_agent_value_with_parameters(user_agent,
                                                                   agent_parameters).gsub('  ', ' ')
  end
  @global_headers['user-agent'] = user_agent unless user_agent.nil?
end

#additional_header(key, value) ⇒ GlobalConfiguration

The setter for a additional header to be attached with all requests.

Parameters:

  • key (String)

    The key of a additional header.

  • value (Object)

    The value of a additional header.

Returns:



81
82
83
84
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 81

def additional_header(key, value)
  @additional_headers[key] = value
  self
end

#additional_headers(additional_headers) ⇒ GlobalConfiguration

The setter for the additional headers to be attached with all requests.

Parameters:

  • additional_headers (Hash)

    The hash of additional headers.

Returns:



72
73
74
75
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 72

def additional_headers(additional_headers)
  @additional_headers = additional_headers
  self
end

#auth_managers(auth_managers) ⇒ GlobalConfiguration

The setter for the auth managers.

Parameters:

  • auth_managers (Hash)

    The hash of auth managers.

Returns:



95
96
97
98
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 95

def auth_managers(auth_managers)
  @auth_managers = auth_managers
  self
end

#base_uri_executor(base_uri_executor) ⇒ GlobalConfiguration

The setter for the base URI extractor callable.

Parameters:

  • base_uri_executor (Callable)

    The callable for the base URI extractor.

Returns:



118
119
120
121
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 118

def base_uri_executor(base_uri_executor)
  @base_uri_executor = base_uri_executor
  self
end

#get_additional_headersHash

The getter for the additional headers.

Returns:

  • (Hash)

    The hash of additional headers.



88
89
90
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 88

def get_additional_headers
  @additional_headers
end

#get_auth_managersHash

The getter for the auth managers.

Returns:

  • (Hash)

    The hash of auth managers.



102
103
104
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 102

def get_auth_managers
  @auth_managers
end

#get_base_uri_executorCallable

The getter for the base URI extractor.

Returns:

  • (Callable)

    The base URI extractor.



125
126
127
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 125

def get_base_uri_executor
  @base_uri_executor
end

#get_global_errorsHash

The getter for the global errors.

Returns:

  • (Hash)

    The hash of global errors.



29
30
31
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 29

def get_global_errors
  @global_errors
end

#get_global_headersHash

The getter for the global headers.

Returns:

  • (Hash)

    The hash of global headers.



65
66
67
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 65

def get_global_headers
  @global_headers
end

#get_sdk_moduleModule

Getter for the current SDK module the core library is being used for.

Returns:

  • (Module)

    Current SDK module.



42
43
44
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 42

def get_sdk_module
  @sdk_module
end

#global_errors(global_errors) ⇒ GlobalConfiguration

The setter for the global errors.

Parameters:

  • global_errors (Hash)

    The hash of global errors.

Returns:



22
23
24
25
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 22

def global_errors(global_errors)
  @global_errors = global_errors
  self
end

#global_header(key, value) ⇒ GlobalConfiguration

The setter for a global header to be attached with all requests.

Parameters:

  • key (String)

    The key of a global header.

  • value (Object)

    The value of a global header.

Returns:



58
59
60
61
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 58

def global_header(key, value)
  @global_headers[key] = value
  self
end

#global_headers(global_headers) ⇒ GlobalConfiguration

The setter for the global headers to be attached with all requests.

Parameters:

  • global_headers (Hash)

    The hash of global headers.

Returns:



49
50
51
52
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 49

def global_headers(global_headers)
  @global_headers = global_headers
  self
end

#sdk_module(sdk_module) ⇒ GlobalConfiguration

Sets the current SDK module core library is being used for.

Returns:



35
36
37
38
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 35

def sdk_module(sdk_module)
  @sdk_module = sdk_module
  self
end

#should_symbolize_hashBoolean

The setter for the flag of wrapping the body parameters in a hash.

Returns:

  • (Boolean)

    True if symbolizing hash is allowed during deserialization of response.



139
140
141
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 139

def should_symbolize_hash
  @symbolize_hash
end

#symbolize_hash(symbolize_hash) ⇒ GlobalConfiguration

The setter for the flag of symbolizing hash while deserialization.

Parameters:

  • symbolize_hash (Boolean)

    The flag of symbolizing hash while deserialization.

Returns:



132
133
134
135
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 132

def symbolize_hash(symbolize_hash)
  @symbolize_hash = symbolize_hash
  self
end

#user_agent(user_agent, agent_parameters: {}) ⇒ GlobalConfiguration

The setter for the user agent information to be attached with all requests.

Parameters:

  • user_agent (String)

    The user agent template string.

  • agent_parameters (Hash, Optional) (defaults to: {})

    The agent configuration to be replaced in the actual user agent template.

Returns:



110
111
112
113
# File 'lib/apimatic-core/configurations/global_configuration.rb', line 110

def user_agent(user_agent, agent_parameters: {})
  add_useragent_in_headers(user_agent, agent_parameters)
  self
end