Class: WhatsAppNotifier::Notification
- Inherits:
-
Object
- Object
- WhatsAppNotifier::Notification
- Defined in:
- lib/whatsapp_notifier/notification.rb
Class Attribute Summary collapse
-
.default_provider ⇒ Object
Returns the value of attribute default_provider.
-
.default_template ⇒ Object
Returns the value of attribute default_template.
-
.default_to ⇒ Object
Returns the value of attribute default_to.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
- .deliver_later(params = {}) ⇒ Object
- .deliver_now(params = {}) ⇒ Object
- .provider(value = nil) ⇒ Object
- .template(name = nil, body = nil) ⇒ Object
- .templates ⇒ Object
- .to(value = nil) ⇒ Object
- .with(params = {}) ⇒ Object
Instance Method Summary collapse
- #deliver_now ⇒ Object
-
#initialize(params = {}) ⇒ Notification
constructor
A new instance of Notification.
- #message ⇒ Object
- #metadata ⇒ Object
- #provider ⇒ Object
- #template_name ⇒ Object
- #template_params ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Notification
Returns a new instance of Notification.
43 44 45 |
# File 'lib/whatsapp_notifier/notification.rb', line 43 def initialize(params = {}) @params = params end |
Class Attribute Details
.default_provider ⇒ Object
Returns the value of attribute default_provider.
4 5 6 |
# File 'lib/whatsapp_notifier/notification.rb', line 4 def default_provider @default_provider end |
.default_template ⇒ Object
Returns the value of attribute default_template.
4 5 6 |
# File 'lib/whatsapp_notifier/notification.rb', line 4 def default_template @default_template end |
.default_to ⇒ Object
Returns the value of attribute default_to.
4 5 6 |
# File 'lib/whatsapp_notifier/notification.rb', line 4 def default_to @default_to end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
41 42 43 |
# File 'lib/whatsapp_notifier/notification.rb', line 41 def params @params end |
Class Method Details
.deliver_later(params = {}) ⇒ Object
36 37 38 |
# File 'lib/whatsapp_notifier/notification.rb', line 36 def deliver_later(params = {}) Jobs::SendMessageJob.perform_later(name, params) end |
.deliver_now(params = {}) ⇒ Object
32 33 34 |
# File 'lib/whatsapp_notifier/notification.rb', line 32 def deliver_now(params = {}) with(params).deliver_now end |
.provider(value = nil) ⇒ Object
15 16 17 18 |
# File 'lib/whatsapp_notifier/notification.rb', line 15 def provider(value = nil) return default_provider if value.nil? self.default_provider = value end |
.template(name = nil, body = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/whatsapp_notifier/notification.rb', line 20 def template(name = nil, body = nil) @templates ||= {} return default_template if name.nil? self.default_template = name.to_sym @templates[name.to_sym] = body if body end |
.templates ⇒ Object
28 29 30 |
# File 'lib/whatsapp_notifier/notification.rb', line 28 def templates @templates ||= {} end |
.to(value = nil) ⇒ Object
10 11 12 13 |
# File 'lib/whatsapp_notifier/notification.rb', line 10 def to(value = nil) return default_to if value.nil? self.default_to = value end |
.with(params = {}) ⇒ Object
6 7 8 |
# File 'lib/whatsapp_notifier/notification.rb', line 6 def with(params = {}) new(params) end |
Instance Method Details
#deliver_now ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/whatsapp_notifier/notification.rb', line 73 def deliver_now raise ConfigurationError, "recipient is required" if to.nil? || to.to_s.strip.empty? WhatsAppNotifier.deliver( to: to, body: , provider: provider, metadata: ) end |
#message ⇒ Object
47 48 49 50 51 |
# File 'lib/whatsapp_notifier/notification.rb', line 47 def return render_template if template_name raise NotImplementedError, "#{self.class.name} must implement #message or define template" end |
#metadata ⇒ Object
61 62 63 |
# File 'lib/whatsapp_notifier/notification.rb', line 61 def params[:metadata] || {} end |
#provider ⇒ Object
57 58 59 |
# File 'lib/whatsapp_notifier/notification.rb', line 57 def provider params[:provider] || self.class.default_provider end |
#template_name ⇒ Object
65 66 67 |
# File 'lib/whatsapp_notifier/notification.rb', line 65 def template_name (params[:template] || self.class.default_template)&.to_sym end |
#template_params ⇒ Object
69 70 71 |
# File 'lib/whatsapp_notifier/notification.rb', line 69 def template_params params[:params] || {} end |
#to ⇒ Object
53 54 55 |
# File 'lib/whatsapp_notifier/notification.rb', line 53 def to params[:to] || self.class.default_to end |