Skip to content

Commit

Permalink
Merge pull request #25 from appwrite/feat-push-params
Browse files Browse the repository at this point in the history
Add new push message parameters
  • Loading branch information
christyjacob4 authored Jan 21, 2025
2 parents 1bd199f + 0c8bc11 commit 029ca91
Show file tree
Hide file tree
Showing 23 changed files with 164 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# # Change Log

## 0.2.0
## 0.3.0

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 1 addition & 3 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/databases/update-string-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
"",
false,
"<DEFAULT>",
databases.WithUpdateStringAttributeSize(0),
databases.WithUpdateStringAttributeSize(1),
databases.WithUpdateStringAttributeNewKey(""),
)

Expand Down
9 changes: 6 additions & 3 deletions docs/examples/messaging/create-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func main() {
service := messaging.NewMessaging(client)
response, error := service.CreatePush(
"<MESSAGE_ID>",
"<TITLE>",
"<BODY>",
messaging.WithCreatePushTitle("<TITLE>"),
messaging.WithCreatePushBody("<BODY>"),
messaging.WithCreatePushTopics([]interface{}{}),
messaging.WithCreatePushUsers([]interface{}{}),
messaging.WithCreatePushTargets([]interface{}{}),
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/messaging/update-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
98 changes: 92 additions & 6 deletions messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -517,18 +539,40 @@ 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 {
opt(options)
}
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
}
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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 {
Expand All @@ -631,6 +687,9 @@ func (options UpdatePushOptions) New() *UpdatePushOptions {
"Badge": false,
"Draft": false,
"ScheduledAt": false,
"ContentAvailable": false,
"Critical": false,
"Priority": false,
}
return &options
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
}
Expand Down
4 changes: 4 additions & 0 deletions models/attributeboolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions models/attributedatetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions models/attributeemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions models/attributeenum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions models/attributefloat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions models/attributeinteger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions models/attributeip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions models/attributerelationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions models/attributestring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions models/attributeurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion models/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Loading

0 comments on commit 029ca91

Please sign in to comment.