Class: OneSignal::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/onesignal/notification.rb,
lib/onesignal/notification/contents.rb,
lib/onesignal/notification/headings.rb

Defined Under Namespace

Classes: Contents, Headings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ Notification

Returns a new instance of Notification.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/onesignal/notification.rb', line 12

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]
  @email_subject     = params[:email_subject]
  @email_body        = params[:email_body]
  @send_after        = params[:send_after].to_s
  @attachments       = params[:attachments]
  @filters           = params[:filters]
  @sounds            = params[:sounds]
  @buttons           = params[:buttons]
  @icons             = params[:icons]
  @external_id       = params[:external_id]
end

Instance Attribute Details

#attachmentsObject (readonly)

Returns the value of attribute attachments.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def attachments
  @attachments
end

#buttonsObject (readonly)

Returns the value of attribute buttons.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def buttons
  @buttons
end

#contentsObject (readonly)

Returns the value of attribute contents.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def contents
  @contents
end

#email_bodyObject (readonly)

Returns the value of attribute email_body.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def email_body
  @email_body
end

#email_subjectObject (readonly)

Returns the value of attribute email_subject.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def email_subject
  @email_subject
end

#excluded_segmentsObject (readonly)

Returns the value of attribute excluded_segments.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def excluded_segments
  @excluded_segments
end

#external_idObject (readonly)

Returns the value of attribute external_id.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def external_id
  @external_id
end

#headingsObject (readonly)

Returns the value of attribute headings.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def headings
  @headings
end

#iconsObject (readonly)

Returns the value of attribute icons.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def icons
  @icons
end

#included_segmentsObject (readonly)

Returns the value of attribute included_segments.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def included_segments
  @included_segments
end

#included_targetsObject (readonly)

Returns the value of attribute included_targets.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def included_targets
  @included_targets
end

#send_afterObject (readonly)

Returns the value of attribute send_after.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def send_after
  @send_after
end

#soundsObject (readonly)

Returns the value of attribute sounds.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def sounds
  @sounds
end

#template_idObject (readonly)

Returns the value of attribute template_id.



8
9
10
# File 'lib/onesignal/notification.rb', line 8

def template_id
  @template_id
end

Instance Method Details

#as_json(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/onesignal/notification.rb', line 34

def as_json options = {}
  super(options)
    .except('attachments', 'sounds', 'included_targets', 'icons')
    .merge(@attachments&.as_json(options) || {})
    .merge(@sounds&.as_json(options) || {})
    .merge(@buttons&.as_json(options) || {})
    .merge(@included_targets&.as_json(options) || {})
    .merge(@icons&.as_json(options) || {})
    .select { |_k, v| v.present? }
end