Class: Blocks::Sdk::BaseClient

Inherits:
Object
  • Object
show all
Defined in:
lib/blocks/sdk/base_client.rb

Overview

Base class for all Blocks Service clients Subclasses should implement the service-specific logic

Direct Known Subclasses

Clients::TranslationsClient

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ BaseClient

Returns a new instance of BaseClient.



21
22
23
# File 'lib/blocks/sdk/base_client.rb', line 21

def initialize(config = {})
  @config = config
end

Class Attribute Details

.service_nameObject

Returns the value of attribute service_name.



7
8
9
# File 'lib/blocks/sdk/base_client.rb', line 7

def service_name
  @service_name
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/blocks/sdk/base_client.rb', line 19

def config
  @config
end

Class Method Details

.inherited(subclass) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/blocks/sdk/base_client.rb', line 9

def inherited(subclass)
  super
  # Extract service name from class name (e.g., "TranslationsClient" -> "translations")
  class_name            = subclass.name.split("::").last
  subclass.service_name = class_name.gsub(/Client$/, "").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
                                    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
                                    .downcase
end

Instance Method Details

#fetchObject

Override in subclasses to fetch data from the service

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/blocks/sdk/base_client.rb', line 26

def fetch
  raise NotImplementedError, "#{self.class} must implement #fetch"
end

#handle_webhook(payload) ⇒ Object

Override in subclasses to handle webhook callbacks

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/blocks/sdk/base_client.rb', line 31

def handle_webhook(payload)
  raise NotImplementedError, "#{self.class} must implement #handle_webhook"
end