Class: WhatsAppNotifier::Providers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_notifier/providers/base.rb

Direct Known Subclasses

WebAutomation

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configurationObject (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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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.

Returns:

  • (Boolean)


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.message}")
  false
end