From 85c10c18f3b63512465e856f98afa5f7cbfa01a2 Mon Sep 17 00:00:00 2001 From: Hrishav Kumar Date: Fri, 15 Jan 2021 18:49:43 +0530 Subject: [PATCH 1/4] update struct for notification request --- types.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types.go b/types.go index 220e496..fa9f790 100644 --- a/types.go +++ b/types.go @@ -93,12 +93,12 @@ type DeviceSubscriptionRequest struct { // SendNotificationRequest is representation of data to be sent to pushy service to create new notification type SendNotificationRequest struct { - To []string `json:"to"` - Data string `json:"data"` - TimeToLive int `json:"time_to_live"` - IOSMutableContent bool `json:"mutable_content"` - IOSContentAvailable bool `json:"content_available"` - IOSNotification IOSNotification `json:"notification"` + To []string `json:"to"` + Data map[string]interface{} `json:"data"` + TimeToLive int `json:"time_to_live"` + IOSMutableContent bool `json:"mutable_content"` + IOSContentAvailable bool `json:"content_available"` + IOSNotification *IOSNotification `json:"notification"` } // IOSNotification is a basic data for notification for iOS devices From a26d0c4eafce5004d095474c2e7bedc0b6068b47 Mon Sep 17 00:00:00 2001 From: Hrishav Kumar Date: Mon, 18 Jan 2021 14:58:18 +0530 Subject: [PATCH 2/4] refactor: add error code in error struct --- types.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types.go b/types.go index fa9f790..5098fe1 100644 --- a/types.go +++ b/types.go @@ -28,6 +28,7 @@ type Pushy struct { // Error are simple error responses returned from pushy if request isn't valid type Error struct { + Code string `json:"code"` Error string `json:"error"` } @@ -133,3 +134,12 @@ type IHTTPClient interface { Post(string, string, io.Reader) (*http.Response, error) Do(*http.Request) (*http.Response, error) } + +const ( + ErrInvalidParam = "INVALID_PARAM" + ErrInvalidParam = "INVALID_API_KEY" + ErrInvalidParam = "AUTH_LIMIT_EXCEEDED" + ErrInvalidParam = "ACCOUNT_SUSPENDED" + ErrInvalidParam = "RATE_LIMIT_EXCEEDED" + ErrInvalidParam = "INTERNAL_SERVER_ERROR" +) From 24bd95a94a8ef70928eb8bd82d966adf2cb59bad Mon Sep 17 00:00:00 2001 From: Hrishav Kumar Date: Mon, 18 Jan 2021 15:03:37 +0530 Subject: [PATCH 3/4] fix: fix error code names --- types.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types.go b/types.go index 5098fe1..8571ad3 100644 --- a/types.go +++ b/types.go @@ -136,10 +136,10 @@ type IHTTPClient interface { } const ( - ErrInvalidParam = "INVALID_PARAM" - ErrInvalidParam = "INVALID_API_KEY" - ErrInvalidParam = "AUTH_LIMIT_EXCEEDED" - ErrInvalidParam = "ACCOUNT_SUSPENDED" - ErrInvalidParam = "RATE_LIMIT_EXCEEDED" - ErrInvalidParam = "INTERNAL_SERVER_ERROR" + ErrInvalidParam = "INVALID_PARAM" + ErrInvalidAuthKey = "INVALID_API_KEY" + ErrAuthLimitExcceded = "AUTH_LIMIT_EXCEEDED" + ErrAccountSuspended = "ACCOUNT_SUSPENDED" + ErrRateLimitExceeded = "RATE_LIMIT_EXCEEDED" + ErrInternalServerError = "INTERNAL_SERVER_ERROR" ) From 1195c443dc72b1c5e71149c50e20cf9265954cb2 Mon Sep 17 00:00:00 2001 From: Hrishav Kumar Date: Mon, 18 Jan 2021 15:09:39 +0530 Subject: [PATCH 4/4] refactor: add more error codes --- types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types.go b/types.go index 8571ad3..1e98e0c 100644 --- a/types.go +++ b/types.go @@ -142,4 +142,6 @@ const ( ErrAccountSuspended = "ACCOUNT_SUSPENDED" ErrRateLimitExceeded = "RATE_LIMIT_EXCEEDED" ErrInternalServerError = "INTERNAL_SERVER_ERROR" + ErrNoRecipents = "NO_RECIPIENTS" + ErrNoApnAuth = "NO_APNS_AUTH" )