Class: Blocks::Sdk::Clients::TranslationsClient
- Inherits:
-
BaseClient
- Object
- BaseClient
- Blocks::Sdk::Clients::TranslationsClient
- Defined in:
- lib/blocks/sdk/clients/translations_client.rb
Overview
Client for UILM Translation Service
Instance Attribute Summary
Attributes inherited from BaseClient
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(module_name:, language: "en") ⇒ Object
- #handle_webhook(payload) ⇒ Object
-
#initialize(config = {}) ⇒ TranslationsClient
constructor
A new instance of TranslationsClient.
Methods inherited from BaseClient
Constructor Details
#initialize(config = {}) ⇒ TranslationsClient
Returns a new instance of TranslationsClient.
18 19 20 21 22 |
# File 'lib/blocks/sdk/clients/translations_client.rb', line 18 def initialize(config = {}) super(config) @base_url = config[:base_url] || ENV.fetch("UILM_BASE_URL") @project_key = config[:project_key] || ENV.fetch("UILM_PROJECT_KEY") end |
Class Method Details
.service_name ⇒ Object
13 14 15 |
# File 'lib/blocks/sdk/clients/translations_client.rb', line 13 def service_name "translations" end |
Instance Method Details
#fetch(module_name:, language: "en") ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/blocks/sdk/clients/translations_client.rb', line 24 def fetch(module_name:, language: "en") conn = build_connection request_params = { ModuleName: module_name, ProjectKey: @project_key, Language: normalize_language(language) } response = conn.get( @base_url, request_params, build_headers ) handle_response(response) rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e log_error("UILM API connection failed: #{e.}") { error: "Connection failed", status: :connection_error } rescue StandardError => e log_error("Unexpected error in TranslationsClient: #{e.}") { error: "Unexpected error occurred", status: :error } end |
#handle_webhook(payload) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/blocks/sdk/clients/translations_client.rb', line 48 def handle_webhook(payload) # Extract cache invalidation parameters from webhook payload # Expected payload structure: { module_name: "...", language: "..." } module_name = payload[:module_name] || payload["module_name"] language = payload[:language] || payload["language"] || "en" { service: service_name, module_name: module_name, language: language, action: :invalidate_cache } end |