forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPnMessage.java
More file actions
265 lines (236 loc) · 6.26 KB
/
Copy pathPnMessage.java
File metadata and controls
265 lines (236 loc) · 6.26 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package com.pubnub.api;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Pubnub Message Object
* @author Pubnub
*
*/
public class PnMessage extends JSONObject {
private String channel;
private Callback callback;
private Pubnub pubnub;
/**
* Constructor for Pubnub Message Class
* @param pubnub
* Pubnub object
* @param channel
* Channel name
* @param callback
* Callback object
*/
public PnMessage(Pubnub pubnub, String channel, Callback callback) {
super();
this.channel = channel;
this.callback = callback;
this.pubnub = pubnub;
}
/**
* Constructor for Pubnub Message Class
*/
public PnMessage() {
super();
}
/**
* Constructor for Pubnub Message Class
* @param apnsMsg
* Pubnub APNS message object
* @param gcmMsg
* Pubnub GCM message object
*/
public PnMessage(PnApnsMessage apnsMsg, PnGcmMessage gcmMsg) {
super();
try {
if (apnsMsg != null) {
this.put("pn_apns", apnsMsg);
}
if (gcmMsg != null) {
this.put("pn_gcm", gcmMsg);
}
} catch (JSONException e) {
}
}
/**
* Constructor for Pubnub Message Class
* @param pubnub
* Pubnub object
* @param callback
* Callback object
* @param apnsMsg
* Pubnub APNS message object
* @param gcmMsg
* Pubnub GCM message object
*/
public PnMessage(Pubnub pubnub, String channel, Callback callback, PnApnsMessage apnsMsg, PnGcmMessage gcmMsg) {
super();
this.channel = channel;
this.callback = callback;
this.pubnub = pubnub;
try {
if (apnsMsg != null) {
this.put("pn_apns", apnsMsg);
}
if (gcmMsg != null) {
this.put("pn_gcm", gcmMsg);
}
} catch (JSONException e) {
}
}
/**
* Getter for channel set on PnMessage Object
* @return channel
*/
public String getChannel() {
return channel;
}
/**
* Setter for channel on PnMessage Object
* @param channel
* Channel name
*/
public void setChannel(String channel) {
this.channel = channel;
}
/**
* Getter for callback set on PnMessage object
* @return callback
*
*/
public Callback getCallback() {
return callback;
}
/**
* Setter for callback on PnMessage object
* @param callback
* Callback
*/
public void setCallback(Callback callback) {
this.callback = callback;
}
/**
* Getter for pubnub set on PnMessage object
* @return pubnub
*/
public Pubnub getPubnub() {
return pubnub;
}
/**
* Setter for pubnub on PnMessage object
* @param pubnub
* Pubnub object
*/
public void setPubnub(Pubnub pubnub) {
this.pubnub = pubnub;
}
/**
* Constructor for Pubnub Message Class
* @param gcmMsg
* Pubnub GCM message object
*/
public PnMessage(PnGcmMessage gcmMsg) {
super();
try {
if (gcmMsg != null) {
this.put("pn_gcm", gcmMsg);
}
} catch (JSONException e) {
}
}
/**
* Constructor for Pubnub Message Class
* @param pubnub
* Pubnub
* @param channel
* Channel
* @param callback
* Callback object
* @param gcmMsg
* Pubnub GCM message object
*/
public PnMessage(Pubnub pubnub, String channel, Callback callback, PnGcmMessage gcmMsg) {
super();
this.channel = channel;
this.callback = callback;
this.pubnub = pubnub;
try {
if (gcmMsg != null) {
this.put("pn_gcm", gcmMsg);
}
} catch (JSONException e) {
}
}
/**
* Constructor for Pubnub Message Class
* @param apnsMsg
* Pubnub APNS message object
*/
public PnMessage(PnApnsMessage apnsMsg) {
super();
try {
if (apnsMsg != null) {
this.put("pn_apns", apnsMsg);
}
} catch (JSONException e) {
}
}
/**
* Constructor for Pubnub Message Class
* @param pubnub
* Pubnub
* @param channel
* Channel
* @param callback
* Callback object
* @param apnsMsg
* Pubnub APNS message object
*/
public PnMessage(Pubnub pubnub, String channel, Callback callback, PnApnsMessage apnsMsg) {
super();
this.channel = channel;
this.callback = callback;
this.pubnub = pubnub;
try {
if (apnsMsg != null) {
this.put("pn_apns", apnsMsg);
}
} catch (JSONException e) {
}
}
/**
* Publish Message
* @param pubnub
* Pubnub object
* @param channel
* Channel
* @param callback
* Callback object
* @throws PubnubException
* Exception if either channel or pubnub object is not set
*/
public void publish(Pubnub pubnub, String channel, Callback callback) throws PubnubException {
this.channel = channel;
this.callback = callback;
this.pubnub = pubnub;
if (this.channel == null) {
throw new PubnubException(PubnubError.PNERROBJ_CHANNEL_MISSING);
}
if (this.pubnub == null) {
throw new PubnubException(PubnubError.PNERROBJ_CONNECTION_NOT_SET);
}
pubnub.publish(channel, this, callback);
}
/**
* Publish Message
* @throws PubnubException
* Exception if either channel or pubnub object is not set
*/
public void publish() throws PubnubException {
if (this.channel == null) {
throw new PubnubException(PubnubError.PNERROBJ_CHANNEL_MISSING);
}
if (this.pubnub == null) {
throw new PubnubException(PubnubError.PNERROBJ_CONNECTION_NOT_SET);
}
pubnub.publish(channel, this, callback);
}
}