Module: Urbanairship::Push::Payload

Includes:
Common
Included in:
Urbanairship
Defined in:
lib/urbanairship/push/payload.rb

Constant Summary

Constants included from Common

Common::CONTENT_TYPE

Instance Method Summary collapse

Methods included from Common

#apid_path, #channel_path, #compact_helper, #create_and_send_path, #custom_events_path, #device_token_path, #experiments_path, #lists_path, #named_users_path, #open_channel_path, #pipelines_path, #push_path, #reports_path, #required, #schedules_path, #segments_path, #tag_lists_path, #try_helper

Instance Method Details

#actions(add_tag: nil, remove_tag: nil, open_: nil, share: nil, app_defined: nil) ⇒ Object

Actions for a Push Notification Object



242
243
244
245
246
247
248
249
250
251
# File 'lib/urbanairship/push/payload.rb', line 242

def actions(add_tag: nil, remove_tag: nil, open_: nil, share: nil,
            app_defined: nil)
  compact_helper({
    add_tag: add_tag,
    remove_tag: remove_tag,
    open: open_,
    share: share,
    app_defined: app_defined
  })
end

#allObject



211
212
213
# File 'lib/urbanairship/push/payload.rb', line 211

def all
  'all'
end

#amazon(alert: nil, consolidation_key: nil, expires_after: nil, extra: nil, title: nil, summary: nil, interactive: nil, style: nil, sound: nil) ⇒ Object

Amazon specific portion of Push Notification Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/urbanairship/push/payload.rb', line 59

def amazon(alert: nil, consolidation_key: nil, expires_after: nil,
           extra: nil, title: nil, summary: nil, interactive: nil, style: nil, sound: nil)
  compact_helper({
    alert: alert,
    consolidation_key: consolidation_key,
    expires_after: expires_after,
    extra: extra,
    title: title,
    summary: summary,
    interactive: interactive,
    style: style,
    sound: sound
  })
end

#android(title: nil, alert: nil, summary: nil, extra: nil, style: nil, icon: nil, icon_color: nil, notification_tag: nil, notification_channel: nil, category: nil, visibility: nil, public_notification: nil, sound: nil, priority: nil, collapse_key: nil, time_to_live: nil, delivery_priority: nil, delay_while_idle: nil, local_only: nil, wearable: nil, background_image: nil, extra_pages: nil, interactive: nil, live_update: nil) ⇒ Object

Android specific portion of Push Notification Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/urbanairship/push/payload.rb', line 75

def android(title: nil, alert: nil, summary: nil, extra: nil,
            style: nil, icon: nil, icon_color: nil, notification_tag: nil,
            notification_channel: nil, category: nil, visibility: nil,
            public_notification: nil, sound: nil, priority: nil, collapse_key: nil,
            time_to_live: nil, delivery_priority: nil, delay_while_idle: nil,
            local_only: nil, wearable: nil, background_image: nil, extra_pages: nil,
            interactive: nil, live_update: nil)
  compact_helper({
    title: title,
    alert: alert,
    summary: summary,
    extra: extra,
    style: style,
    icon: icon,
    icon_color: icon_color,
    notification_tag: notification_tag,
    notification_channel: notification_channel,
    category: category,
    visibility: visibility,
    public_notification: public_notification,
    sound: sound,
    priority: priority,
    collapse_key: collapse_key,
    time_to_live: time_to_live,
    delivery_priority: delivery_priority,
    delay_while_idle: delay_while_idle,
    local_only: local_only,
    wearable: wearable,
    interactive: interactive,
    live_update: live_update
  })
end

#content(title: nil, subtitle: nil, body: nil) ⇒ Object

iOS Content builder. Each argument describes the portions of the notification that should be modified if the media_attachment succeeds.



265
266
267
268
269
270
271
# File 'lib/urbanairship/push/payload.rb', line 265

def content(title: nil, subtitle: nil, body: nil)
  compact_helper({
    title: title,
    subtitle: subtitle,
    body: body
  })
end

#crop(x: nil, y: nil, width: nil, height: nil) ⇒ Object

iOS crop builder.



274
275
276
277
278
279
280
281
# File 'lib/urbanairship/push/payload.rb', line 274

def crop(x: nil, y: nil, width: nil, height: nil)
  compact_helper({
    x: x,
    y: y,
    width: width,
    height: height
  })
end

#device_types(types) ⇒ Object

Target specified device types



216
217
218
# File 'lib/urbanairship/push/payload.rb', line 216

def device_types(types)
  types
end

#email(bypass_opt_in_level: nil, html_body: nil, message_type: required('message_type'), plaintext_body: required('plaintext_body'), reply_to: required('reply_to'), sender_address: required('sender_address'), sender_name: required('sender_name'), subject: required('subject')) ⇒ Object

Email specific portion of Push Notification Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/urbanairship/push/payload.rb', line 189

def email(bypass_opt_in_level: nil, html_body: nil, message_type: required('message_type'),
          plaintext_body: required('plaintext_body'), reply_to: required('reply_to'),
          sender_address: required('sender_address'), sender_name: required('sender_name'),
          subject: required('subject'))
  fail ArgumentError, 'Message type must not be nil' if message_type.nil?
  fail ArgumentError, 'Plaintext Body must not be nil' if plaintext_body.nil?
  fail ArgumentError, 'Reply To must not be nil' if reply_to.nil?
  fail ArgumentError, 'Sender address must not be nil' if sender_address.nil?
  fail ArgumentError, 'Sender name must not be nil' if sender_name.nil?
  fail ArgumentError, 'Subject must not be nil' if subject.nil?
  compact_helper({
      bypass_opt_in_level: bypass_opt_in_level,
      html_body: html_body,
      message_type: message_type,
      plaintext_body: plaintext_body,
      reply_to: reply_to,
      sender_address: sender_address,
      sender_name: sender_name,
      subject: subject
    })
end

#in_app(alert: nil, display_type: nil, display: nil, expiry: nil, actions: nil, interactive: nil, extra: nil) ⇒ Object

In-app message specific portion of Push Notification Object



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/urbanairship/push/payload.rb', line 160

def in_app(alert: nil, display_type: nil, display: nil, expiry: nil,
           actions: nil, interactive: nil, extra: nil)
  compact_helper({
    alert: alert,
    display_type: display_type,
    display: display,
    expiry: expiry,
    actions: actions,
    interactive: interactive,
    extra: extra
  })
end

#interactive(type: required('type'), button_actions: nil) ⇒ Object

Interactive Notification portion of Push Notification Object



174
175
176
177
# File 'lib/urbanairship/push/payload.rb', line 174

def interactive(type: required('type'), button_actions: nil)
  fail ArgumentError, 'type must not be nil' if type.nil?
  compact_helper({ type: type, button_actions: button_actions })
end

#ios(alert: nil, badge: nil, sound: nil, content_available: nil, extra: nil, expiry: nil, priority: nil, category: nil, interactive: nil, mutable_content: nil, media_attachment: nil, title: nil, subtitle: nil, collapse_id: nil, thread_id: nil, live_activity: nil) ⇒ Object

iOS specific portion of Push Notification Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/urbanairship/push/payload.rb', line 34

def ios(alert: nil, badge: nil, sound: nil, content_available: nil,
        extra: nil, expiry: nil, priority: nil, category: nil,
        interactive: nil, mutable_content: nil, media_attachment: nil,
        title: nil, subtitle: nil, collapse_id: nil, thread_id: nil, live_activity: nil)
  compact_helper({
    alert: alert,
    badge: badge,
    sound: sound,
    'content-available' => content_available,
    extra: extra,
    expiry: expiry,
    priority: priority,
    category: category,
    interactive: interactive,
    'mutable-content' => mutable_content,
    media_attachment: media_attachment,
    title: title,
    subtitle: subtitle,
    collapse_id: collapse_id,
    thread_id: thread_id,
    live_activity: live_activity
  })
end

#live_activity(event: required('event'), alert: nil, name: required('name'), priority: nil, content_state: nil, relevance_score: nil, stale_date: nil, dismissal_date: nil, timestamp: nil) ⇒ Object

iOS Live Activity



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/urbanairship/push/payload.rb', line 319

def live_activity(
  event: required('event'), 
  alert: nil, 
  name: required('name'), 
  priority: nil, 
  content_state: nil, 
  relevance_score: nil, 
  stale_date: nil, 
  dismissal_date: nil, 
  timestamp: nil
)
  valid_events = ['update', 'end']
  fail ArgumentError, 'Invalid event type' unless valid_events.include?(event)
  fail ArgumentError, 'priority must be 5 or 10' if priority && ![5, 10].include?(priority)

  compact_helper({
    event: event,
    alert: alert,
    name: name,
    priority: priority,
    content_state: content_state,
    relevance_score: relevance_score,
    stale_date: stale_date,
    dismissal_date: dismissal_date,
    timestamp: timestamp
  })
end

#live_update(event: required('event'), name: required('name'), content_state: nil, type: nil, dismissal_date: nil, timestamp: nil) ⇒ Object

Android Live Update



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/urbanairship/push/payload.rb', line 348

def live_update(
  event: required('event'), 
  name: required('name'), 
  content_state: nil, 
  type: nil, 
  dismissal_date: nil, 
  timestamp: nil
)
  valid_events = ['start', 'update', 'end']
  fail ArgumentError, 'Invalid event type' unless valid_events.include?(event)

  compact_helper({
    event: event,
    name: name,
    content_state: content_state,
    type: type,
    dismissal_date: dismissal_date,
    timestamp: timestamp
  })
end

#media_attachment(url: required('url'), content: nil, options: nil) ⇒ Object

iOS Media Attachment builder



254
255
256
257
258
259
260
261
# File 'lib/urbanairship/push/payload.rb', line 254

def media_attachment(url: required('url'), content: nil, options: nil)
  fail ArgumentError, 'url must not be nil' if url.nil?
  compact_helper({
    url: url,
    content: content,
    options: options
  })
end

#message(title: required('title'), body: required('body'), content_type: nil, content_encoding: nil, extra: nil, expiry: nil, icons: nil, options: nil) ⇒ Object

Rich Message specific portion of Push Notification Object



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/urbanairship/push/payload.rb', line 145

def message(title: required('title'), body: required('body'), content_type: nil, content_encoding: nil,
            extra: nil, expiry: nil, icons: nil, options: nil)
  compact_helper({
    title: title,
    body: body,
    content_type: content_type,
    content_encoding: content_encoding,
    extra: extra,
    expiry: expiry,
    icons: icons,
    options: options
  })
end

#notification(alert: nil, ios: nil, android: nil, amazon: nil, web: nil, wns: nil, open_platforms: nil, actions: nil, interactive: nil, sms: nil, email: nil) ⇒ Object

Notification Object for a Push Payload



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/urbanairship/push/payload.rb', line 9

def notification(alert: nil, ios: nil, android: nil, amazon: nil,
                 web: nil, wns: nil, open_platforms: nil,
                 actions: nil, interactive: nil, sms: nil, email: nil)
  payload = compact_helper({
    alert: alert,
    ios: ios,
    android: android,
    amazon: amazon,
    web: web,
    wns: wns,
    actions: actions,
    interactive: interactive,
    sms: sms,
    email: email
  })
  if open_platforms
    open_platforms.each {|platform, overrides|
      payload[platform] = overrides
    }
  end
  fail ArgumentError, 'Notification body is empty' if payload.empty?
  payload
end

#open_platform(alert: nil, title: nil, summary: nil, extra: nil, media_attachment: nil, interactive: nil) ⇒ Object

Open Platform specific portion of Push Notification Object.



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/urbanairship/push/payload.rb', line 132

def open_platform(alert: nil, title: nil, summary: nil,
                  extra: nil, media_attachment: nil, interactive: nil)
  compact_helper({
    alert: alert,
    title: title,
    summary: summary,
    extra: extra,
    media_attachment: media_attachment,
    interactive: interactive
  })
end

#options(expiry: nil, bypass_frequency_limits: nil, bypass_holdout_groups: nil, no_throttle: nil, omit_from_activity_log: nil, personalization: nil, redact_payload: nil) ⇒ Object

Options for a message



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/urbanairship/push/payload.rb', line 221

def options(
    expiry: nil,
    bypass_frequency_limits: nil,
    bypass_holdout_groups: nil,
    no_throttle: nil,
    omit_from_activity_log: nil,
    personalization: nil,
    redact_payload: nil
)
  compact_helper(
    expiry: expiry,
    bypass_frequency_limits: bypass_frequency_limits,
    bypass_holdout_groups: bypass_holdout_groups,
    no_throttle: no_throttle,
    omit_from_activity_log: omit_from_activity_log,
    personalization: personalization,
    redact_payload: redact_payload
  )
end

#public_notification(title: nil, alert: nil, summary: nil) ⇒ Object

Android L public notification payload builder.



301
302
303
304
305
306
307
# File 'lib/urbanairship/push/payload.rb', line 301

def public_notification(title: nil, alert: nil, summary: nil)
  compact_helper({
    title: title,
    alert: alert,
    summary: summary
  })
end

#sms(alert: nil, expiry: nil) ⇒ Object

SMS specific portion of Push Notification Object



180
181
182
183
184
185
# File 'lib/urbanairship/push/payload.rb', line 180

def sms(alert: nil, expiry: nil)
  compact_helper({
    alert: alert,
    expiry: expiry
    })
end

#style(type: required('type'), content: required('content'), title: nil, summary: nil) ⇒ Object

Android/Amazon style builder.



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/urbanairship/push/payload.rb', line 284

def style(type: required('type'), content: required('content'),
          title: nil, summary: nil)
  fail ArgumentError, 'type must not be nil' if type.nil?

  mapping = {
    big_picture: 'big_picture', big_text: 'big_text', inbox: 'lines'
  }

  compact_helper({
    type: type,
    mapping[type.to_sym] => content,
    title: title,
    summary: summary
  })
end

#wearable(background_image: nil, extra_pages: nil, interactive: nil) ⇒ Object

Android wearable payload builder.



310
311
312
313
314
315
316
# File 'lib/urbanairship/push/payload.rb', line 310

def wearable(background_image: nil, extra_pages: nil, interactive: nil)
  compact_helper({
    background_image: background_image,
    extra_pages: extra_pages,
    interactive: interactive,
  })
end

#web(alert: nil, title: nil, extra: nil, require_interaction: nil, icon: nil) ⇒ Object

Web Notify specific portion of Push Notification Object



109
110
111
112
113
114
115
116
117
# File 'lib/urbanairship/push/payload.rb', line 109

def web(alert: nil, title: nil, extra: nil, require_interaction: nil, icon: nil)
  compact_helper({
    alert: alert,
    title: title,
    extra: extra,
    require_interaction: require_interaction,
    icon: icon
  })
end

#wns_payload(alert: nil, toast: nil, tile: nil, badge: nil) ⇒ Object

WNS specific portion of Push Notification Object



120
121
122
123
124
125
126
127
128
129
# File 'lib/urbanairship/push/payload.rb', line 120

def wns_payload(alert: nil, toast: nil, tile: nil, badge: nil)
  payload = compact_helper({
    alert: alert,
    toast: toast,
    tile: tile,
    badge: badge
  })
  fail ArgumentError, 'Must specify one message type' if payload.size != 1
  payload
end