-
Notifications
You must be signed in to change notification settings - Fork 117
/
payload.rb
127 lines (115 loc) · 3.79 KB
/
payload.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module Urbanairship
module Push
module Payload
require 'urbanairship/common'
include Urbanairship::Common
# Notification Object for a Push Payload
def notification(alert: nil, ios: nil, android: nil, amazon: nil,
wns: nil, mpns: nil, actions: nil, interactive: nil)
payload = compact_helper({
alert: alert,
actions: actions,
ios: ios,
android: android,
amazon: amazon,
wns: wns,
mpns: mpns,
interactive: interactive
})
fail ArgumentError, 'Notification body is empty' if payload.empty?
payload
end
# iOS specific portion of Push Notification Object
def ios(alert: nil, badge: nil, sound: nil, extra: nil, expiry: nil,
category: nil, interactive: nil, content_available: nil)
compact_helper({
alert: alert,
badge: badge,
sound: sound,
extra: extra,
expiry: expiry,
category: category,
interactive: interactive,
'content-available' => content_available
})
end
# Amazon specific portion of Push Notification Object
def amazon(alert: nil, consolidation_key: nil, expires_after: nil,
extra: nil, title: nil, summary: nil, interactive: nil)
compact_helper({
alert: alert,
consolidation_key: consolidation_key,
expires_after: expires_after,
extra: extra,
title: title,
summary: summary,
interactive: interactive
})
end
# Android specific portion of Push Notification Object
def android(alert: nil, collapse_key: nil, time_to_live: nil,
extra: nil, delay_while_idle: nil, interactive: nil)
compact_helper({
alert: alert,
collapse_key: collapse_key,
time_to_live: time_to_live,
extra: extra,
delay_while_idle: delay_while_idle,
interactive: interactive
})
end
# WNS specific portion of Push Notification Object
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
# Rich Message specific portion of Push Notification Object
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
# Interactive Notification portion of Push Notification Object
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
def all
'all'
end
# Target specified device types
def device_types(types)
types
end
# Expiry for a Rich Message
def options(expiry: required('expiry'))
{ expiry: expiry }
end
# Actions for a Push Notification Object
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
end
end
end