forked from pubnub/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.go
492 lines (420 loc) · 16.1 KB
/
enums.go
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
package pubnub
import (
"fmt"
"reflect"
)
// StatusCategory is used as an enum to catgorize the various status events
// in the APIs lifecycle
type StatusCategory int
// OperationType is used as an enum to catgorize the various operations
// in the APIs lifecycle
type OperationType int
// ReconnectionPolicy is used as an enum to catgorize the reconnection policies
type ReconnectionPolicy int
// PNPushType is used as an enum to catgorize the available Push Types
type PNPushType int
// PNUserSpaceInclude is used as an enum to catgorize the available User and Space include types
type PNUserSpaceInclude int
// PNMembershipsInclude is used as an enum to catgorize the available Memberships include types
type PNMembershipsInclude int
// PNMembersInclude is used as an enum to catgorize the available Members include types
type PNMembersInclude int
// PNObjectsEvent is used as an enum to catgorize the available Object Events
type PNObjectsEvent string
// PNObjectsEventType is used as an enum to catgorize the available Object Event types
type PNObjectsEventType string
// PNMessageActionsEventType is used as an enum to catgorize the available Message Actions Event types
type PNMessageActionsEventType string
const (
// PNMessageActionsAdded is the enum when the event of type `added` occurs
PNMessageActionsAdded PNMessageActionsEventType = "added"
// PNMessageActionsRemoved is the enum when the event of type `removed` occurs
PNMessageActionsRemoved = "removed"
)
const (
// PNObjectsUserEvent is the enum when the event of type `user` occurs
PNObjectsUserEvent PNObjectsEventType = "user"
// PNObjectsSpaceEvent is the enum when the event of type `space` occurs
PNObjectsSpaceEvent = "space"
// PNObjectsMembershipEvent is the enum when the event of type `membership` occurs
PNObjectsMembershipEvent = "membership"
// PNObjectsNoneEvent is used for error handling
PNObjectsNoneEvent = "none"
)
const (
// PNObjectsEventCreate is the enum when the event `create` occurs
PNObjectsEventCreate PNObjectsEvent = "create"
// PNObjectsEventUpdate is the enum when the event `update` occurs
PNObjectsEventUpdate = "update"
// PNObjectsEventDelete is the enum when the event `delete` occurs
PNObjectsEventDelete = "delete"
)
const (
// PNUserSpaceCustom is the enum equivalent to the value `custom` available User and Space include types
PNUserSpaceCustom PNUserSpaceInclude = 1 + iota
)
func (s PNUserSpaceInclude) String() string {
return [...]string{"custom"}[s-1]
}
const (
// PNMembershipsCustom is the enum equivalent to the value `custom` available Memberships include types
PNMembershipsCustom PNMembershipsInclude = 1 + iota
// PNMembershipsSpace is the enum equivalent to the value `space` available Memberships include types
PNMembershipsSpace
// PNMembershipsSpaceCustom is the enum equivalent to the value `space.custom` available Memberships include types
PNMembershipsSpaceCustom
)
func (s PNMembershipsInclude) String() string {
return [...]string{"custom", "space", "space.custom"}[s-1]
}
const (
// PNMembersCustom is the enum equivalent to the value `custom` available Members include types
PNMembersCustom PNMembersInclude = 1 + iota
// PNMembersUser is the enum equivalent to the value `user` available Members include types
PNMembersUser
// PNMembersUserCustom is the enum equivalent to the value `user.custom` available Members include types
PNMembersUserCustom
)
func (s PNMembersInclude) String() string {
return [...]string{"custom", "user", "user.custom"}[s-1]
}
// PNMessageType is used as an enum to catgorize the Subscribe response.
type PNMessageType int
const (
// PNNonePolicy is to be used when selecting the no Reconnection Policy
// ReconnectionPolicy is set in the config.
PNNonePolicy ReconnectionPolicy = 1 + iota
// PNLinearPolicy is to be used when selecting the Linear Reconnection Policy
// ReconnectionPolicy is set in the config.
PNLinearPolicy
// PNExponentialPolicy is to be used when selecting the Exponential Reconnection Policy
// ReconnectionPolicy is set in the config.
PNExponentialPolicy
)
const (
// PNMessageTypeSignal is to identify Signal the Subscribe response
PNMessageTypeSignal PNMessageType = 1 + iota
// PNMessageTypeObjects is to identify Objects the Subscribe response
PNMessageTypeObjects
// PNMessageTypeMessageActions is to identify Actions the Subscribe response
PNMessageTypeMessageActions
)
const (
// PNUnknownCategory as the StatusCategory means an unknown status category event occurred.
PNUnknownCategory StatusCategory = 1 + iota
// PNTimeoutCategory as the StatusCategory means the request timeout has reached.
PNTimeoutCategory
// PNConnectedCategory as the StatusCategory means the channel is subscribed to receive messages.
PNConnectedCategory
// PNDisconnectedCategory as the StatusCategory means a disconnection occurred due to network issues.
PNDisconnectedCategory
// PNCancelledCategory as the StatusCategory means the context was cancelled.
PNCancelledCategory
// PNLoopStopCategory as the StatusCategory means the subscribe loop was stopped.
PNLoopStopCategory
// PNAcknowledgmentCategory as the StatusCategory is the Acknowledgement of an operation (like Unsubscribe).
PNAcknowledgmentCategory
// PNBadRequestCategory as the StatusCategory means the request was malformed.
PNBadRequestCategory
// PNAccessDeniedCategory as the StatusCategory means that PAM is enabled and the channel is not granted R/W access.
PNAccessDeniedCategory
// PNNoStubMatchedCategory as the StatusCategory means an unknown status category event occurred.
PNNoStubMatchedCategory
// PNReconnectedCategory as the StatusCategory means that the network was reconnected (after a disconnection).
// Applicable on for PNLinearPolicy and PNExponentialPolicy.
PNReconnectedCategory
// PNReconnectionAttemptsExhausted as the StatusCategory means that the reconnection attempts
// to reconnect to the network were exhausted. All channels would be unsubscribed at this point.
// Applicable on for PNLinearPolicy and PNExponentialPolicy.
// Reconnection attempts are set in the config: MaximumReconnectionRetries.
PNReconnectionAttemptsExhausted
// PNRequestMessageCountExceededCategory is fired when the MessageQueueOverflowCount limit is exceeded by the number of messages received in a single subscribe request
PNRequestMessageCountExceededCategory
)
const (
// PNSubscribeOperation is the enum used for the Subcribe operation.
PNSubscribeOperation OperationType = 1 + iota
// PNUnsubscribeOperation is the enum used for the Unsubcribe operation.
PNUnsubscribeOperation
// PNPublishOperation is the enum used for the Publish operation.
PNPublishOperation
// PNFireOperation is the enum used for the Fire operation.
PNFireOperation
// PNHistoryOperation is the enum used for the History operation.
PNHistoryOperation
// PNFetchMessagesOperation is the enum used for the Fetch operation.
PNFetchMessagesOperation
// PNWhereNowOperation is the enum used for the Where Now operation.
PNWhereNowOperation
// PNHereNowOperation is the enum used for the Here Now operation.
PNHereNowOperation
// PNHeartBeatOperation is the enum used for the Heartbeat operation.
PNHeartBeatOperation
// PNSetStateOperation is the enum used for the Set State operation.
PNSetStateOperation
// PNGetStateOperation is the enum used for the Get State operation.
PNGetStateOperation
// PNAddChannelsToChannelGroupOperation is the enum used for the Add Channels to Channel Group operation.
PNAddChannelsToChannelGroupOperation
// PNRemoveChannelFromChannelGroupOperation is the enum used for the Remove Channels from Channel Group operation.
PNRemoveChannelFromChannelGroupOperation
// PNRemoveGroupOperation is the enum used for the Remove Channel Group operation.
PNRemoveGroupOperation
// PNChannelsForGroupOperation is the enum used for the List Channels of Channel Group operation.
PNChannelsForGroupOperation
// PNPushNotificationsEnabledChannelsOperation is the enum used for the List Channels with Push Notifications enabled operation.
PNPushNotificationsEnabledChannelsOperation
// PNAddPushNotificationsOnChannelsOperation is the enum used for the Add Channels to Push Notifications operation.
PNAddPushNotificationsOnChannelsOperation
// PNRemovePushNotificationsFromChannelsOperation is the enum used for the Remove Channels from Push Notifications operation.
PNRemovePushNotificationsFromChannelsOperation
// PNRemoveAllPushNotificationsOperation is the enum used for the Remove All Channels from Push Notifications operation.
PNRemoveAllPushNotificationsOperation
// PNTimeOperation is the enum used for the Time operation.
PNTimeOperation
// PNAccessManagerGrant is the enum used for the Access Manager Grant operation.
PNAccessManagerGrant
// PNAccessManagerRevoke is the enum used for the Access Manager Revoke operation.
PNAccessManagerRevoke
// PNDeleteMessagesOperation is the enum used for the Delete Messages from History operation.
PNDeleteMessagesOperation
// PNMessageCountsOperation is the enum used for History with messages operation.
PNMessageCountsOperation
// PNSignalOperation is the enum used for Signal opertaion.
PNSignalOperation
// PNCreateUserOperation is the enum used to create users in the Object API.
// ENUM ORDER needs to be maintained for Objects AIP
PNCreateUserOperation
// PNGetUsersOperation is the enum used to get users in the Object API.
PNGetUsersOperation
// PNGetUserOperation is the enum used to get user in the Object API.
PNGetUserOperation
// PNUpdateUserOperation is the enum used to update users in the Object API.
PNUpdateUserOperation
// PNDeleteUserOperation is the enum used to delete users in the Object API.
PNDeleteUserOperation
// PNGetSpaceOperation is the enum used to get space in the Object API.
PNGetSpaceOperation
// PNGetSpacesOperation is the enum used to get spaces in the Object API.
PNGetSpacesOperation
// PNCreateSpaceOperation is the enum used to create space in the Object API.
PNCreateSpaceOperation
// PNDeleteSpaceOperation is the enum used to delete space in the Object API.
PNDeleteSpaceOperation
// PNUpdateSpaceOperation is the enum used to update space in the Object API.
PNUpdateSpaceOperation
// PNGetMembershipsOperation is the enum used to get memberships in the Object API.
PNGetMembershipsOperation
// PNGetMembersOperation is the enum used to get members in the Object API.
PNGetMembersOperation
// PNManageMembershipsOperation is the enum used to manage memberships in the Object API.
PNManageMembershipsOperation
// PNManageMembersOperation is the enum used to manage members in the Object API.
// ENUM ORDER needs to be maintained for Objects API.
PNManageMembersOperation
// PNAccessManagerGrantToken is the enum used for Grant v3 requests.
PNAccessManagerGrantToken
// PNGetMessageActionsOperation is the enum used for Message Actions Get requests.
PNGetMessageActionsOperation
// PNHistoryWithActionsOperation is the enum used for History with Actions requests.
PNHistoryWithActionsOperation
// PNAddMessageActionsOperation is the enum used for Message Actions Add requests.
PNAddMessageActionsOperation
// PNRemoveMessageActionsOperation is the enum used for Message Actions Remove requests.
PNRemoveMessageActionsOperation
)
const (
// PNPushTypeNone is used as an enum to for selecting `none` as the PNPushType
PNPushTypeNone PNPushType = 1 + iota
// PNPushTypeGCM is used as an enum to for selecting `GCM` as the PNPushType
PNPushTypeGCM
// PNPushTypeAPNS is used as an enum to for selecting `APNS` as the PNPushType
PNPushTypeAPNS
// PNPushTypeMPNS is used as an enum to for selecting `MPNS` as the PNPushType
PNPushTypeMPNS
)
func (p PNPushType) String() string {
switch p {
case PNPushTypeAPNS:
return "apns"
case PNPushTypeGCM:
return "gcm"
case PNPushTypeMPNS:
return "mpns"
default:
return "none"
}
}
var operations = [...]string{
"Subscribe",
"Unsubscribe",
"Publish",
"History",
"Fetch Messages",
"Where Now",
"Here Now",
"Heartbeat",
"Set State",
"Get State",
"Add Channel To Channel Group",
"Remove Channel From Channel Group",
"Remove Channel Group",
"List Channels In Channel Group",
"List Push Enabled Channels",
"Add Push From Channel",
"Remove Push From Channel",
"Remove All Push Notifications",
"Time",
"Grant",
"Revoke",
"Delete messages",
"Signal",
"Create User",
"Get Users",
"Fetch User",
"Update User",
"Delete User",
"Get Space",
"Get Spaces",
"Create Space",
"Delete Space",
"Update Space",
"PNGetMembershipsOperation",
"PNGetMembersOperation",
"PNManageMembershipsOperation",
"PNManageMembersOperation",
"GrantToken",
}
func (c StatusCategory) String() string {
switch c {
case PNUnknownCategory:
return "Unknown"
case PNTimeoutCategory:
return "Timeout"
case PNConnectedCategory:
return "Connected"
case PNDisconnectedCategory:
return "Disconnected"
case PNCancelledCategory:
return "Cancelled"
case PNLoopStopCategory:
return "Loop Stop"
case PNAcknowledgmentCategory:
return "Acknowledgment"
case PNBadRequestCategory:
return "Bad Request"
case PNAccessDeniedCategory:
return "Access Denied"
case PNReconnectedCategory:
return "Reconnected"
case PNReconnectionAttemptsExhausted:
return "Reconnection Attempts Exhausted"
case PNNoStubMatchedCategory:
return "No Stub Matched"
default:
return "No Stub Matched"
}
}
func (t OperationType) String() string {
switch t {
case PNSubscribeOperation:
return "Subscribe"
case PNUnsubscribeOperation:
return "Unsubscribe"
case PNPublishOperation:
return "Publish"
case PNFireOperation:
return "Fire"
case PNHistoryOperation:
return "History"
case PNFetchMessagesOperation:
return "Fetch Messages"
case PNWhereNowOperation:
return "Where Now"
case PNHereNowOperation:
return "Here Now"
case PNHeartBeatOperation:
return "Heartbeat"
case PNSetStateOperation:
return "Set State"
case PNGetStateOperation:
return "Get State"
case PNAddChannelsToChannelGroupOperation:
return "Add Channel To Channel Group"
case PNRemoveChannelFromChannelGroupOperation:
return "Remove Channel From Channel Group"
case PNRemoveGroupOperation:
return "Remove Channel Group"
case PNChannelsForGroupOperation:
return "List Channels In Channel Group"
case PNPushNotificationsEnabledChannelsOperation:
return "List Push Enabled Channels"
case PNAddPushNotificationsOnChannelsOperation:
return "Add Push From Channel"
case PNRemovePushNotificationsFromChannelsOperation:
return "Remove Push From Channel"
case PNRemoveAllPushNotificationsOperation:
return "Remove All Push Notifications"
case PNTimeOperation:
return "Time"
case PNAccessManagerGrant:
return "Grant"
case PNAccessManagerRevoke:
return "Revoke"
case PNDeleteMessagesOperation:
return "Delete messages"
case PNSignalOperation:
return "Signal"
case PNCreateUserOperation:
return "Create User"
case PNGetUsersOperation:
return "Get Users"
case PNGetUserOperation:
return "Fetch Users"
case PNUpdateUserOperation:
return "Update User"
case PNDeleteUserOperation:
return "Delete User"
case PNGetSpaceOperation:
return "Get Space"
case PNGetSpacesOperation:
return "Get Spaces"
case PNCreateSpaceOperation:
return "Create Space"
case PNDeleteSpaceOperation:
return "Delete Space"
case PNUpdateSpaceOperation:
return "Update Space"
case PNGetMembershipsOperation:
return "Get Memberships"
case PNGetMembersOperation:
return "Get Members"
case PNManageMembershipsOperation:
return "Manage Memberships"
case PNManageMembersOperation:
return "Manage Members"
case PNAccessManagerGrantToken:
return "Grant Token"
default:
return "No Category Matched"
}
}
// EnumArrayToStringArray converts a string enum to an array
func EnumArrayToStringArray(include interface{}) []string {
s := []string{}
switch fmt.Sprintf("%s", reflect.TypeOf(include)) {
case "[]pubnub.PNMembersInclude":
for _, v := range include.([]PNMembersInclude) {
s = append(s, fmt.Sprintf("%s", v))
}
case "[]pubnub.PNMembershipsInclude":
for _, v := range include.([]PNMembershipsInclude) {
s = append(s, fmt.Sprintf("%s", v))
}
case "[]pubnub.PNUserSpaceInclude":
for _, v := range include.([]PNUserSpaceInclude) {
s = append(s, fmt.Sprintf("%s", v))
}
}
return s
}