class OneSignal::Notification

Attributes

attachments[R]
buttons[R]
contents[R]
excluded_segments[R]
headings[R]
included_segments[R]
included_targets[R]
send_after[R]
sounds[R]
template_id[R]

Public Class Methods

new(**params) click to toggle source
# File lib/onesignal/notification.rb, line 11
def initialize **params
  unless params.include?(:contents) || params.include?(:template_id)
    raise ArgumentError, 'missing contents or template_id'
  end

  @contents          = params[:contents]
  @headings          = params[:headings]
  @template_id       = params[:template_id]
  @included_segments = params[:included_segments]
  @excluded_segments = params[:excluded_segments]
  @included_targets  = params[:included_targets]
  @send_after        = params[:send_after].to_s
  @attachments       = params[:attachments]
  @filters           = params[:filters]
  @sounds            = params[:sounds]
  @buttons           = params[:buttons]
end

Public Instance Methods

as_json(options = {}) click to toggle source
Calls superclass method
# File lib/onesignal/notification.rb, line 29
def as_json options = {}
  super(options)
    .except('attachments', 'sounds', 'included_targets')
    .merge(@attachments&.as_json(options) || {})
    .merge(@sounds&.as_json(options) || {})
    .merge(@buttons&.as_json(options) || {})
    .merge(@included_targets&.as_json(options) || {})
    .select { |_k, v| v.present? }
end