Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Change Log

## v3.0.0

* [BREAKING] Renamed Webhook model fields: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`, `signatureKey` → `secret`
* [BREAKING] Renamed Webhook service parameters to match: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`
* [BREAKING] Renamed `Webhooks.UpdateSignature()` to `Webhooks.UpdateSecret()` with new optional `secret` parameter
* Added `Client.GetHeaders()` method to retrieve request headers
* Added `secret` parameter to Webhook create and update methods
* Added `x` OAuth provider to `OAuthProvider` enum
* Added `userType` field to `Log` model
* Added `purge` parameter to `UpdateCollection` and `UpdateTable` for cache invalidation
* Added Project service: platform CRUD, key CRUD, protocol/service status management
* Added new models: `Key`, `KeyList`, `Project`, `DevKey`, `MockNumber`, `AuthProvider`, `PlatformAndroid`, `PlatformApple`, `PlatformLinux`, `PlatformList`, `PlatformWeb`, `PlatformWindows`, `BillingLimits`, `Block`
* Added new enums: `PlatformType`, `ProtocolId`, `ServiceId`
* Updated `BuildRuntime`, `Runtime` enums with `dart-3.11` and `flutter-3.41`
* Updated `Scopes` enum with `KeysRead`, `KeysWrite`, `PlatformsRead`, `PlatformsWrite`
* Updated `X-Appwrite-Response-Format` header to `1.9.1`
* Updated TTL description for list caching in Databases and TablesDB

## v2.1.0

* Added `GetHeaders` method to `Client` for retrieving current request headers
Expand Down
8 changes: 4 additions & 4 deletions 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.9.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.9.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 All @@ -23,7 +23,7 @@ go mod init <YOUR_MODULE_NAME>
To install using `go get`:

```bash
go get github.com/appwrite/sdk-for-go/v2
go get github.com/appwrite/sdk-for-go/v3
```

## Testing the SDK
Expand Down Expand Up @@ -51,8 +51,8 @@ go get github.com/appwrite/sdk-for-go/v2
"os"
"time"

"github.com/appwrite/sdk-for-go/v2/appwrite"
"github.com/appwrite/sdk-for-go/v2/id"
"github.com/appwrite/sdk-for-go/v3/appwrite"
"github.com/appwrite/sdk-for-go/v3/id"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package account
import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v2/models"
"github.com/appwrite/sdk-for-go/v3/client"
"github.com/appwrite/sdk-for-go/v3/models"
"strings"
)

Expand Down
3 changes: 2 additions & 1 deletion account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v3/client"
)

func TestAccount(t *testing.T) {
Expand Down Expand Up @@ -278,6 +278,7 @@ func TestAccount(t *testing.T) {
"userEmail": "john@appwrite.io",
"userName": "John Doe",
"mode": "admin",
"userType": "user",
"ip": "127.0.0.1",
"time": "2020-10-15T06:38:00.000+00:00",
"osCode": "Mac",
Expand Down
4 changes: 2 additions & 2 deletions activities/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package activities
import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v2/models"
"github.com/appwrite/sdk-for-go/v3/client"
"github.com/appwrite/sdk-for-go/v3/models"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion activities/activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v3/client"
)

func TestActivities(t *testing.T) {
Expand Down
38 changes: 19 additions & 19 deletions appwrite/appwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ package appwrite
import (
"time"

"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v2/account"
"github.com/appwrite/sdk-for-go/v2/activities"
"github.com/appwrite/sdk-for-go/v2/avatars"
"github.com/appwrite/sdk-for-go/v2/backups"
"github.com/appwrite/sdk-for-go/v2/databases"
"github.com/appwrite/sdk-for-go/v2/functions"
"github.com/appwrite/sdk-for-go/v2/graphql"
"github.com/appwrite/sdk-for-go/v2/health"
"github.com/appwrite/sdk-for-go/v2/locale"
"github.com/appwrite/sdk-for-go/v2/messaging"
"github.com/appwrite/sdk-for-go/v2/project"
"github.com/appwrite/sdk-for-go/v2/sites"
"github.com/appwrite/sdk-for-go/v2/storage"
"github.com/appwrite/sdk-for-go/v2/tablesdb"
"github.com/appwrite/sdk-for-go/v2/teams"
"github.com/appwrite/sdk-for-go/v2/tokens"
"github.com/appwrite/sdk-for-go/v2/users"
"github.com/appwrite/sdk-for-go/v2/webhooks"
"github.com/appwrite/sdk-for-go/v3/client"
"github.com/appwrite/sdk-for-go/v3/account"
"github.com/appwrite/sdk-for-go/v3/activities"
"github.com/appwrite/sdk-for-go/v3/avatars"
"github.com/appwrite/sdk-for-go/v3/backups"
"github.com/appwrite/sdk-for-go/v3/databases"
"github.com/appwrite/sdk-for-go/v3/functions"
"github.com/appwrite/sdk-for-go/v3/graphql"
"github.com/appwrite/sdk-for-go/v3/health"
"github.com/appwrite/sdk-for-go/v3/locale"
"github.com/appwrite/sdk-for-go/v3/messaging"
"github.com/appwrite/sdk-for-go/v3/project"
"github.com/appwrite/sdk-for-go/v3/sites"
"github.com/appwrite/sdk-for-go/v3/storage"
"github.com/appwrite/sdk-for-go/v3/tablesdb"
"github.com/appwrite/sdk-for-go/v3/teams"
"github.com/appwrite/sdk-for-go/v3/tokens"
"github.com/appwrite/sdk-for-go/v3/users"
"github.com/appwrite/sdk-for-go/v3/webhooks"
)

func NewAccount(clt client.Client) *account.Account {
Expand Down
2 changes: 1 addition & 1 deletion avatars/avatars.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package avatars
import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v3/client"
"net/url"
"fmt"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion avatars/avatars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v3/client"
)

func TestAvatars(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions backups/backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package backups
import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v2/models"
"github.com/appwrite/sdk-for-go/v3/client"
"github.com/appwrite/sdk-for-go/v3/models"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion backups/backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http/httptest"
"testing"

"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v3/client"
)

func TestBackups(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"time"
"runtime"

"github.com/appwrite/sdk-for-go/v2/file"
"github.com/appwrite/sdk-for-go/v3/file"
)

const (
Expand Down Expand Up @@ -73,12 +73,12 @@ type Client struct {
// Initialize a new Appwrite client with a given timeout
func New(optionalSetters ...ClientOption) Client {
headers := map[string]string{
"X-Appwrite-Response-Format" : "1.9.0",
"user-agent" : fmt.Sprintf("AppwriteGoSDK/v2.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"X-Appwrite-Response-Format" : "1.9.1",
"user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"x-sdk-name": "Go",
"x-sdk-platform": "server",
"x-sdk-language": "go",
"x-sdk-version": "v2.1.0",
"x-sdk-version": "v3.0.0",
}
httpClient, err := GetDefaultClient(defaultTimeout)
if err != nil {
Expand Down
112 changes: 101 additions & 11 deletions databases/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package databases
import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/v2/client"
"github.com/appwrite/sdk-for-go/v2/models"
"github.com/appwrite/sdk-for-go/v3/client"
"github.com/appwrite/sdk-for-go/v3/models"
"fmt"
"strings"
)

Expand Down Expand Up @@ -854,6 +855,7 @@ type UpdateCollectionOptions struct {
Permissions []string
DocumentSecurity bool
Enabled bool
Purge bool
enabledSetters map[string]bool
}
func (options UpdateCollectionOptions) New() *UpdateCollectionOptions {
Expand All @@ -862,6 +864,7 @@ func (options UpdateCollectionOptions) New() *UpdateCollectionOptions {
"Permissions": false,
"DocumentSecurity": false,
"Enabled": false,
"Purge": false,
}
return &options
}
Expand Down Expand Up @@ -890,6 +893,12 @@ func (srv *Databases) WithUpdateCollectionEnabled(v bool) UpdateCollectionOption
o.enabledSetters["Enabled"] = true
}
}
func (srv *Databases) WithUpdateCollectionPurge(v bool) UpdateCollectionOption {
return func(o *UpdateCollectionOptions) {
o.Purge = v
o.enabledSetters["Purge"] = true
}
}

// UpdateCollection update a collection by its unique ID.
//
Expand All @@ -916,6 +925,9 @@ func (srv *Databases) UpdateCollection(DatabaseId string, CollectionId string, o
if options.enabledSetters["Enabled"] {
params["enabled"] = options.Enabled
}
if options.enabledSetters["Purge"] {
params["purge"] = options.Purge
}
headers := map[string]interface{}{
"content-type": "application/json",
}
Expand Down Expand Up @@ -3643,7 +3655,7 @@ func (srv *Databases) UpdateVarcharAttribute(DatabaseId string, CollectionId str
// GetAttribute get attribute by ID.
//
// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.getColumn` instead.
func (srv *Databases) GetAttribute(DatabaseId string, CollectionId string, Key string)(*interface{}, error) {
func (srv *Databases) GetAttribute(DatabaseId string, CollectionId string, Key string)(models.Model, error) {
r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key)
path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/{key}")
params := map[string]interface{}{}
Expand All @@ -3660,20 +3672,98 @@ func (srv *Databases) GetAttribute(DatabaseId string, CollectionId string, Key s
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

var parsed interface{}

err = json.Unmarshal(bytes, &parsed)
if err != nil {
var response map[string]interface{}
if err := json.Unmarshal(bytes, &response); err != nil {
return nil, err
}
return &parsed, nil
if fmt.Sprint(response["type"]) == "string" && fmt.Sprint(response["format"]) == "email" {
parsed := models.AttributeEmail{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "string" && fmt.Sprint(response["format"]) == "enum" {
parsed := models.AttributeEnum{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "string" && fmt.Sprint(response["format"]) == "url" {
parsed := models.AttributeUrl{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "string" && fmt.Sprint(response["format"]) == "ip" {
parsed := models.AttributeIp{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "boolean" {
parsed := models.AttributeBoolean{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "integer" {
parsed := models.AttributeInteger{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "double" {
parsed := models.AttributeFloat{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "datetime" {
parsed := models.AttributeDatetime{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "relationship" {
parsed := models.AttributeRelationship{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}
if fmt.Sprint(response["type"]) == "string" {
parsed := models.AttributeString{}.New(bytes)
if err := json.Unmarshal(bytes, parsed); err != nil {
return nil, err
}

return parsed, nil
}

return nil, errors.New("unable to match response to any expected response model")
}
var parsed interface{}
parsed, ok := resp.Result.(interface{})
parsed, ok := resp.Result.(models.Model)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil
return parsed, nil

}

Expand Down
Loading