Class: Blocks::Sdk::BaseClient
- Inherits:
-
Object
- Object
- Blocks::Sdk::BaseClient
- 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
Class Attribute Summary collapse
-
.service_name ⇒ Object
Returns the value of attribute service_name.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#fetch ⇒ Object
Override in subclasses to fetch data from the service.
-
#handle_webhook(payload) ⇒ Object
Override in subclasses to handle webhook callbacks.
-
#initialize(config = {}) ⇒ BaseClient
constructor
A new instance of BaseClient.
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_name ⇒ Object
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
#config ⇒ Object (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
#fetch ⇒ Object
Override in subclasses to fetch data from the service
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
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 |