@@ -4,7 +4,9 @@ package payload
4
4
5
5
import "encoding/json"
6
6
7
- type payload struct {
7
+ // Payload represents a notification which holds the content that will be
8
+ // marshalled as JSON.
9
+ type Payload struct {
8
10
content map [string ]interface {}
9
11
}
10
12
@@ -29,189 +31,208 @@ type alert struct {
29
31
TitleLocKey string `json:"title-loc-key,omitempty"`
30
32
}
31
33
32
- // NewPayload represents a notification payload.
33
- func NewPayload () * payload {
34
- return & payload {
34
+ // NewPayload returns a new Payload struct
35
+ func NewPayload () * Payload {
36
+ return & Payload {
35
37
map [string ]interface {}{
36
38
"aps" : & aps {},
37
39
},
38
40
}
39
41
}
40
42
41
- // Sets the aps alert on the payload.
42
- // This will display a notification alert message to the user.
43
- // {"aps":{"alert":alert}}
44
- func (p * payload ) Alert (alert interface {}) * payload {
43
+ // Alert sets the aps alert on the payload.
44
+ // This will display a notification alert message to the <b>user.</b>
45
+ //
46
+ // {"aps":{"alert":alert}}`
47
+ func (p * Payload ) Alert (alert interface {}) * Payload {
45
48
p .aps ().Alert = alert
46
49
return p
47
50
}
48
51
49
- // Sets the aps badge on the payload.
52
+ // Badge sets the aps badge on the payload.
50
53
// This will display a numeric badge on the app icon.
51
- // {"aps":{"badge":b}}
52
- func (p * payload ) Badge (b int ) * payload {
54
+ //
55
+ // {"aps":{"badge":b}}
56
+ func (p * Payload ) Badge (b int ) * Payload {
53
57
p .aps ().Badge = b
54
58
return p
55
59
}
56
60
57
- // Sets the aps badge on the payload to 0.
61
+ // ZeroBadge sets the aps badge on the payload to 0.
58
62
// This will clear the badge on the app icon.
59
- // {"aps":{"badge":0}}
60
- func (p * payload ) ZeroBadge () * payload {
63
+ //
64
+ // {"aps":{"badge":0}}
65
+ func (p * Payload ) ZeroBadge () * Payload {
61
66
p .aps ().Badge = 0
62
67
return p
63
68
}
64
69
65
- // Removes the badge attribute from the payload.
70
+ // UnsetBadge removes the badge attribute from the payload.
66
71
// This will leave the badge on the app icon unchanged.
67
72
// If you wish to clear the app icon badge, use ZeroBadge() instead.
68
- // {"aps":{}}
69
- func (p * payload ) UnsetBadge () * payload {
73
+ //
74
+ // {"aps":{}}
75
+ func (p * Payload ) UnsetBadge () * Payload {
70
76
p .aps ().Badge = nil
71
77
return p
72
78
}
73
79
74
- // Sets the aps sound on the payload.
80
+ // Sound sets the aps sound on the payload.
75
81
// This will play a sound from the app bundle, or the default sound otherwise.
76
- // {"aps":{"sound":sound}}
77
- func (p * payload ) Sound (sound string ) * payload {
82
+ //
83
+ // {"aps":{"sound":sound}}
84
+ func (p * Payload ) Sound (sound string ) * Payload {
78
85
p .aps ().Sound = sound
79
86
return p
80
87
}
81
88
82
- // Sets the aps content-available on the payload to 1.
89
+ // ContentAvailable sets the aps content-available on the payload to 1.
83
90
// This will indicate to the app that there is new content available to download
84
91
// and launch the app in the background.
85
- // {"aps":{"content-available":1}}
86
- func (p * payload ) ContentAvailable () * payload {
92
+ //
93
+ // {"aps":{"content-available":1}}
94
+ func (p * Payload ) ContentAvailable () * Payload {
87
95
p .aps ().ContentAvailable = 1
88
96
return p
89
97
}
90
98
91
99
// Custom payload
92
100
93
- // Sets a custom key and value on the payload.
101
+ // Custom sets a custom key and value on the payload.
94
102
// This will add custom key/value data to the notification payload at root level.
95
- // {"aps":{}, key:value}
96
- func (p * payload ) Custom (key string , val interface {}) * payload {
103
+ //
104
+ // {"aps":{}, key:value}
105
+ func (p * Payload ) Custom (key string , val interface {}) * Payload {
97
106
p .content [key ] = val
98
107
return p
99
108
}
100
109
101
110
// Alert dictionary
102
111
103
- // Sets the aps alert title on the payload.
112
+ // AlertTitle sets the aps alert title on the payload.
104
113
// This will display a short string describing the purpose of the notification.
105
114
// Apple Watch & Safari display this string as part of the notification interface.
106
- // {"aps":{"alert":"title"}}
107
- func (p * payload ) AlertTitle (title string ) * payload {
115
+ //
116
+ // {"aps":{"alert":"title"}}
117
+ func (p * Payload ) AlertTitle (title string ) * Payload {
108
118
p .aps ().alert ().Title = title
109
119
return p
110
120
}
111
121
112
- // Sets the aps alert title localization key on the payload.
122
+ // AlertTitleLocKey sets the aps alert title localization key on the payload.
113
123
// This is the key to a title string in the Localizable.strings file for the
114
124
// current localization. See Localized Formatted Strings in Apple documentation
115
125
// for more information.
116
- // {"aps":{"alert":{"title-loc-key":key}}}
117
- func (p * payload ) AlertTitleLocKey (key string ) * payload {
126
+ //
127
+ // {"aps":{"alert":{"title-loc-key":key}}}
128
+ func (p * Payload ) AlertTitleLocKey (key string ) * Payload {
118
129
p .aps ().alert ().TitleLocKey = key
119
130
return p
120
131
}
121
132
122
- // Sets the aps alert title localization args on the payload.
133
+ // AlertTitleLocArgs sets the aps alert title localization args on the payload.
123
134
// These are the variable string values to appear in place of the format
124
135
// specifiers in title-loc-key. See Localized Formatted Strings in Apple
125
136
// documentation for more information.
126
- // {"aps":{"alert":{"title-loc-args":args}}}
127
- func (p * payload ) AlertTitleLocArgs (args []string ) * payload {
137
+ //
138
+ // {"aps":{"alert":{"title-loc-args":args}}}
139
+ func (p * Payload ) AlertTitleLocArgs (args []string ) * Payload {
128
140
p .aps ().alert ().TitleLocArgs = args
129
141
return p
130
142
}
131
143
132
- // Sets the aps alert body on the payload.
144
+ // AlertBody sets the aps alert body on the payload.
133
145
// This is the text of the alert message.
134
- // {"aps":{"alert":{"body":body}}}
135
- func (p * payload ) AlertBody (body string ) * payload {
146
+ //
147
+ // {"aps":{"alert":{"body":body}}}
148
+ func (p * Payload ) AlertBody (body string ) * Payload {
136
149
p .aps ().alert ().Body = body
137
150
return p
138
151
}
139
152
140
- // Sets the aps launch image on the payload.
153
+ // AlertLaunchImage sets the aps launch image on the payload.
141
154
// This is the filename of an image file in the app bundle. The image is used
142
155
// as the launch image when users tap the action button or move the action
143
156
// slider.
144
- // {"aps":{"alert":{"launch-image":image}}}
145
- func (p * payload ) AlertLaunchImage (image string ) * payload {
157
+ //
158
+ // {"aps":{"alert":{"launch-image":image}}}
159
+ func (p * Payload ) AlertLaunchImage (image string ) * Payload {
146
160
p .aps ().alert ().LaunchImage = image
147
161
return p
148
162
}
149
163
150
- // Sets the aps alert localization key on the payload.
164
+ // AlertLocKey sets the aps alert localization key on the payload.
151
165
// This is the key to an alert-message string in the Localizable.strings file
152
166
// for the current localization. See Localized Formatted Strings in Apple
153
167
// documentation for more information.
154
- // {"aps":{"alert":{"loc-key":key}}}
155
- func (p * payload ) AlertLocKey (key string ) * payload {
168
+ //
169
+ // {"aps":{"alert":{"loc-key":key}}}
170
+ func (p * Payload ) AlertLocKey (key string ) * Payload {
156
171
p .aps ().alert ().LocKey = key
157
172
return p
158
173
}
159
174
160
- // Sets the aps alert action on the payload.
175
+ // AlertAction sets the aps alert action on the payload.
161
176
// This is the label of the action button, if the user sets the notifications
162
177
// to appear as alerts. This label should be succinct, such as “Details” or
163
178
// “Read more”. If omitted, the default value is “Show”.
164
- // {"aps":{"alert":{"action":action}}}
165
- func (p * payload ) AlertAction (action string ) * payload {
179
+ //
180
+ // {"aps":{"alert":{"action":action}}}
181
+ func (p * Payload ) AlertAction (action string ) * Payload {
166
182
p .aps ().alert ().Action = action
167
183
return p
168
184
}
169
185
170
- // Sets the aps alert action localization key on the payload.
186
+ // AlertActionLocKey sets the aps alert action localization key on the payload.
171
187
// This is the the string used as a key to get a localized string in the current
172
188
// localization to use for the notfication right button’s title instead of
173
189
// “View”. See Localized Formatted Strings in Apple documentation for more
174
190
// information.
175
- // {"aps":{"alert":{"action-loc-key":key}}}
176
- func (p * payload ) AlertActionLocKey (key string ) * payload {
191
+ //
192
+ // {"aps":{"alert":{"action-loc-key":key}}}
193
+ func (p * Payload ) AlertActionLocKey (key string ) * Payload {
177
194
p .aps ().alert ().ActionLocKey = key
178
195
return p
179
196
}
180
197
181
198
// General
182
199
183
- // Sets the aps category on the payload.
200
+ // Category sets the aps category on the payload.
184
201
// This is a string value that represents the identifier property of the
185
202
// UIMutableUserNotificationCategory object you created to define custom actions.
186
- // {"aps":{"alert":{"category":category}}}
187
- func (p * payload ) Category (category string ) * payload {
203
+ //
204
+ // {"aps":{"alert":{"category":category}}}
205
+ func (p * Payload ) Category (category string ) * Payload {
188
206
p .aps ().Category = category
189
207
return p
190
208
}
191
209
192
- // Sets the mdm on the payload.
210
+ // Mdm sets the mdm on the payload.
193
211
// This is for Apple Mobile Device Management (mdm) payloads.
194
- // {"aps":{}:"mdm":mdm}
195
- func (p * payload ) Mdm (mdm string ) * payload {
212
+ //
213
+ // {"aps":{}:"mdm":mdm}
214
+ func (p * Payload ) Mdm (mdm string ) * Payload {
196
215
p .content ["mdm" ] = mdm
197
216
return p
198
217
}
199
218
200
- // Sets the aps category on the payload.
219
+ // URLArgs sets the aps category on the payload.
201
220
// This specifies an array of values that are paired with the placeholders
202
221
// inside the urlFormatString value of your website.json file.
203
222
// See Apple Notification Programming Guide for Websites.
204
- // {"aps":{"url-args":urlArgs}}
205
- func (p * payload ) URLArgs (urlArgs []string ) * payload {
223
+ //
224
+ // {"aps":{"url-args":urlArgs}}
225
+ func (p * Payload ) URLArgs (urlArgs []string ) * Payload {
206
226
p .aps ().URLArgs = urlArgs
207
227
return p
208
228
}
209
229
210
- func (p * payload ) MarshalJSON () ([]byte , error ) {
230
+ // MarshalJSON returns the JSON encoded version of the Payload
231
+ func (p * Payload ) MarshalJSON () ([]byte , error ) {
211
232
return json .Marshal (p .content )
212
233
}
213
234
214
- func (p * payload ) aps () * aps {
235
+ func (p * Payload ) aps () * aps {
215
236
return p .content ["aps" ].(* aps )
216
237
}
217
238
0 commit comments