forked from uniqush/uniqush-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restapi_response.go
83 lines (67 loc) · 3.31 KB
/
restapi_response.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
package main
// These are constants with codes for a uniqush response type.
// nolint: golint
const (
/* Not errors */
UNIQUSH_SUCCESS = "UNIQUSH_SUCCESS"
UNIQUSH_REMOVE_INVALID_REG = "UNIQUSH_REMOVE_INVALID_REG"
UNIQUSH_UPDATE_UNSUBSCRIBE = "UNIQUSH_UPDATE_UNSUBSCRIBE"
/* Errors */
UNIQUSH_ERROR_GENERIC = "UNIQUSH_ERROR_GENERIC"
UNIQUSH_ERROR_EMPTY_NOTIFICATION = "UNIQUSH_ERROR_EMPTY_NOTIFICATION"
UNIQUSH_ERROR_DATABASE = "UNIQUSH_ERROR_DATABASE"
UNIQUSH_ERROR_FAILED_RETRY = "UNIQUSH_ERROR_FAILED_RETRY"
UNIQUSH_ERROR_BUILD_PUSH_SERVICE_PROVIDER = "UNIQUSH_ERROR_BUILD_PUSH_SERVICE_PROVIDER"
UNIQUSH_ERROR_UPDATE_PUSH_SERVICE_PROVIDER = "UNIQUSH_ERROR_UPDATE_PUSH_SERVICE_PROVIDER"
UNIQUSH_ERROR_BAD_DELIVERY_POINT = "UNIQUSH_ERROR_BAD_DELIVERY_POINT"
UNIQUSH_ERROR_BUILD_DELIVERY_POINT = "UNIQUSH_ERROR_BUILD_DELIVERY_POINT"
UNIQUSH_ERROR_UPDATE_DELIVERY_POINT = "UNIQUSH_ERROR_UPDATE_DELIVERY_POINT"
UNIQUSH_ERROR_CANNOT_GET_SERVICE = "UNIQUSH_ERROR_CANNOT_GET_SERVICE"
UNIQUSH_ERROR_CANNOT_GET_SUBSCRIBER = "UNIQUSH_ERROR_CANNOT_GET_SUBSCRIBER"
UNIQUSH_ERROR_CANNOT_GET_DELIVERY_POINT_ID = "UNIQUSH_ERROR_CANNOT_GET_DELIVERY_POINT_ID"
UNIQUSH_ERROR_NO_DEVICE = "UNIQUSH_ERROR_NO_DEVICE"
UNIQUSH_ERROR_NO_DELIVERY_POINT = "UNIQUSH_ERROR_NO_DELIVERY_POINT"
UNIQUSH_ERROR_NO_PUSH_SERVICE_PROVIDER = "UNIQUSH_ERROR_NO_PUSH_SERVICE_PROVIDER"
UNIQUSH_ERROR_NO_SUBSCRIBER = "UNIQUSH_ERROR_NO_SUBSCRIBER"
UNIQUSH_ERROR_NO_PUSH_SERVICE_TYPE = "UNIQUSH_ERROR_NO_PUSH_SERVICE_TYPE"
)
// APIResponseDetails is used to represent responses of various APIs. Different APIs use different subsets of fields.
type APIResponseDetails struct {
RequestID *string `json:"requestId,omitempty"`
Service *string `json:"service,omitempty"`
From *string `json:"from,omitempty"`
Subscriber *string `json:"subscriber,omitempty"`
PushServiceProvider *string `json:"pushServiceProvider,omitempty"`
DeliveryPoint *string `json:"deliveryPoint,omitempty"`
MessageID *string `json:"messageId,omitempty"`
Code string `json:"code"`
ErrorMsg *string `json:"errorMsg,omitempty"`
ModifiedDp bool `json:"modifiedDp,omitempty"`
}
// PreviewAPIResponseDetails represents the response of /preview. It contains a representation of the payload that would be sent to external push services
type PreviewAPIResponseDetails struct {
Code string `json:"code"`
Payload interface{} `json:"payload,omitempty"`
ErrorMsg *string `json:"errorMsg,omitempty"`
}
func strPtrOfErr(e error) *string {
if e == nil {
return nil
}
s := e.Error()
return &s
}
// APIResponseHandler is interface for collecting API responses
type APIResponseHandler interface {
AddDetailsToHandler(v APIResponseDetails)
ToJSON() []byte
}
// NullAPIResponseHandler is an APIResponseHandler implementation that does nothing.
type NullAPIResponseHandler struct{}
var _ APIResponseHandler = &NullAPIResponseHandler{}
// AddDetailsToHandler does nothing for NullAPIResponseHandler
func (handler *NullAPIResponseHandler) AddDetailsToHandler(v APIResponseDetails) {}
// ToJSON returns an empty list for NullAPIResponseHandler
func (handler *NullAPIResponseHandler) ToJSON() []byte {
return []byte{}
}