Class: Heathrow::Plugin::Base
- Inherits:
-
Object
- Object
- Heathrow::Plugin::Base
- Defined in:
- lib/heathrow/plugin/base.rb
Overview
Base class for all Heathrow plugins
All communication source plugins (Gmail, Slack, Discord, etc.) should inherit from this class.
Required Methods:
- fetch_messages: Fetch new messages from the source
Optional Methods:
- send_message: Send a message (if two-way communication supported)
- delete_message: Delete a message
- mark_read: Mark message as read on the source
- can_reply?: Does this source support replying?
- can_delete?: Does this source support deleting messages?
- setup_wizard: Configuration wizard steps
- validate_config: Validate source configuration
- capabilities: List of capabilities this plugin supports
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#event_bus ⇒ Object
readonly
Returns the value of attribute event_bus.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #can_delete? ⇒ Boolean
- #can_mark_read? ⇒ Boolean
-
#can_reply? ⇒ Boolean
Capabilities.
-
#capabilities ⇒ Object
Get all capabilities.
-
#delete_message(external_id) ⇒ Object
Delete a message (if supported).
-
#fetch_messages ⇒ Object
Fetch new messages from the source Must return an array of message hashes: [{ external_id: "msg_123", sender: "[email protected]", sender_name: "John Doe", recipients: ["[email protected]"], subject: "Hello", content: "Message content", timestamp: 1234567890, ... }].
-
#health_check ⇒ Object
Health check Returns [healthy, status_message].
-
#initialize(source, logger: nil, event_bus: nil) ⇒ Base
constructor
A new instance of Base.
-
#mark_read(external_id) ⇒ Object
Mark message as read on the source (if supported).
-
#metadata ⇒ Object
Get source metadata.
-
#send_message(recipients, subject: nil, content:, **options) ⇒ Object
Send a message through this source Returns [success, result_or_error].
-
#setup_wizard ⇒ Object
Setup wizard for configuration Returns array of wizard steps: [{ key: 'api_key', prompt: 'Enter your API key:', type: 'text', required: true }].
- #supports_attachments? ⇒ Boolean
- #supports_real_time? ⇒ Boolean
- #supports_threads? ⇒ Boolean
-
#validate_config ⇒ Object
Validate configuration Returns [valid, error_message].
Constructor Details
#initialize(source, logger: nil, event_bus: nil) ⇒ Base
Returns a new instance of Base.
25 26 27 28 29 30 31 |
# File 'lib/heathrow/plugin/base.rb', line 25 def initialize(source, logger: nil, event_bus: nil) @source = source @config = parse_config(source['config']) @logger = logger @event_bus = event_bus @capabilities = default_capabilities end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/heathrow/plugin/base.rb', line 23 def config @config end |
#event_bus ⇒ Object (readonly)
Returns the value of attribute event_bus.
23 24 25 |
# File 'lib/heathrow/plugin/base.rb', line 23 def event_bus @event_bus end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
23 24 25 |
# File 'lib/heathrow/plugin/base.rb', line 23 def logger @logger end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
23 24 25 |
# File 'lib/heathrow/plugin/base.rb', line 23 def source @source end |
Instance Method Details
#can_delete? ⇒ Boolean
70 71 72 |
# File 'lib/heathrow/plugin/base.rb', line 70 def can_delete? @capabilities.include?('delete') end |
#can_mark_read? ⇒ Boolean
74 75 76 |
# File 'lib/heathrow/plugin/base.rb', line 74 def can_mark_read? @capabilities.include?('mark_read') end |
#can_reply? ⇒ Boolean
Capabilities
66 67 68 |
# File 'lib/heathrow/plugin/base.rb', line 66 def can_reply? @capabilities.include?('write') end |
#capabilities ⇒ Object
Get all capabilities
91 92 93 |
# File 'lib/heathrow/plugin/base.rb', line 91 def capabilities @capabilities end |
#delete_message(external_id) ⇒ Object
Delete a message (if supported)
56 57 58 |
# File 'lib/heathrow/plugin/base.rb', line 56 def (external_id) raise NotImplementedError, "#{self.class} does not support deleting messages" end |
#fetch_messages ⇒ Object
Fetch new messages from the source Must return an array of message hashes:
[{
external_id: "msg_123",
sender: "[email protected]",
sender_name: "John Doe",
recipients: ["[email protected]"],
subject: "Hello",
content: "Message content",
timestamp: 1234567890,
...
}]
45 46 47 |
# File 'lib/heathrow/plugin/base.rb', line 45 def raise NotImplementedError, "#{self.class} must implement fetch_messages" end |
#health_check ⇒ Object
Health check Returns [healthy, status_message]
115 116 117 118 119 120 121 122 123 |
# File 'lib/heathrow/plugin/base.rb', line 115 def health_check begin # Default: try to fetch messages as health check [true, "OK"] rescue => e [false, e.] end end |
#mark_read(external_id) ⇒ Object
Mark message as read on the source (if supported)
61 62 63 |
# File 'lib/heathrow/plugin/base.rb', line 61 def mark_read(external_id) raise NotImplementedError, "#{self.class} does not support marking messages as read" end |
#metadata ⇒ Object
Get source metadata
126 127 128 129 130 131 132 |
# File 'lib/heathrow/plugin/base.rb', line 126 def { type: self.class.name.split('::').last.downcase, capabilities: @capabilities, config_keys: @config.keys } end |
#send_message(recipients, subject: nil, content:, **options) ⇒ Object
Send a message through this source Returns [success, result_or_error]
51 52 53 |
# File 'lib/heathrow/plugin/base.rb', line 51 def (recipients, subject: nil, content:, **) raise NotImplementedError, "#{self.class} does not support sending messages" end |
#setup_wizard ⇒ Object
Setup wizard for configuration Returns array of wizard steps:
[{
key: 'api_key',
prompt: 'Enter your API key:',
type: 'text',
required: true
}]
103 104 105 |
# File 'lib/heathrow/plugin/base.rb', line 103 def setup_wizard [] end |
#supports_attachments? ⇒ Boolean
82 83 84 |
# File 'lib/heathrow/plugin/base.rb', line 82 def @capabilities.include?('attachments') end |
#supports_real_time? ⇒ Boolean
78 79 80 |
# File 'lib/heathrow/plugin/base.rb', line 78 def supports_real_time? @capabilities.include?('real_time') end |
#supports_threads? ⇒ Boolean
86 87 88 |
# File 'lib/heathrow/plugin/base.rb', line 86 def supports_threads? @capabilities.include?('threads') end |
#validate_config ⇒ Object
Validate configuration Returns [valid, error_message]
109 110 111 |
# File 'lib/heathrow/plugin/base.rb', line 109 def validate_config [true, nil] end |