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



23
24
25
26
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 23

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
16
17
18
19
20
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 11

def qr_code(metadata: {})
  session = store.load
  user_id = [:user_id]
  cached = cached_qr(session, user_id)
  return cached if cached

  generated = adapter.fetch_qr_code(metadata: )
  store.save(with_cached_qr(session, user_id, generated))
  generated
end