Module: DeepL::Utils::ClientBuilder Private

Extended by:
ClientBuilder
Included in:
ClientBuilder
Defined in:
lib/deepl/utils/client_builder.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Builds the API connection of a DeepL::Client or DeepL::AdminClient from its constructor options. Nothing is read from the environment or from module state.

Instance Method Summary collapse

Instance Method Details

#build_api(key, key_name:, server_url:, default_server_url:, headers:, max_retries:, timeout:, proxy:, send_platform_info:, app_info:, http_client_options:, logger:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/deepl/utils/client_builder.rb', line 14

def build_api(key, key_name:, server_url:, default_server_url:, headers:, max_retries:,
              timeout:, proxy:, send_platform_info:, app_info:, http_client_options:, logger:) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/ParameterLists
  key = key.to_s.strip
  raise ArgumentError, "#{key_name} must not be empty" if key.empty?

  host = host(server_url, default_server_url)
  headers = (headers || {}).to_h
  configuration = Configuration.new(
    auth_key: key, host: host, max_network_retries: or_default(max_retries, 5),
    timeout: or_default(timeout, 10), logger: logger,
    headers: headers.reject { |name, _| user_agent_header?(name) },
    user_agent: headers.find { |name, _| user_agent_header?(name) }&.last,
    send_platform_info: or_default(send_platform_info, true), app_info: AppInfo.from(app_info)
  )
  API.new(configuration, merge_proxy(http_client_options, proxy))
end