Skip to content

Commit

Permalink
Feature/add missing fields (#231)
Browse files Browse the repository at this point in the history
* Add missing ExpiredToken field to response
* Add ApnsUniqueID identifier for development push
  • Loading branch information
sideshow authored Aug 12, 2024
1 parent 6572a53 commit 83ca0a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error
r := &Response{}
r.StatusCode = response.StatusCode
r.ApnsID = response.Header.Get("apns-id")
r.ApnsUniqueID = response.Header.Get("apns-unique-id")

decoder := json.NewDecoder(response.Body)
if err := decoder.Decode(r); err != nil && err != io.EOF {
Expand Down Expand Up @@ -234,5 +235,4 @@ func setHeaders(r *http.Request, n *Notification) {
} else {
r.Header.Set("apns-push-type", string(PushTypeAlert))
}

}
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,19 @@ func TestBadPayload(t *testing.T) {
func Test200SuccessResponse(t *testing.T) {
n := mockNotification()
var apnsID = "02ABC856-EF8D-4E49-8F15-7B8A61D978D6"
var apnsUniqueID = "A6739D99-D92A-424B-A91E-BF012365BD4E"
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("apns-id", apnsID)
w.Header().Set("apns-unique-id", apnsUniqueID)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()
res, err := mockClient(server.URL).Push(n)
assert.NoError(t, err)
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Equal(t, apnsID, res.ApnsID)
assert.Equal(t, apnsUniqueID, res.ApnsUniqueID)
assert.Equal(t, true, res.Sent())
}

Expand Down
8 changes: 8 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const (
// 405 The specified :method was not POST.
ReasonMethodNotAllowed = "MethodNotAllowed"

// 410 The device token has expired.
ReasonExpiredToken = "ExpiredToken"

// 410 The device token is inactive for the specified topic.
ReasonUnregistered = "Unregistered"

Expand Down Expand Up @@ -132,6 +135,11 @@ type Response struct {
// 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 Time

// An identifier that is only available in the Developement enviroment. Use
// this to query Delivery Log information for the corresponding notification
// in Push Notifications Console.
ApnsUniqueID string
}

// Sent returns whether or not the notification was successfully sent.
Expand Down

0 comments on commit 83ca0a4

Please sign in to comment.