Class: WhatsAppNotifier::Providers::Base
- Inherits:
-
Object
- Object
- WhatsAppNotifier::Providers::Base
- Defined in:
- lib/whatsapp_notifier/providers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #connection_status(metadata: {}) ⇒ Object
- #deliver(_payload) ⇒ Object
-
#initialize(configuration:) ⇒ Base
constructor
A new instance of Base.
- #scan_qr(metadata: {}) ⇒ Object
-
#session_ready?(metadata: {}) ⇒ Boolean
True when the paired session can actually send right now.
Constructor Details
#initialize(configuration:) ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/whatsapp_notifier/providers/base.rb', line 6 def initialize(configuration:) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/whatsapp_notifier/providers/base.rb', line 4 def configuration @configuration end |
Instance Method Details
#connection_status(metadata: {}) ⇒ Object
18 19 20 |
# File 'lib/whatsapp_notifier/providers/base.rb', line 18 def connection_status(metadata: {}) raise NotImplementedError, "#{self.class.name} does not support status checking" end |
#deliver(_payload) ⇒ Object
10 11 12 |
# File 'lib/whatsapp_notifier/providers/base.rb', line 10 def deliver(_payload) raise NotImplementedError, "#{self.class.name} must implement #deliver" end |
#scan_qr(metadata: {}) ⇒ Object
14 15 16 |
# File 'lib/whatsapp_notifier/providers/base.rb', line 14 def scan_qr(metadata: {}) raise NotImplementedError, "#{self.class.name} does not support QR scanning" end |
#session_ready?(metadata: {}) ⇒ Boolean
True when the paired session can actually send right now. Wraps #connection_status so hosts stop reimplementing the same "authenticated == true, rescue transport errors to false" check — a status endpoint the host cannot reach means sends can't succeed either, so an unreachable service reads as not-ready.
ConfigurationError is deliberately NOT swallowed: that is a boot-time
mistake in the host, and answering false would quietly park every
send behind a "session down" backoff instead of surfacing it.
31 32 33 34 35 36 37 38 39 |
# File 'lib/whatsapp_notifier/providers/base.rb', line 31 def session_ready?(metadata: {}) status = connection_status(metadata: ) status.is_a?(Hash) && status[:authenticated] == true rescue ConfigurationError raise rescue StandardError => e configuration.logger&.warn("[WhatsAppNotifier] session_ready? failed: #{e.}") false end |