Class: WhatsAppNotifier::Session::QrService
- Inherits:
-
Object
- Object
- WhatsAppNotifier::Session::QrService
- Defined in:
- lib/whatsapp_notifier/session/qr_service.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #activate!(token) ⇒ Object
-
#initialize(store:, adapter:) ⇒ QrService
constructor
A new instance of QrService.
- #qr_code(metadata: {}) ⇒ Object
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
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/whatsapp_notifier/session/qr_service.rb', line 4 def adapter @adapter end |
#store ⇒ Object (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 |