Module: Whatsapp::Rails::Helpers
- Defined in:
- lib/whatsapp/rails/helpers.rb
Overview
View helpers for displaying WhatsApp session information in Rails views.
Automatically included in ActionView when the Railtie loads.
Instance Method Summary collapse
-
#whatsapp_connected?(account_or_key) ⇒ Boolean
Whether the session is connected.
-
#whatsapp_qr(account_or_key, size: 200, html_options: {}) ⇒ String?
Render a QR code as an +
+ tag with a base64 data URI.
-
#whatsapp_rate_limit_info(account_or_key) ⇒ Hash
Get rate limiting statistics for a session.
-
#whatsapp_status(account_or_key) ⇒ Symbol
Get the session status as a symbol.
-
#whatsapp_status_badge(account_or_key, html_options: {}) ⇒ String
Render a status badge as a ++ with CSS classes.
Instance Method Details
#whatsapp_connected?(account_or_key) ⇒ Boolean
Whether the session is connected.
40 41 42 |
# File 'lib/whatsapp/rails/helpers.rb', line 40 def whatsapp_connected?(account_or_key) resolve_session(account_or_key).connected? end |
#whatsapp_qr(account_or_key, size: 200, html_options: {}) ⇒ String?
Render a QR code as an ++ tag with a base64 data URI.
18 19 20 21 22 23 24 25 26 |
# File 'lib/whatsapp/rails/helpers.rb', line 18 def whatsapp_qr(account_or_key, size: 200, html_options: {}) session = resolve_session(account_or_key) qr = session.qr_data return nil unless qr src = "data:image/png;base64,#{qr}" opts = {src: src, width: size, height: size, alt: "WhatsApp QR Code"}.merge() tag(:img, opts) end |
#whatsapp_rate_limit_info(account_or_key) ⇒ Hash
Get rate limiting statistics for a session.
48 49 50 |
# File 'lib/whatsapp/rails/helpers.rb', line 48 def whatsapp_rate_limit_info(account_or_key) resolve_session(account_or_key).rate_limit_stats end |
#whatsapp_status(account_or_key) ⇒ Symbol
Get the session status as a symbol.
32 33 34 |
# File 'lib/whatsapp/rails/helpers.rb', line 32 def whatsapp_status(account_or_key) resolve_session(account_or_key).status end |
#whatsapp_status_badge(account_or_key, html_options: {}) ⇒ String
Render a status badge as a ++ with CSS classes.
57 58 59 60 61 62 |
# File 'lib/whatsapp/rails/helpers.rb', line 57 def whatsapp_status_badge(account_or_key, html_options: {}) status = whatsapp_status(account_or_key) css = "whatsapp-status whatsapp-status--#{status}" css = "#{css} #{.delete(:class)}" if [:class] content_tag(:span, status.to_s, {class: css}.merge()) end |