Class: Dadata::ClientBase Private

Inherits:
Object
  • Object
show all
Includes:
SensitiveData
Defined in:
lib/dadata/client/base.rb

Overview

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

Base client class that handles HTTP communication with the DaData API. Implements secure logging and request/response handling.

Direct Known Subclasses

CleanClient, ProfileClient, SuggestClient

Constant Summary collapse

ERRORS =

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

HTTP status codes and their descriptions

{
  200 => 'Request processed successfully',
  400 => 'Invalid request (invalid JSON or XML)',
  401 => 'Missing API key or secret key, or non-existent key used',
  403 => 'Invalid API key, unconfirmed email, or daily request limit exceeded',
  404 => 'Service not found',
  405 => 'Request method other than POST used',
  413 => 'Request too long or too many conditions',
  429 => 'Too many requests per second or new connections per minute',
  500 => 'Internal service error'
}.freeze
STATUS_ERRORS =

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

Maps HTTP status codes to the specific error class to raise. Any status not listed falls back to the generic ApiError.

{
  400 => BadRequestError,
  401 => UnauthorizedError,
  403 => AuthenticationError,
  404 => NotFoundError,
  429 => RateLimitError
}.freeze

Constants included from SensitiveData

SensitiveData::SENSITIVE_HEADERS

Instance Method Summary collapse

Methods included from SensitiveData

#sanitize_headers, #sanitize_message

Constructor Details

#initialize(base_url, token, secret = nil) ⇒ ClientBase

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.

Creates a new client instance

Parameters:

  • base_url (String)

    The base URL for API requests

  • token (String)

    The API token for authentication

  • secret (String, nil) (defaults to: nil)

    Optional secret key for additional authentication



141
142
143
144
145
146
147
# File 'lib/dadata/client/base.rb', line 141

def initialize(base_url, token, secret = nil)
  @base_url = base_url
  @token = token
  @secret = secret
  @connection = build_connection
  @logger = Dadata.configuration&.logger
end

Instance Method Details

#closevoid

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.

This method returns an undefined value.

Closes the persistent connection, releasing any pooled sockets.



168
169
170
# File 'lib/dadata/client/base.rb', line 168

def close
  @connection.close if @connection.respond_to?(:close)
end

#submit(url, data, method = :get, timeout: Dadata.timeout_sec) ⇒ Hash

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.

Submits a request to the API

Parameters:

  • url (String)

    The endpoint URL

  • data (Hash)

    The request data

  • method (Symbol) (defaults to: :get)

    The HTTP method to use (:get or :post)

  • timeout (Integer) (defaults to: Dadata.timeout_sec)

    Request timeout in seconds

Returns:

  • (Hash)

    The parsed response

Raises:



158
159
160
161
162
163
# File 'lib/dadata/client/base.rb', line 158

def submit(url, data, method = :get, timeout: Dadata.timeout_sec)
  response = send_request(url, data, method, timeout)
  handle_response(response)
rescue Faraday::Error => e
  handle_connection_error(e)
end