Class: LokaliseManager::TaskDefinitions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lokalise_manager/task_definitions/base.rb

Overview

Base class for LokaliseManager task definitions.

Provides shared functionality for Importer and Exporter classes, including:

  • API client management.

  • Configuration merging.

  • File validation helpers.

  • Exponential backoff for retrying failed API requests.

Direct Known Subclasses

Exporter, Importer

Constant Summary collapse

EXCEPTIONS =

Defines exceptions that should trigger a retry with exponential backoff.

  • JSON::ParserError: Occurs when the API responds with non-JSON content (e.g., HTML due to rate limits).

  • RubyLokaliseApi::Error::TooManyRequests: Raised when too many requests are sent in a short period.

[JSON::ParserError, RubyLokaliseApi::Error::TooManyRequests].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_opts = {}, global_config = LokaliseManager::GlobalConfig) ⇒ Base

Initializes a new task object with merged global and custom configurations.

Parameters:

  • custom_opts (Hash) (defaults to: {})

    Custom configuration options specific to the task.

  • global_config (Object) (defaults to: LokaliseManager::GlobalConfig)

    The global configuration object.



30
31
32
33
# File 'lib/lokalise_manager/task_definitions/base.rb', line 30

def initialize(custom_opts = {}, global_config = LokaliseManager::GlobalConfig)
  merged_opts = merge_configs(global_config, custom_opts)
  @config = build_config_class(merged_opts)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/lokalise_manager/task_definitions/base.rb', line 18

def config
  @config
end

Instance Method Details

#api_clientRubyLokaliseApi::Client

Retrieves or initializes the Lokalise API client based on the current configuration.

Returns:

  • (RubyLokaliseApi::Client)

    An instance of the Lokalise API client.



38
39
40
# File 'lib/lokalise_manager/task_definitions/base.rb', line 38

def api_client
  @api_client ||= create_api_client
end

#reset_api_client!Object

Resets the API client, clearing cached instances.

Useful when switching authentication tokens or handling connection issues.



45
46
47
48
49
# File 'lib/lokalise_manager/task_definitions/base.rb', line 45

def reset_api_client!
  ::RubyLokaliseApi.reset_client!
  ::RubyLokaliseApi.reset_oauth2_client!
  @api_client = nil
end