noticed icon indicating copy to clipboard operation
noticed copied to clipboard

Defaults options to delivery methods

Open rafaelpivato opened this issue 4 years ago • 0 comments

To favor sub-classing, allow default options to be defined for a notification. Here goes a suggestion:

class ApplicationNotification < Noticed::Base
  deliver_by_defaults :database, format: :database_format
  deliver_by_defaults :action_cable, format: :action_cable_format
  deliver_by_defaults :twilio, credentials: :twilio_credentials

  def database_format
    {
      'type': self.class.name,
      'params': params
    }
  end

  def action_cable_format
    params
  end

  def twilio_credentials
    {
      account_sid: ENV['TWILIO_ACCOUNT_SID'],
      auth_token: ENV['TWILIO_AUTH_TOKEN'],
      phone_number: ENV['TWILIO_PHONE_NUMBER']
    }
  end
end


class CommentCreatedNotification < ApplicationNotification
  deliver_by :database
  deliver_by :action_cable
  deliver_by :twilio
end

This wold work nice with #94 as well.

rafaelpivato avatar Feb 21 '21 19:02 rafaelpivato