Skip to content

Commit 83ca0a4

Browse files
authored
Feature/add missing fields (#231)
* Add missing ExpiredToken field to response * Add ApnsUniqueID identifier for development push
1 parent 6572a53 commit 83ca0a4

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (c *Client) PushWithContext(ctx Context, n *Notification) (*Response, error
192192
r := &Response{}
193193
r.StatusCode = response.StatusCode
194194
r.ApnsID = response.Header.Get("apns-id")
195+
r.ApnsUniqueID = response.Header.Get("apns-unique-id")
195196

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

client_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,19 @@ func TestBadPayload(t *testing.T) {
370370
func Test200SuccessResponse(t *testing.T) {
371371
n := mockNotification()
372372
var apnsID = "02ABC856-EF8D-4E49-8F15-7B8A61D978D6"
373+
var apnsUniqueID = "A6739D99-D92A-424B-A91E-BF012365BD4E"
373374
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
374375
w.Header().Set("Content-Type", "application/json; charset=utf-8")
375376
w.Header().Set("apns-id", apnsID)
377+
w.Header().Set("apns-unique-id", apnsUniqueID)
376378
w.WriteHeader(http.StatusOK)
377379
}))
378380
defer server.Close()
379381
res, err := mockClient(server.URL).Push(n)
380382
assert.NoError(t, err)
381383
assert.Equal(t, http.StatusOK, res.StatusCode)
382384
assert.Equal(t, apnsID, res.ApnsID)
385+
assert.Equal(t, apnsUniqueID, res.ApnsUniqueID)
383386
assert.Equal(t, true, res.Sent())
384387
}
385388

response.go

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const (
8484
// 405 The specified :method was not POST.
8585
ReasonMethodNotAllowed = "MethodNotAllowed"
8686

87+
// 410 The device token has expired.
88+
ReasonExpiredToken = "ExpiredToken"
89+
8790
// 410 The device token is inactive for the specified topic.
8891
ReasonUnregistered = "Unregistered"
8992

@@ -132,6 +135,11 @@ type Response struct {
132135
// If the value of StatusCode is 410, this is the last time at which APNs
133136
// confirmed that the device token was no longer valid for the topic.
134137
Timestamp Time
138+
139+
// An identifier that is only available in the Developement enviroment. Use
140+
// this to query Delivery Log information for the corresponding notification
141+
// in Push Notifications Console.
142+
ApnsUniqueID string
135143
}
136144

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

0 commit comments

Comments
 (0)