From 0c8bc111c498dfa3b73834187e80a787c39951a7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 11 Dec 2024 01:12:27 +1300 Subject: [PATCH] Add new push message parameters --- CHANGELOG.md | 2 +- README.md | 2 +- account/account.go | 4 +- client/client.go | 4 +- .../databases/update-string-attribute.md | 2 +- docs/examples/messaging/create-push.md | 9 +- docs/examples/messaging/update-push.md | 3 + messaging/messaging.go | 98 +++++++++++++++++-- models/attributeboolean.go | 4 + models/attributedatetime.go | 4 + models/attributeemail.go | 4 + models/attributeenum.go | 4 + models/attributefloat.go | 4 + models/attributeinteger.go | 4 + models/attributeip.go | 4 + models/attributerelationship.go | 4 + models/attributestring.go | 4 + models/attributeurl.go | 4 + models/function.go | 2 +- models/index.go | 4 + models/membership.go | 9 +- models/target.go | 2 + teams/teams.go | 6 +- 23 files changed, 164 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cdd79..fdcb999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ # # Change Log -## 0.2.0 +## 0.3.0 \ No newline at end of file diff --git a/README.md b/README.md index 693ac4a..309c19c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Go SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-go.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.6.1-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) diff --git a/account/account.go b/account/account.go index 990b85f..05edfac 100644 --- a/account/account.go +++ b/account/account.go @@ -1513,9 +1513,7 @@ func (srv *Account) WithCreateMagicURLTokenPhrase(v bool) CreateMagicURLTokenOpt // submit a request to the [POST // /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) // endpoint to complete the login process. The link sent to the user's email -// address is valid for 1 hour. If you are on a mobile device you can leave -// the URL parameter empty, so that the login completion will be handled by -// your Appwrite instance by default. +// address is valid for 1 hour. // // A user is limited to 10 active sessions at a time by default. [Learn more // about session diff --git a/client/client.go b/client/client.go index f4e352b..55997f9 100644 --- a/client/client.go +++ b/client/client.go @@ -69,11 +69,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.6.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/0.2.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/0.3.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "0.2.0", + "x-sdk-version": "0.3.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { diff --git a/docs/examples/databases/update-string-attribute.md b/docs/examples/databases/update-string-attribute.md index d662060..f3e6add 100644 --- a/docs/examples/databases/update-string-attribute.md +++ b/docs/examples/databases/update-string-attribute.md @@ -20,7 +20,7 @@ func main() { "", false, "", - databases.WithUpdateStringAttributeSize(0), + databases.WithUpdateStringAttributeSize(1), databases.WithUpdateStringAttributeNewKey(""), ) diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md index 090e0cb..b400374 100644 --- a/docs/examples/messaging/create-push.md +++ b/docs/examples/messaging/create-push.md @@ -16,8 +16,8 @@ func main() { service := messaging.NewMessaging(client) response, error := service.CreatePush( "", - "", - "<BODY>", + messaging.WithCreatePushTitle("<TITLE>"), + messaging.WithCreatePushBody("<BODY>"), messaging.WithCreatePushTopics([]interface{}{}), messaging.WithCreatePushUsers([]interface{}{}), messaging.WithCreatePushTargets([]interface{}{}), @@ -28,9 +28,12 @@ func main() { messaging.WithCreatePushSound("<SOUND>"), messaging.WithCreatePushColor("<COLOR>"), messaging.WithCreatePushTag("<TAG>"), - messaging.WithCreatePushBadge("<BADGE>"), + messaging.WithCreatePushBadge(0), messaging.WithCreatePushDraft(false), messaging.WithCreatePushScheduledAt(""), + messaging.WithCreatePushContentAvailable(false), + messaging.WithCreatePushCritical(false), + messaging.WithCreatePushPriority("normal"), ) if error != nil { diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md index af1b609..d1b4725 100644 --- a/docs/examples/messaging/update-push.md +++ b/docs/examples/messaging/update-push.md @@ -31,6 +31,9 @@ func main() { messaging.WithUpdatePushBadge(0), messaging.WithUpdatePushDraft(false), messaging.WithUpdatePushScheduledAt(""), + messaging.WithUpdatePushContentAvailable(false), + messaging.WithUpdatePushCritical(false), + messaging.WithUpdatePushPriority("normal"), ) if error != nil { diff --git a/messaging/messaging.go b/messaging/messaging.go index 6978e8c..278a767 100644 --- a/messaging/messaging.go +++ b/messaging/messaging.go @@ -405,6 +405,8 @@ func (srv *Messaging) UpdateEmail(MessageId string, optionalSetters ...UpdateEma } type CreatePushOptions struct { + Title string + Body string Topics []string Users []string Targets []string @@ -415,13 +417,18 @@ type CreatePushOptions struct { Sound string Color string Tag string - Badge string + Badge int Draft bool ScheduledAt string + ContentAvailable bool + Critical bool + Priority string enabledSetters map[string]bool } func (options CreatePushOptions) New() *CreatePushOptions { options.enabledSetters = map[string]bool{ + "Title": false, + "Body": false, "Topics": false, "Users": false, "Targets": false, @@ -435,10 +442,25 @@ func (options CreatePushOptions) New() *CreatePushOptions { "Badge": false, "Draft": false, "ScheduledAt": false, + "ContentAvailable": false, + "Critical": false, + "Priority": false, } return &options } type CreatePushOption func(*CreatePushOptions) +func (srv *Messaging) WithCreatePushTitle(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Title = v + o.enabledSetters["Title"] = true + } +} +func (srv *Messaging) WithCreatePushBody(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Body = v + o.enabledSetters["Body"] = true + } +} func (srv *Messaging) WithCreatePushTopics(v []string) CreatePushOption { return func(o *CreatePushOptions) { o.Topics = v @@ -499,7 +521,7 @@ func (srv *Messaging) WithCreatePushTag(v string) CreatePushOption { o.enabledSetters["Tag"] = true } } -func (srv *Messaging) WithCreatePushBadge(v string) CreatePushOption { +func (srv *Messaging) WithCreatePushBadge(v int) CreatePushOption { return func(o *CreatePushOptions) { o.Badge = v o.enabledSetters["Badge"] = true @@ -517,9 +539,27 @@ func (srv *Messaging) WithCreatePushScheduledAt(v string) CreatePushOption { o.enabledSetters["ScheduledAt"] = true } } - +func (srv *Messaging) WithCreatePushContentAvailable(v bool) CreatePushOption { + return func(o *CreatePushOptions) { + o.ContentAvailable = v + o.enabledSetters["ContentAvailable"] = true + } +} +func (srv *Messaging) WithCreatePushCritical(v bool) CreatePushOption { + return func(o *CreatePushOptions) { + o.Critical = v + o.enabledSetters["Critical"] = true + } +} +func (srv *Messaging) WithCreatePushPriority(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Priority = v + o.enabledSetters["Priority"] = true + } +} + // CreatePush create a new push notification. -func (srv *Messaging) CreatePush(MessageId string, Title string, Body string, optionalSetters ...CreatePushOption)(*models.Message, error) { +func (srv *Messaging) CreatePush(MessageId string, optionalSetters ...CreatePushOption)(*models.Message, error) { path := "/messaging/messages/push" options := CreatePushOptions{}.New() for _, opt := range optionalSetters { @@ -527,8 +567,12 @@ func (srv *Messaging) CreatePush(MessageId string, Title string, Body string, op } params := map[string]interface{}{} params["messageId"] = MessageId - params["title"] = Title - params["body"] = Body + if options.enabledSetters["Title"] { + params["title"] = options.Title + } + if options.enabledSetters["Body"] { + params["body"] = options.Body + } if options.enabledSetters["Topics"] { params["topics"] = options.Topics } @@ -568,6 +612,15 @@ func (srv *Messaging) CreatePush(MessageId string, Title string, Body string, op if options.enabledSetters["ScheduledAt"] { params["scheduledAt"] = options.ScheduledAt } + if options.enabledSetters["ContentAvailable"] { + params["contentAvailable"] = options.ContentAvailable + } + if options.enabledSetters["Critical"] { + params["critical"] = options.Critical + } + if options.enabledSetters["Priority"] { + params["priority"] = options.Priority + } headers := map[string]interface{}{ "content-type": "application/json", } @@ -612,6 +665,9 @@ type UpdatePushOptions struct { Badge int Draft bool ScheduledAt string + ContentAvailable bool + Critical bool + Priority string enabledSetters map[string]bool } func (options UpdatePushOptions) New() *UpdatePushOptions { @@ -631,6 +687,9 @@ func (options UpdatePushOptions) New() *UpdatePushOptions { "Badge": false, "Draft": false, "ScheduledAt": false, + "ContentAvailable": false, + "Critical": false, + "Priority": false, } return &options } @@ -725,6 +784,24 @@ func (srv *Messaging) WithUpdatePushScheduledAt(v string) UpdatePushOption { o.enabledSetters["ScheduledAt"] = true } } +func (srv *Messaging) WithUpdatePushContentAvailable(v bool) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.ContentAvailable = v + o.enabledSetters["ContentAvailable"] = true + } +} +func (srv *Messaging) WithUpdatePushCritical(v bool) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Critical = v + o.enabledSetters["Critical"] = true + } +} +func (srv *Messaging) WithUpdatePushPriority(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Priority = v + o.enabledSetters["Priority"] = true + } +} // UpdatePush update a push notification by its unique ID. func (srv *Messaging) UpdatePush(MessageId string, optionalSetters ...UpdatePushOption)(*models.Message, error) { @@ -781,6 +858,15 @@ func (srv *Messaging) UpdatePush(MessageId string, optionalSetters ...UpdatePush if options.enabledSetters["ScheduledAt"] { params["scheduledAt"] = options.ScheduledAt } + if options.enabledSetters["ContentAvailable"] { + params["contentAvailable"] = options.ContentAvailable + } + if options.enabledSetters["Critical"] { + params["critical"] = options.Critical + } + if options.enabledSetters["Priority"] { + params["priority"] = options.Priority + } headers := map[string]interface{}{ "content-type": "application/json", } diff --git a/models/attributeboolean.go b/models/attributeboolean.go index 5524221..93b7969 100644 --- a/models/attributeboolean.go +++ b/models/attributeboolean.go @@ -21,6 +21,10 @@ type AttributeBoolean struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Default value for attribute when not provided. Cannot be set when attribute // is required. Default bool `json:"xdefault"` diff --git a/models/attributedatetime.go b/models/attributedatetime.go index 85e9d34..2594c92 100644 --- a/models/attributedatetime.go +++ b/models/attributedatetime.go @@ -21,6 +21,10 @@ type AttributeDatetime struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // ISO 8601 format. Format string `json:"format"` // Default value for attribute when not provided. Only null is optional diff --git a/models/attributeemail.go b/models/attributeemail.go index 83d11b5..b9169f6 100644 --- a/models/attributeemail.go +++ b/models/attributeemail.go @@ -21,6 +21,10 @@ type AttributeEmail struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // String format. Format string `json:"format"` // Default value for attribute when not provided. Cannot be set when attribute diff --git a/models/attributeenum.go b/models/attributeenum.go index c7e9cca..c59289a 100644 --- a/models/attributeenum.go +++ b/models/attributeenum.go @@ -21,6 +21,10 @@ type AttributeEnum struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Array of elements in enumerated type. Elements []string `json:"elements"` // String format. diff --git a/models/attributefloat.go b/models/attributefloat.go index 1eb6152..3461aef 100644 --- a/models/attributefloat.go +++ b/models/attributefloat.go @@ -21,6 +21,10 @@ type AttributeFloat struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Minimum value to enforce for new documents. Min float64 `json:"min"` // Maximum value to enforce for new documents. diff --git a/models/attributeinteger.go b/models/attributeinteger.go index acc77df..c7ee76d 100644 --- a/models/attributeinteger.go +++ b/models/attributeinteger.go @@ -21,6 +21,10 @@ type AttributeInteger struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Minimum value to enforce for new documents. Min int `json:"min"` // Maximum value to enforce for new documents. diff --git a/models/attributeip.go b/models/attributeip.go index 43411f0..6c0882c 100644 --- a/models/attributeip.go +++ b/models/attributeip.go @@ -21,6 +21,10 @@ type AttributeIp struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // String format. Format string `json:"format"` // Default value for attribute when not provided. Cannot be set when attribute diff --git a/models/attributerelationship.go b/models/attributerelationship.go index 232b9d8..b67128a 100644 --- a/models/attributerelationship.go +++ b/models/attributerelationship.go @@ -21,6 +21,10 @@ type AttributeRelationship struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // The ID of the related collection. RelatedCollection string `json:"relatedCollection"` // The type of the relationship. diff --git a/models/attributestring.go b/models/attributestring.go index 7b2b208..2077966 100644 --- a/models/attributestring.go +++ b/models/attributestring.go @@ -21,6 +21,10 @@ type AttributeString struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Attribute size. Size int `json:"size"` // Default value for attribute when not provided. Cannot be set when attribute diff --git a/models/attributeurl.go b/models/attributeurl.go index 9a41220..daec4dd 100644 --- a/models/attributeurl.go +++ b/models/attributeurl.go @@ -21,6 +21,10 @@ type AttributeUrl struct { Required bool `json:"required"` // Is attribute an array? Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // String format. Format string `json:"format"` // Default value for attribute when not provided. Cannot be set when attribute diff --git a/models/function.go b/models/function.go index 46ed1e1..50e307a 100644 --- a/models/function.go +++ b/models/function.go @@ -37,7 +37,7 @@ type Function struct { Vars []Variable `json:"vars"` // Function trigger events. Events []string `json:"events"` - // Function execution schedult in CRON format. + // Function execution schedule in CRON format. Schedule string `json:"schedule"` // Function execution timeout in seconds. Timeout int `json:"timeout"` diff --git a/models/index.go b/models/index.go index 621bb2c..67dcfa2 100644 --- a/models/index.go +++ b/models/index.go @@ -21,6 +21,10 @@ type Index struct { Attributes []string `json:"attributes"` // Index orders. Orders []string `json:"orders"` + // Index creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Index update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Used by Decode() method data []byte diff --git a/models/membership.go b/models/membership.go index 95b1c86..777b9dd 100644 --- a/models/membership.go +++ b/models/membership.go @@ -15,9 +15,11 @@ type Membership struct { UpdatedAt string `json:"$updatedAt"` // User ID. UserId string `json:"userId"` - // User name. + // User name. Hide this attribute by toggling membership privacy in the + // Console. UserName string `json:"userName"` - // User email address. + // User email address. Hide this attribute by toggling membership privacy in + // the Console. UserEmail string `json:"userEmail"` // Team ID. TeamId string `json:"teamId"` @@ -32,7 +34,8 @@ type Membership struct { // otherwise. Confirm bool `json:"confirm"` // Multi factor authentication status, true if the user has MFA enabled or - // false otherwise. + // false otherwise. Hide this attribute by toggling membership privacy in the + // Console. Mfa bool `json:"mfa"` // User list of roles Roles []string `json:"roles"` diff --git a/models/target.go b/models/target.go index c50eb51..6e68dff 100644 --- a/models/target.go +++ b/models/target.go @@ -24,6 +24,8 @@ type Target struct { ProviderType string `json:"providerType"` // The target identifier. Identifier string `json:"identifier"` + // Is the target expired. + Expired bool `json:"expired"` // Used by Decode() method data []byte diff --git a/teams/teams.go b/teams/teams.go index 5d45896..d94f640 100644 --- a/teams/teams.go +++ b/teams/teams.go @@ -283,7 +283,8 @@ func (srv *Teams) WithListMembershipsSearch(v string) ListMembershipsOption { } // ListMemberships use this endpoint to list a team's members using the team's -// ID. All team members have read access to this endpoint. +// ID. All team members have read access to this endpoint. Hide sensitive +// attributes from the response by toggling membership privacy in the Console. func (srv *Teams) ListMemberships(TeamId string, optionalSetters ...ListMembershipsOption)(*models.MembershipList, error) { r := strings.NewReplacer("{teamId}", TeamId) path := r.Replace("/teams/{teamId}/memberships") @@ -452,7 +453,8 @@ func (srv *Teams) CreateMembership(TeamId string, Roles []string, optionalSetter } // GetMembership get a team member by the membership unique id. All team -// members have read access for this resource. +// members have read access for this resource. Hide sensitive attributes from +// the response by toggling membership privacy in the Console. func (srv *Teams) GetMembership(TeamId string, MembershipId string)(*models.Membership, error) { r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId) path := r.Replace("/teams/{teamId}/memberships/{membershipId}")