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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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]
  @send_after = params[:send_after].to_s
  @attachments = params[:attachments]
  @filters = params[:filters]
  @sounds = params[:sounds]
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

#contentsObject (readonly)

Returns the value of attribute contents.



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

def contents
  @contents
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

#headingsObject (readonly)

Returns the value of attribute headings.



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

def headings
  @headings
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

#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



27
28
29
30
31
32
33
# File 'lib/onesignal/notification.rb', line 27

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