diff --git a/CHANGELOG.md b/CHANGELOG.md index f177f1f9..44b607a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## v0.16.1 + +* Update SDK as per latest server specs, these include - + * Updates to Runtime enums + * `Output` is now renamed to `ImageFormat` - Note that this is a breaking change + * Introduces Backups module for managing Database backups + * Introduces Organization module + ## v0.16.0 * Added ability to create columns and indexes synchronously while creating a table @@ -7,7 +15,8 @@ ## v0.15.0 * Rename `VCSDeploymentType` enum to `VCSReferenceType` -* Change `CreateTemplateDeployment` method signature: replace `Version` parameter with `Type` (TemplateReferenceType) and `Reference` parameters +* Change `CreateTemplateDeployment` method signature: replace `Version` parameter with `Type` (TemplateReferenceType) + and `Reference` parameters * Add `GetScreenshot` method to `Avatars` service * Add `Theme`, `Timezone` and `Output` enums diff --git a/LICENSE b/LICENSE index c1602fcd..6f8702b5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2026 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index c5d66a60..b4599f4c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # 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.8.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.8.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) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** +**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** -Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Go SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) +Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Go SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) ![Appwrite](https://github.com/appwrite/appwrite/raw/main/public/images/github.png) diff --git a/account/account.go b/account/account.go index cd8aee1a..fd68baaf 100644 --- a/account/account.go +++ b/account/account.go @@ -259,15 +259,39 @@ func (srv *Account) DeleteIdentity(IdentityId string)(*interface{}, error) { return &parsed, nil } - +type CreateJWTOptions struct { + Duration int + enabledSetters map[string]bool +} +func (options CreateJWTOptions) New() *CreateJWTOptions { + options.enabledSetters = map[string]bool{ + "Duration": false, + } + return &options +} +type CreateJWTOption func(*CreateJWTOptions) +func (srv *Account) WithCreateJWTDuration(v int) CreateJWTOption { + return func(o *CreateJWTOptions) { + o.Duration = v + o.enabledSetters["Duration"] = true + } +} + // CreateJWT use this endpoint to create a JSON Web Token. You can use the // resulting JWT to authenticate on behalf of the current user when working // with the Appwrite server-side API and SDKs. The JWT secret is valid for 15 // minutes from its creation and will be invalid if the user will logout in // that time frame. -func (srv *Account) CreateJWT()(*models.Jwt, error) { +func (srv *Account) CreateJWT(optionalSetters ...CreateJWTOption)(*models.Jwt, error) { path := "/account/jwts" + options := CreateJWTOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} + if options.enabledSetters["Duration"] { + params["duration"] = options.Duration + } headers := map[string]interface{}{ "content-type": "application/json", } diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index e82e1a86..312ca531 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -6,12 +6,14 @@ import ( "github.com/appwrite/sdk-for-go/client" "github.com/appwrite/sdk-for-go/account" "github.com/appwrite/sdk-for-go/avatars" + "github.com/appwrite/sdk-for-go/backups" "github.com/appwrite/sdk-for-go/databases" "github.com/appwrite/sdk-for-go/functions" "github.com/appwrite/sdk-for-go/graphql" "github.com/appwrite/sdk-for-go/health" "github.com/appwrite/sdk-for-go/locale" "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/organizations" "github.com/appwrite/sdk-for-go/sites" "github.com/appwrite/sdk-for-go/storage" "github.com/appwrite/sdk-for-go/tablesdb" @@ -26,6 +28,9 @@ func NewAccount(clt client.Client) *account.Account { func NewAvatars(clt client.Client) *avatars.Avatars { return avatars.New(clt) } +func NewBackups(clt client.Client) *backups.Backups { + return backups.New(clt) +} func NewDatabases(clt client.Client) *databases.Databases { return databases.New(clt) } @@ -44,6 +49,9 @@ func NewLocale(clt client.Client) *locale.Locale { func NewMessaging(clt client.Client) *messaging.Messaging { return messaging.New(clt) } +func NewOrganizations(clt client.Client) *organizations.Organizations { + return organizations.New(clt) +} func NewSites(clt client.Client) *sites.Sites { return sites.New(clt) } diff --git a/backups/backups.go b/backups/backups.go new file mode 100644 index 00000000..9a66beaf --- /dev/null +++ b/backups/backups.go @@ -0,0 +1,663 @@ +package backups + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Backups service +type Backups struct { + client client.Client +} + +func New(clt client.Client) *Backups { + return &Backups{ + client: clt, + } +} + +type ListArchivesOptions struct { + Queries []string + enabledSetters map[string]bool +} +func (options ListArchivesOptions) New() *ListArchivesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListArchivesOption func(*ListArchivesOptions) +func (srv *Backups) WithListArchivesQueries(v []string) ListArchivesOption { + return func(o *ListArchivesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListArchives list all archives for a project. +func (srv *Backups) ListArchives(optionalSetters ...ListArchivesOption)(*models.BackupArchiveList, error) { + path := "/backups/archives" + options := ListArchivesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupArchiveList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupArchiveList + parsed, ok := resp.Result.(models.BackupArchiveList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateArchiveOptions struct { + ResourceId string + enabledSetters map[string]bool +} +func (options CreateArchiveOptions) New() *CreateArchiveOptions { + options.enabledSetters = map[string]bool{ + "ResourceId": false, + } + return &options +} +type CreateArchiveOption func(*CreateArchiveOptions) +func (srv *Backups) WithCreateArchiveResourceId(v string) CreateArchiveOption { + return func(o *CreateArchiveOptions) { + o.ResourceId = v + o.enabledSetters["ResourceId"] = true + } +} + +// CreateArchive create a new archive asynchronously for a project. +func (srv *Backups) CreateArchive(Services []string, optionalSetters ...CreateArchiveOption)(*models.BackupArchive, error) { + path := "/backups/archives" + options := CreateArchiveOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["services"] = Services + if options.enabledSetters["ResourceId"] { + params["resourceId"] = options.ResourceId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupArchive{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupArchive + parsed, ok := resp.Result.(models.BackupArchive) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetArchive get a backup archive using it's ID. +func (srv *Backups) GetArchive(ArchiveId string)(*models.BackupArchive, error) { + r := strings.NewReplacer("{archiveId}", ArchiveId) + path := r.Replace("/backups/archives/{archiveId}") + params := map[string]interface{}{} + params["archiveId"] = ArchiveId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupArchive{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupArchive + parsed, ok := resp.Result.(models.BackupArchive) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteArchive delete an existing archive for a project. +func (srv *Backups) DeleteArchive(ArchiveId string)(*interface{}, error) { + r := strings.NewReplacer("{archiveId}", ArchiveId) + path := r.Replace("/backups/archives/{archiveId}") + params := map[string]interface{}{} + params["archiveId"] = ArchiveId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListPoliciesOptions struct { + Queries []string + enabledSetters map[string]bool +} +func (options ListPoliciesOptions) New() *ListPoliciesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListPoliciesOption func(*ListPoliciesOptions) +func (srv *Backups) WithListPoliciesQueries(v []string) ListPoliciesOption { + return func(o *ListPoliciesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListPolicies list all policies for a project. +func (srv *Backups) ListPolicies(optionalSetters ...ListPoliciesOption)(*models.BackupPolicyList, error) { + path := "/backups/policies" + options := ListPoliciesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupPolicyList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupPolicyList + parsed, ok := resp.Result.(models.BackupPolicyList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreatePolicyOptions struct { + Name string + ResourceId string + Enabled bool + enabledSetters map[string]bool +} +func (options CreatePolicyOptions) New() *CreatePolicyOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "ResourceId": false, + "Enabled": false, + } + return &options +} +type CreatePolicyOption func(*CreatePolicyOptions) +func (srv *Backups) WithCreatePolicyName(v string) CreatePolicyOption { + return func(o *CreatePolicyOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func (srv *Backups) WithCreatePolicyResourceId(v string) CreatePolicyOption { + return func(o *CreatePolicyOptions) { + o.ResourceId = v + o.enabledSetters["ResourceId"] = true + } +} +func (srv *Backups) WithCreatePolicyEnabled(v bool) CreatePolicyOption { + return func(o *CreatePolicyOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreatePolicy create a new backup policy. +func (srv *Backups) CreatePolicy(PolicyId string, Services []string, Retention int, Schedule string, optionalSetters ...CreatePolicyOption)(*models.BackupPolicy, error) { + path := "/backups/policies" + options := CreatePolicyOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["policyId"] = PolicyId + params["services"] = Services + params["retention"] = Retention + params["schedule"] = Schedule + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["ResourceId"] { + params["resourceId"] = options.ResourceId + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupPolicy{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupPolicy + parsed, ok := resp.Result.(models.BackupPolicy) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPolicy get a backup policy using it's ID. +func (srv *Backups) GetPolicy(PolicyId string)(*models.BackupPolicy, error) { + r := strings.NewReplacer("{policyId}", PolicyId) + path := r.Replace("/backups/policies/{policyId}") + params := map[string]interface{}{} + params["policyId"] = PolicyId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupPolicy{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupPolicy + parsed, ok := resp.Result.(models.BackupPolicy) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdatePolicyOptions struct { + Name string + Retention int + Schedule string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdatePolicyOptions) New() *UpdatePolicyOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Retention": false, + "Schedule": false, + "Enabled": false, + } + return &options +} +type UpdatePolicyOption func(*UpdatePolicyOptions) +func (srv *Backups) WithUpdatePolicyName(v string) UpdatePolicyOption { + return func(o *UpdatePolicyOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func (srv *Backups) WithUpdatePolicyRetention(v int) UpdatePolicyOption { + return func(o *UpdatePolicyOptions) { + o.Retention = v + o.enabledSetters["Retention"] = true + } +} +func (srv *Backups) WithUpdatePolicySchedule(v string) UpdatePolicyOption { + return func(o *UpdatePolicyOptions) { + o.Schedule = v + o.enabledSetters["Schedule"] = true + } +} +func (srv *Backups) WithUpdatePolicyEnabled(v bool) UpdatePolicyOption { + return func(o *UpdatePolicyOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdatePolicy update an existing policy using it's ID. +func (srv *Backups) UpdatePolicy(PolicyId string, optionalSetters ...UpdatePolicyOption)(*models.BackupPolicy, error) { + r := strings.NewReplacer("{policyId}", PolicyId) + path := r.Replace("/backups/policies/{policyId}") + options := UpdatePolicyOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["policyId"] = PolicyId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Retention"] { + params["retention"] = options.Retention + } + if options.enabledSetters["Schedule"] { + params["schedule"] = options.Schedule + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupPolicy{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupPolicy + parsed, ok := resp.Result.(models.BackupPolicy) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeletePolicy delete a policy using it's ID. +func (srv *Backups) DeletePolicy(PolicyId string)(*interface{}, error) { + r := strings.NewReplacer("{policyId}", PolicyId) + path := r.Replace("/backups/policies/{policyId}") + params := map[string]interface{}{} + params["policyId"] = PolicyId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateRestorationOptions struct { + NewResourceId string + NewResourceName string + enabledSetters map[string]bool +} +func (options CreateRestorationOptions) New() *CreateRestorationOptions { + options.enabledSetters = map[string]bool{ + "NewResourceId": false, + "NewResourceName": false, + } + return &options +} +type CreateRestorationOption func(*CreateRestorationOptions) +func (srv *Backups) WithCreateRestorationNewResourceId(v string) CreateRestorationOption { + return func(o *CreateRestorationOptions) { + o.NewResourceId = v + o.enabledSetters["NewResourceId"] = true + } +} +func (srv *Backups) WithCreateRestorationNewResourceName(v string) CreateRestorationOption { + return func(o *CreateRestorationOptions) { + o.NewResourceName = v + o.enabledSetters["NewResourceName"] = true + } +} + +// CreateRestoration create and trigger a new restoration for a backup on a +// project. +func (srv *Backups) CreateRestoration(ArchiveId string, Services []string, optionalSetters ...CreateRestorationOption)(*models.BackupRestoration, error) { + path := "/backups/restoration" + options := CreateRestorationOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["archiveId"] = ArchiveId + params["services"] = Services + if options.enabledSetters["NewResourceId"] { + params["newResourceId"] = options.NewResourceId + } + if options.enabledSetters["NewResourceName"] { + params["newResourceName"] = options.NewResourceName + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupRestoration{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupRestoration + parsed, ok := resp.Result.(models.BackupRestoration) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListRestorationsOptions struct { + Queries []string + enabledSetters map[string]bool +} +func (options ListRestorationsOptions) New() *ListRestorationsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListRestorationsOption func(*ListRestorationsOptions) +func (srv *Backups) WithListRestorationsQueries(v []string) ListRestorationsOption { + return func(o *ListRestorationsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListRestorations list all backup restorations for a project. +func (srv *Backups) ListRestorations(optionalSetters ...ListRestorationsOption)(*models.BackupRestorationList, error) { + path := "/backups/restorations" + options := ListRestorationsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupRestorationList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupRestorationList + parsed, ok := resp.Result.(models.BackupRestorationList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetRestoration get the current status of a backup restoration. +func (srv *Backups) GetRestoration(RestorationId string)(*models.BackupRestoration, error) { + r := strings.NewReplacer("{restorationId}", RestorationId) + path := r.Replace("/backups/restorations/{restorationId}") + params := map[string]interface{}{} + params["restorationId"] = RestorationId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.BackupRestoration{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.BackupRestoration + parsed, ok := resp.Result.(models.BackupRestoration) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/client/client.go b/client/client.go index 2d4691d6..51e298d5 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.8.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.16.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.16.1 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v0.16.0", + "x-sdk-version": "v0.16.1", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { @@ -439,7 +439,6 @@ func toString(arg interface{}) string { } } - // flatten recursively flattens params into a map[string]string and writes it to result func flatten(params interface{}, prefix string, result *map[string]string) error { if result == nil { diff --git a/databases/databases.go b/databases/databases.go index ffd2a543..e2570e65 100644 --- a/databases/databases.go +++ b/databases/databases.go @@ -3619,18 +3619,26 @@ func (srv *Databases) GetDocument(DatabaseId string, CollectionId string, Docume } type UpsertDocumentOptions struct { + Data interface{} Permissions []string TransactionId string enabledSetters map[string]bool } func (options UpsertDocumentOptions) New() *UpsertDocumentOptions { options.enabledSetters = map[string]bool{ + "Data": false, "Permissions": false, "TransactionId": false, } return &options } type UpsertDocumentOption func(*UpsertDocumentOptions) +func (srv *Databases) WithUpsertDocumentData(v interface{}) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} func (srv *Databases) WithUpsertDocumentPermissions(v []string) UpsertDocumentOption { return func(o *UpsertDocumentOptions) { o.Permissions = v @@ -3643,14 +3651,14 @@ func (srv *Databases) WithUpsertDocumentTransactionId(v string) UpsertDocumentOp o.enabledSetters["TransactionId"] = true } } - + // UpsertDocument create or update a Document. Before using this route, you // should create a new collection resource using either a [server // integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) // API or directly from your database console. // // Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRow` instead. -func (srv *Databases) UpsertDocument(DatabaseId string, CollectionId string, DocumentId string, Data interface{}, optionalSetters ...UpsertDocumentOption)(*models.Document, error) { +func (srv *Databases) UpsertDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpsertDocumentOption)(*models.Document, error) { r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) path := r.Replace("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}") options := UpsertDocumentOptions{}.New() @@ -3661,7 +3669,9 @@ func (srv *Databases) UpsertDocument(DatabaseId string, CollectionId string, Doc params["databaseId"] = DatabaseId params["collectionId"] = CollectionId params["documentId"] = DocumentId - params["data"] = Data + if options.enabledSetters["Data"] { + params["data"] = options.Data + } if options.enabledSetters["Permissions"] { params["permissions"] = options.Permissions } diff --git a/docs/examples/account/create-jwt.md b/docs/examples/account/create-jwt.md index b3adb795..a5952d8c 100644 --- a/docs/examples/account/create-jwt.md +++ b/docs/examples/account/create-jwt.md @@ -14,4 +14,6 @@ client := client.New( service := account.New(client) -response, error := service.CreateJWT()) +response, error := service.CreateJWT( + account.WithCreateJWTDuration(0), +) diff --git a/docs/examples/backups/create-archive.md b/docs/examples/backups/create-archive.md new file mode 100644 index 00000000..af3e6a17 --- /dev/null +++ b/docs/examples/backups/create-archive.md @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.CreateArchive( + []interface{}{}, + backups.WithCreateArchiveResourceId(""), +) diff --git a/docs/examples/backups/create-policy.md b/docs/examples/backups/create-policy.md new file mode 100644 index 00000000..0f9bda72 --- /dev/null +++ b/docs/examples/backups/create-policy.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.CreatePolicy( + "", + []interface{}{}, + 1, + "", + backups.WithCreatePolicyName(""), + backups.WithCreatePolicyResourceId(""), + backups.WithCreatePolicyEnabled(false), +) diff --git a/docs/examples/backups/create-restoration.md b/docs/examples/backups/create-restoration.md new file mode 100644 index 00000000..ec753d83 --- /dev/null +++ b/docs/examples/backups/create-restoration.md @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.CreateRestoration( + "", + []interface{}{}, + backups.WithCreateRestorationNewResourceId(""), + backups.WithCreateRestorationNewResourceName(""), +) diff --git a/docs/examples/backups/delete-archive.md b/docs/examples/backups/delete-archive.md new file mode 100644 index 00000000..c75d3f25 --- /dev/null +++ b/docs/examples/backups/delete-archive.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.DeleteArchive( + "", +) diff --git a/docs/examples/backups/delete-policy.md b/docs/examples/backups/delete-policy.md new file mode 100644 index 00000000..04697734 --- /dev/null +++ b/docs/examples/backups/delete-policy.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.DeletePolicy( + "", +) diff --git a/docs/examples/backups/get-archive.md b/docs/examples/backups/get-archive.md new file mode 100644 index 00000000..eea6cf39 --- /dev/null +++ b/docs/examples/backups/get-archive.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.GetArchive( + "", +) diff --git a/docs/examples/backups/get-policy.md b/docs/examples/backups/get-policy.md new file mode 100644 index 00000000..15cbfefd --- /dev/null +++ b/docs/examples/backups/get-policy.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.GetPolicy( + "", +) diff --git a/docs/examples/backups/get-restoration.md b/docs/examples/backups/get-restoration.md new file mode 100644 index 00000000..ab9f0c81 --- /dev/null +++ b/docs/examples/backups/get-restoration.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.GetRestoration( + "", +) diff --git a/docs/examples/backups/list-archives.md b/docs/examples/backups/list-archives.md new file mode 100644 index 00000000..20ea7e40 --- /dev/null +++ b/docs/examples/backups/list-archives.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.ListArchives( + backups.WithListArchivesQueries([]interface{}{}), +) diff --git a/docs/examples/backups/list-policies.md b/docs/examples/backups/list-policies.md new file mode 100644 index 00000000..4bf0520c --- /dev/null +++ b/docs/examples/backups/list-policies.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.ListPolicies( + backups.WithListPoliciesQueries([]interface{}{}), +) diff --git a/docs/examples/backups/list-restorations.md b/docs/examples/backups/list-restorations.md new file mode 100644 index 00000000..8e27c879 --- /dev/null +++ b/docs/examples/backups/list-restorations.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.ListRestorations( + backups.WithListRestorationsQueries([]interface{}{}), +) diff --git a/docs/examples/backups/update-policy.md b/docs/examples/backups/update-policy.md new file mode 100644 index 00000000..51e21871 --- /dev/null +++ b/docs/examples/backups/update-policy.md @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/backups" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := backups.New(client) + +response, error := service.UpdatePolicy( + "", + backups.WithUpdatePolicyName(""), + backups.WithUpdatePolicyRetention(1), + backups.WithUpdatePolicySchedule(""), + backups.WithUpdatePolicyEnabled(false), +) diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 314385d6..51359e88 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -18,7 +18,13 @@ response, error := service.UpdateDocument( "", "", "", - databases.WithUpdateDocumentData(map[string]interface{}{}), + databases.WithUpdateDocumentData(map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 33, + "isAdmin": false + }), databases.WithUpdateDocumentPermissions(interface{}{"read("any")"}), databases.WithUpdateDocumentTransactionId(""), ) diff --git a/docs/examples/databases/update-documents.md b/docs/examples/databases/update-documents.md index 729656af..1e1043c6 100644 --- a/docs/examples/databases/update-documents.md +++ b/docs/examples/databases/update-documents.md @@ -17,7 +17,13 @@ service := databases.New(client) response, error := service.UpdateDocuments( "", "", - databases.WithUpdateDocumentsData(map[string]interface{}{}), + databases.WithUpdateDocumentsData(map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 33, + "isAdmin": false + }), databases.WithUpdateDocumentsQueries([]interface{}{}), databases.WithUpdateDocumentsTransactionId(""), ) diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md index 471c3918..95f1c4b6 100644 --- a/docs/examples/databases/upsert-document.md +++ b/docs/examples/databases/upsert-document.md @@ -18,7 +18,13 @@ response, error := service.UpsertDocument( "", "", "", - map[string]interface{}{}, + databases.WithUpsertDocumentData(map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + }), databases.WithUpsertDocumentPermissions(interface{}{"read("any")"}), databases.WithUpsertDocumentTransactionId(""), ) diff --git a/docs/examples/organizations/delete.md b/docs/examples/organizations/delete.md new file mode 100644 index 00000000..42d89b04 --- /dev/null +++ b/docs/examples/organizations/delete.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/organizations" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := organizations.New(client) + +response, error := service.Delete( + "", +) diff --git a/docs/examples/organizations/estimation-delete-organization.md b/docs/examples/organizations/estimation-delete-organization.md new file mode 100644 index 00000000..347ae770 --- /dev/null +++ b/docs/examples/organizations/estimation-delete-organization.md @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/organizations" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := organizations.New(client) + +response, error := service.EstimationDeleteOrganization( + "", +) diff --git a/docs/examples/tablesdb/update-row.md b/docs/examples/tablesdb/update-row.md index 12ea0b10..212be5b2 100644 --- a/docs/examples/tablesdb/update-row.md +++ b/docs/examples/tablesdb/update-row.md @@ -18,7 +18,13 @@ response, error := service.UpdateRow( "", "", "", - tablesdb.WithUpdateRowData(map[string]interface{}{}), + tablesdb.WithUpdateRowData(map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 33, + "isAdmin": false + }), tablesdb.WithUpdateRowPermissions(interface{}{"read("any")"}), tablesdb.WithUpdateRowTransactionId(""), ) diff --git a/docs/examples/tablesdb/update-rows.md b/docs/examples/tablesdb/update-rows.md index ff6a81e5..706abaee 100644 --- a/docs/examples/tablesdb/update-rows.md +++ b/docs/examples/tablesdb/update-rows.md @@ -17,7 +17,13 @@ service := tablesdb.New(client) response, error := service.UpdateRows( "", "", - tablesdb.WithUpdateRowsData(map[string]interface{}{}), + tablesdb.WithUpdateRowsData(map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 33, + "isAdmin": false + }), tablesdb.WithUpdateRowsQueries([]interface{}{}), tablesdb.WithUpdateRowsTransactionId(""), ) diff --git a/docs/examples/tablesdb/upsert-row.md b/docs/examples/tablesdb/upsert-row.md index 4caa5415..097b3550 100644 --- a/docs/examples/tablesdb/upsert-row.md +++ b/docs/examples/tablesdb/upsert-row.md @@ -18,7 +18,13 @@ response, error := service.UpsertRow( "", "", "", - tablesdb.WithUpsertRowData(map[string]interface{}{}), + tablesdb.WithUpsertRowData(map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 33, + "isAdmin": false + }), tablesdb.WithUpsertRowPermissions(interface{}{"read("any")"}), tablesdb.WithUpsertRowTransactionId(""), ) diff --git a/models/backup_archive.go b/models/backup_archive.go new file mode 100644 index 00000000..88b0395e --- /dev/null +++ b/models/backup_archive.go @@ -0,0 +1,58 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Archive Model +type BackupArchive struct { + // Archive ID. + Id string `json:"$id"` + // Archive creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Archive update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Archive policy ID. + PolicyId string `json:"policyId"` + // Archive size in bytes. + Size int `json:"size"` + // The status of the archive creation. Possible values: pending, processing, + // uploading, completed, failed. + Status string `json:"status"` + // The backup start time. + StartedAt string `json:"startedAt"` + // Migration ID. + MigrationId string `json:"migrationId"` + // The services that are backed up by this archive. + Services []string `json:"services"` + // The resources that are backed up by this archive. + Resources []string `json:"resources"` + // The resource ID to backup. Set only if this archive should backup a single + // resource. + ResourceId string `json:"resourceId"` + // The resource type to backup. Set only if this archive should backup a + // single resource. + ResourceType string `json:"resourceType"` + + // Used by Decode() method + data []byte +} + +func (model BackupArchive) New(data []byte) *BackupArchive { + model.data = data + return &model +} + +func (model *BackupArchive) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/backup_archive_list.go b/models/backup_archive_list.go new file mode 100644 index 00000000..8aebff87 --- /dev/null +++ b/models/backup_archive_list.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// BackupArchiveList Model +type BackupArchiveList struct { + // Total number of archives that matched your query. + Total int `json:"total"` + // List of archives. + Archives []BackupArchive `json:"archives"` + + // Used by Decode() method + data []byte +} + +func (model BackupArchiveList) New(data []byte) *BackupArchiveList { + model.data = data + return &model +} + +func (model *BackupArchiveList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/backup_policy.go b/models/backup_policy.go new file mode 100644 index 00000000..015e190f --- /dev/null +++ b/models/backup_policy.go @@ -0,0 +1,55 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Backup Model +type BackupPolicy struct { + // Backup policy ID. + Id string `json:"$id"` + // Backup policy name. + Name string `json:"name"` + // Policy creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Policy update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // The services that are backed up by this policy. + Services []string `json:"services"` + // The resources that are backed up by this policy. + Resources []string `json:"resources"` + // The resource ID to backup. Set only if this policy should backup a single + // resource. + ResourceId string `json:"resourceId"` + // The resource type to backup. Set only if this policy should backup a single + // resource. + ResourceType string `json:"resourceType"` + // How many days to keep the backup before it will be automatically deleted. + Retention int `json:"retention"` + // Policy backup schedule in CRON format. + Schedule string `json:"schedule"` + // Is this policy enabled. + Enabled bool `json:"enabled"` + + // Used by Decode() method + data []byte +} + +func (model BackupPolicy) New(data []byte) *BackupPolicy { + model.data = data + return &model +} + +func (model *BackupPolicy) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/backup_policy_list.go b/models/backup_policy_list.go new file mode 100644 index 00000000..fc2056df --- /dev/null +++ b/models/backup_policy_list.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// BackupPolicyList Model +type BackupPolicyList struct { + // Total number of policies that matched your query. + Total int `json:"total"` + // List of policies. + Policies []BackupPolicy `json:"policies"` + + // Used by Decode() method + data []byte +} + +func (model BackupPolicyList) New(data []byte) *BackupPolicyList { + model.data = data + return &model +} + +func (model *BackupPolicyList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/backup_restoration.go b/models/backup_restoration.go new file mode 100644 index 00000000..56518e5c --- /dev/null +++ b/models/backup_restoration.go @@ -0,0 +1,54 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Restoration Model +type BackupRestoration struct { + // Restoration ID. + Id string `json:"$id"` + // Restoration creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Restoration update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Backup archive ID. + ArchiveId string `json:"archiveId"` + // Backup policy ID. + PolicyId string `json:"policyId"` + // The status of the restoration. Possible values: pending, downloading, + // processing, completed, failed. + Status string `json:"status"` + // The backup start time. + StartedAt string `json:"startedAt"` + // Migration ID. + MigrationId string `json:"migrationId"` + // The services that are backed up by this policy. + Services []string `json:"services"` + // The resources that are backed up by this policy. + Resources []string `json:"resources"` + // Optional data in key-value object. + Options string `json:"options"` + + // Used by Decode() method + data []byte +} + +func (model BackupRestoration) New(data []byte) *BackupRestoration { + model.data = data + return &model +} + +func (model *BackupRestoration) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/backup_restoration_list.go b/models/backup_restoration_list.go new file mode 100644 index 00000000..cb038e50 --- /dev/null +++ b/models/backup_restoration_list.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// BackupRestorationList Model +type BackupRestorationList struct { + // Total number of restorations that matched your query. + Total int `json:"total"` + // List of restorations. + Restorations []BackupRestoration `json:"restorations"` + + // Used by Decode() method + data []byte +} + +func (model BackupRestorationList) New(data []byte) *BackupRestorationList { + model.data = data + return &model +} + +func (model *BackupRestorationList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/bucket.go b/models/bucket.go index b4f05240..2f12ef43 100644 --- a/models/bucket.go +++ b/models/bucket.go @@ -27,7 +27,7 @@ type Bucket struct { MaximumFileSize int `json:"maximumFileSize"` // Allowed file extensions. AllowedFileExtensions []string `json:"allowedFileExtensions"` - // Compression algorithm choosen for compression. Will be one of none, + // Compression algorithm chosen for compression. Will be one of none, // [gzip](https://en.wikipedia.org/wiki/Gzip), or // [zstd](https://en.wikipedia.org/wiki/Zstd). Compression string `json:"compression"` @@ -37,6 +37,8 @@ type Bucket struct { Antivirus bool `json:"antivirus"` // Image transformations are enabled. Transformations bool `json:"transformations"` + // Total size of this bucket in bytes. + TotalSize int `json:"totalSize"` // Used by Decode() method data []byte diff --git a/models/database.go b/models/database.go index df410bab..2d81fe7e 100644 --- a/models/database.go +++ b/models/database.go @@ -21,6 +21,10 @@ type Database struct { Enabled bool `json:"enabled"` // Database type. Type string `json:"type"` + // Database backup policies. + Policies []Index `json:"policies"` + // Database backup archives. + Archives []Collection `json:"archives"` // Used by Decode() method data []byte diff --git a/models/estimation_delete_organization.go b/models/estimation_delete_organization.go new file mode 100644 index 00000000..4d4fe0ba --- /dev/null +++ b/models/estimation_delete_organization.go @@ -0,0 +1,33 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// EstimationDeleteOrganization Model +type EstimationDeleteOrganization struct { + // List of unpaid invoices + UnpaidInvoices []Invoice `json:"unpaidInvoices"` + + // Used by Decode() method + data []byte +} + +func (model EstimationDeleteOrganization) New(data []byte) *EstimationDeleteOrganization { + model.data = data + return &model +} + +func (model *EstimationDeleteOrganization) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/file.go b/models/file.go index 5818ca31..567cf3f5 100644 --- a/models/file.go +++ b/models/file.go @@ -30,6 +30,12 @@ type File struct { ChunksTotal int `json:"chunksTotal"` // Total number of chunks uploaded ChunksUploaded int `json:"chunksUploaded"` + // Whether file contents are encrypted at rest. + Encryption bool `json:"encryption"` + // Compression algorithm used for the file. Will be one of none, + // [gzip](https://en.wikipedia.org/wiki/Gzip), or + // [zstd](https://en.wikipedia.org/wiki/Zstd). + Compression string `json:"compression"` // Used by Decode() method data []byte diff --git a/models/invoice.go b/models/invoice.go new file mode 100644 index 00000000..2003b1e9 --- /dev/null +++ b/models/invoice.go @@ -0,0 +1,75 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Invoice Model +type Invoice struct { + // Invoice ID. + Id string `json:"$id"` + // Invoice creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Invoice update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Invoice permissions. [Learn more about permissions](/docs/permissions). + Permissions []string `json:"$permissions"` + // Project ID + TeamId string `json:"teamId"` + // Aggregation ID + AggregationId string `json:"aggregationId"` + // Billing plan selected. Can be one of `tier-0`, `tier-1` or `tier-2`. + Plan string `json:"plan"` + // Usage breakdown per resource + Usage []UsageResources `json:"usage"` + // Invoice Amount + Amount float64 `json:"amount"` + // Tax percentage + Tax float64 `json:"tax"` + // Tax amount + TaxAmount float64 `json:"taxAmount"` + // VAT percentage + Vat float64 `json:"vat"` + // VAT amount + VatAmount float64 `json:"vatAmount"` + // Gross amount after vat, tax, and discounts applied. + GrossAmount float64 `json:"grossAmount"` + // Credits used. + CreditsUsed float64 `json:"creditsUsed"` + // Currency the invoice is in + Currency string `json:"currency"` + // Client secret for processing failed payments in front-end + ClientSecret string `json:"clientSecret"` + // Invoice status + Status string `json:"status"` + // Last payment error associated with the invoice + LastError string `json:"lastError"` + // Invoice due date. + DueAt string `json:"dueAt"` + // Beginning date of the invoice + From string `json:"from"` + // End date of the invoice + To string `json:"to"` + + // Used by Decode() method + data []byte +} + +func (model Invoice) New(data []byte) *Invoice { + model.data = data + return &model +} + +func (model *Invoice) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/usage_resources.go b/models/usage_resources.go new file mode 100644 index 00000000..5123d659 --- /dev/null +++ b/models/usage_resources.go @@ -0,0 +1,43 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// UsageResource Model +type UsageResources struct { + // Invoice name + Name string `json:"name"` + // Invoice value + Value int `json:"value"` + // Invoice amount + Amount float64 `json:"amount"` + // Invoice rate + Rate float64 `json:"rate"` + // Invoice description + Desc string `json:"desc"` + // Resource ID + ResourceId string `json:"resourceId"` + + // Used by Decode() method + data []byte +} + +func (model UsageResources) New(data []byte) *UsageResources { + model.data = data + return &model +} + +func (model *UsageResources) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/organizations/organizations.go b/organizations/organizations.go new file mode 100644 index 00000000..71736d9f --- /dev/null +++ b/organizations/organizations.go @@ -0,0 +1,90 @@ +package organizations + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Organizations service +type Organizations struct { + client client.Client +} + +func New(clt client.Client) *Organizations { + return &Organizations{ + client: clt, + } +} + + +// Delete delete an organization. +func (srv *Organizations) Delete(OrganizationId string)(*interface{}, error) { + r := strings.NewReplacer("{organizationId}", OrganizationId) + path := r.Replace("/organizations/{organizationId}") + params := map[string]interface{}{} + params["organizationId"] = OrganizationId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// EstimationDeleteOrganization get estimation for deleting an organization. +func (srv *Organizations) EstimationDeleteOrganization(OrganizationId string)(*models.EstimationDeleteOrganization, error) { + r := strings.NewReplacer("{organizationId}", OrganizationId) + path := r.Replace("/organizations/{organizationId}/estimations/delete-organization") + params := map[string]interface{}{} + params["organizationId"] = OrganizationId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.EstimationDeleteOrganization{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.EstimationDeleteOrganization + parsed, ok := resp.Result.(models.EstimationDeleteOrganization) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +}