Skip to content

Commit

Permalink
Add documentation for Response
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshow committed Jan 17, 2016
1 parent cd65437 commit d3c92b1
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit d3c92b1

Please sign in to comment.