Class: WhatsAppNotifier::Session::QrService

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_notifier/session/qr_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store:, adapter:) ⇒ QrService

Returns a new instance of QrService.



6
7
8
9
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 6

def initialize(store:, adapter:)
  @store = store
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



4
5
6
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 4

def adapter
  @adapter
end

#storeObject (readonly)

Returns the value of attribute store.



4
5
6
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 4

def store
  @store
end

Instance Method Details

#activate!(token) ⇒ Object



17
18
19
20
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 17

def activate!(token)
  session = store.load
  store.save(session.merge(active: true, token: token, qr_code: nil))
end

#qr_code(metadata: {}) ⇒ Object



11
12
13
14
15
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 11

def qr_code(metadata: {})
  # We don't cache the QR code because it expires every ~20 seconds.
  # The underlying adapter/service provides the latest one each call.
  adapter.fetch_qr_code(metadata: )
end