Skip to content
Open
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
  •  
  •  
  •  
19 changes: 6 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Change Log

## v0.16.0
## v0.16.1

* Added ability to create columns and indexes synchronously while creating a table
* Breaking change: `Output` enum has been removed; use `ImageFormat` instead.
* Add `getQueueAudits` support to `Health` service.
* Add longtext/mediumtext/text/varchar attribute and column helpers to `Databases` and `TablesDB` services.

## v0.15.0

* Rename `VCSDeploymentType` enum to `VCSReferenceType`
* 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
* Update SDK as per latest server specs, these include -
* Introduces Backups module for managing Database backups
* Introduces Organization module
* Introduce Account level keys, Backup Service & Models

## v0.14.0

Expand Down Expand Up @@ -66,4 +59,4 @@

## 0.3.0

* Add new push message parameters
* Add new push message parameters
247 changes: 247 additions & 0 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,253 @@ func (srv *Account) CreateJWT(optionalSetters ...CreateJWTOption)(*models.Jwt, e
}
return &parsed, nil

}
type ListKeysOptions struct {
Total bool
enabledSetters map[string]bool
}
func (options ListKeysOptions) New() *ListKeysOptions {
options.enabledSetters = map[string]bool{
"Total": false,
}
return &options
}
type ListKeysOption func(*ListKeysOptions)
func (srv *Account) WithListKeysTotal(v bool) ListKeysOption {
return func(o *ListKeysOptions) {
o.Total = v
o.enabledSetters["Total"] = true
}
}

// ListKeys get a list of all API keys from the current account.
func (srv *Account) ListKeys(optionalSetters ...ListKeysOption)(*models.KeyList, error) {
path := "/account/keys"
options := ListKeysOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
if options.enabledSetters["Total"] {
params["total"] = options.Total
}
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.KeyList{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.KeyList
parsed, ok := resp.Result.(models.KeyList)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}
type CreateKeyOptions struct {
Expire string
enabledSetters map[string]bool
}
func (options CreateKeyOptions) New() *CreateKeyOptions {
options.enabledSetters = map[string]bool{
"Expire": false,
}
return &options
}
type CreateKeyOption func(*CreateKeyOptions)
func (srv *Account) WithCreateKeyExpire(v string) CreateKeyOption {
return func(o *CreateKeyOptions) {
o.Expire = v
o.enabledSetters["Expire"] = true
}
}

// CreateKey create a new account API key.
func (srv *Account) CreateKey(Name string, Scopes []string, optionalSetters ...CreateKeyOption)(*models.Key, error) {
path := "/account/keys"
options := CreateKeyOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
params["name"] = Name
params["scopes"] = Scopes
if options.enabledSetters["Expire"] {
params["expire"] = options.Expire
}
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.Key{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.Key
parsed, ok := resp.Result.(models.Key)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}

// GetKey get a key by its unique ID. This endpoint returns details about a
// specific API key in your account including it's scopes.
func (srv *Account) GetKey(KeyId string)(*models.Key, error) {
r := strings.NewReplacer("{keyId}", KeyId)
path := r.Replace("/account/keys/{keyId}")
params := map[string]interface{}{}
params["keyId"] = KeyId
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.Key{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.Key
parsed, ok := resp.Result.(models.Key)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}
type UpdateKeyOptions struct {
Expire string
enabledSetters map[string]bool
}
func (options UpdateKeyOptions) New() *UpdateKeyOptions {
options.enabledSetters = map[string]bool{
"Expire": false,
}
return &options
}
type UpdateKeyOption func(*UpdateKeyOptions)
func (srv *Account) WithUpdateKeyExpire(v string) UpdateKeyOption {
return func(o *UpdateKeyOptions) {
o.Expire = v
o.enabledSetters["Expire"] = true
}
}

// UpdateKey update a key by its unique ID. Use this endpoint to update the
// name, scopes, or expiration time of an API key.
func (srv *Account) UpdateKey(KeyId string, Name string, Scopes []string, optionalSetters ...UpdateKeyOption)(*models.Key, error) {
r := strings.NewReplacer("{keyId}", KeyId)
path := r.Replace("/account/keys/{keyId}")
options := UpdateKeyOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
params["keyId"] = KeyId
params["name"] = Name
params["scopes"] = Scopes
if options.enabledSetters["Expire"] {
params["expire"] = options.Expire
}
headers := map[string]interface{}{
"content-type": "application/json",
}

resp, err := srv.client.Call("PUT", path, headers, params)
if err != nil {
return nil, err
}
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.Key{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.Key
parsed, ok := resp.Result.(models.Key)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}

// DeleteKey delete a key by its unique ID. Once deleted, the key can no
// longer be used to authenticate API calls.
func (srv *Account) DeleteKey(KeyId string)(*interface{}, error) {
r := strings.NewReplacer("{keyId}", KeyId)
path := r.Replace("/account/keys/{keyId}")
params := map[string]interface{}{}
params["keyId"] = KeyId
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 ListLogsOptions struct {
Queries []string
Expand Down
8 changes: 8 additions & 0 deletions appwrite/appwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
Loading