Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add missing fields #231

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading