Method: ActivityNotification::NotificationApi.notify_to

Defined in:
lib/activity_notification/apis/notification_api.rb

.notify_to(target, notifiable, options = {}) ⇒ Notification Also known as: notify_now_to

Generates notifications to one target.

Examples:

Notify to one user

ActivityNotification::Notification.notify_to @comment.auther, @comment

Parameters:

  • target (Object)

    Target to send notifications

  • notifiable (Object)

    Notifiable instance

  • options (Hash) (defaults to: {})

    Options for notifications

Options Hash (options):

  • :key (String) — default: notifiable.default_notification_key

    Key of the notification

  • :group (Object) — default: nil

    Group unit of the notifications

  • :group_expiry_delay (ActiveSupport::Duration) — default: nil

    Expiry period of a notification group

  • :notifier (Object) — default: nil

    Notifier of the notifications

  • :parameters (Hash) — default: {}

    Additional parameters of the notifications

  • :notify_later (Boolean) — default: false

    Whether it generates notifications asynchronously

  • :send_email (Boolean) — default: true

    Whether it sends notification email

  • :send_later (Boolean) — default: true

    Whether it sends notification email asynchronously

  • :publish_optional_targets (Boolean) — default: true

    Whether it publishes notification to optional targets

  • :optional_targets (Hash<String, Hash>) — default: {}

    Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options

Returns:



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/activity_notification/apis/notification_api.rb', line 340

def notify_to(target, notifiable, options = {})
  if options[:notify_later]
    notify_later_to(target, notifiable, options)
  else
    send_email               = options.has_key?(:send_email)               ? options[:send_email]               : true
    send_later               = options.has_key?(:send_later)               ? options[:send_later]               : true
    publish_optional_targets = options.has_key?(:publish_optional_targets) ? options[:publish_optional_targets] : true
    # Generate notification
    notification = generate_notification(target, notifiable, options)
    # Send notification email
    if notification.present? && send_email
      notification.send_notification_email({ send_later: send_later })
    end
    # Publish to optional targets
    if notification.present? && publish_optional_targets
      notification.publish_to_optional_targets(options[:optional_targets] || {})
    end
    # Return generated notification
    notification
  end
end