diff --git a/response.go b/response.go index bf3f4cd1..efa51aef 100644 --- a/response.go +++ b/response.go @@ -6,13 +6,17 @@ import ( "time" ) +// StatusSent is a 200 response. const StatusSent = http.StatusOK + +// The possible Reason error codes returned from APNs. +// From table 6-6 in the Apple Local and Remote Notification Programming Guide. const ( ReasonPayloadEmpty = "PayloadEmpty" ReasonPayloadTooLarge = "PayloadTooLarge" ReasonBadTopic = "BadTopic" ReasonTopicDisallowed = "TopicDisallowed" - ReasonBadMessageId = "BadMessageId" + ReasonBadMessageID = "BadMessageId" ReasonBadExpirationDate = "BadExpirationDate" ReasonBadPriority = "BadPriority" ReasonMissingDeviceToken = "MissingDeviceToken" @@ -49,13 +53,34 @@ func (t *timestamp) UnmarshalJSON(b []byte) error { return nil } +// Response represents a result from the APNs gateway indicating whether a +// notification was accepted or rejected and (if applicable) the metadata +// surrounding the rejection. type Response struct { + + // The HTTP status code retuened by APNs. + // A 200 value indicates that the notification was succesfull sent. + // For a list of other possible status codes, see table 6-4 in the Apple Local + // and Remote Notification Programming Guide StatusCode int - Reason string - ApnsID string - Timestamp timestamp + + // The APNs error string indicating the reason for the notification failure (if + // any). The error code is specified as a string. For a list of possible + // values, see the Reason constants above. + // If the notification was accepted, this value will be "" + Reason string + + // The APNs ApnsID value from the Notification. If you didnt set an ApnsID on the + // Notification, this will be a new unique UUID whcih has been created by APNs. + ApnsID string + + // If the value of StatusCode is 410, this is the last time at which APNs + // confirmed that the device token was no longer valid for the topic. + Timestamp timestamp } +// Sent returns whether the notification was succesfull sent. +// This is the same as checking if the StatusCode == 200 func (c *Response) Sent() bool { return c.StatusCode == StatusSent }