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
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Change Log

## v4.0.0

* Breaking: Renamed `AuthMethod` enum to `ProjectAuthMethodId`
* Breaking: Renamed `EmailTemplateType` to `ProjectEmailTemplateId` and `EmailTemplateLocale` to `ProjectEmailTemplateLocale`
* Breaking: Renamed `ServiceId` to `ProjectServiceId`, `ProtocolId` to `ProjectProtocolId`, `Secure` to `ProjectSMTPSecure`, `ProjectPolicy` to `ProjectPolicyId`
* Breaking: Replaced `Scopes` enum with `ProjectKeyScopes` for project key endpoints
* Breaking: Removed `Project.UpdateDenyCanonicalEmailPolicy`; replaced with `UpdateDenyAliasedEmailPolicy`, `UpdateDenyDisposableEmailPolicy`, and `UpdateDenyFreeEmailPolicy`
* Breaking: Removed `AuthProvider` model; use new `ProjectOAuthProviderId` enum instead
* Added: `Project.Get` method to fetch current project details
* Added: `Advisor`, `Presences`, and `Usage` services
* Added: `Insight`, `Presence`, `Report`, `UsageEvent`, and `UsageGauge` models with list variants
* Added: `ProjectAuthMethod`, `ProjectProtocol`, and `ProjectService` models
* Added: `ProjectOAuthProviderId` and `ProjectOAuth2GooglePrompt` enums
* Updated: `Project`, `Database`, and `OAuth2Google` model schemas
* Updated: `X-Appwrite-Response-Format` header to `1.9.5`

## v3.1.0

* Added: Introduced `bigint` create/update APIs for legacy Databases attributes
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.4-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.9.5-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/v3
go get github.com/appwrite/sdk-for-go/v4
```

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

"github.com/appwrite/sdk-for-go/v3/appwrite"
"github.com/appwrite/sdk-for-go/v3/id"
"github.com/appwrite/sdk-for-go/v4/appwrite"
"github.com/appwrite/sdk-for-go/v4/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/v3/client"
"github.com/appwrite/sdk-for-go/v3/models"
"github.com/appwrite/sdk-for-go/v4/client"
"github.com/appwrite/sdk-for-go/v4/models"
"strings"
)

Expand Down
2 changes: 1 addition & 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/v3/client"
"github.com/appwrite/sdk-for-go/v4/client"
)

func TestAccount(t *testing.T) {
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/v3/client"
"github.com/appwrite/sdk-for-go/v3/models"
"github.com/appwrite/sdk-for-go/v4/client"
"github.com/appwrite/sdk-for-go/v4/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/v3/client"
"github.com/appwrite/sdk-for-go/v4/client"
)

func TestActivities(t *testing.T) {
Expand Down
264 changes: 264 additions & 0 deletions advisor/advisor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
package advisor

import (
"encoding/json"
"errors"
"github.com/appwrite/sdk-for-go/v4/client"
"github.com/appwrite/sdk-for-go/v4/models"
"strings"
)

// Advisor service
type Advisor struct {
client client.Client
}

func New(clt client.Client) *Advisor {
return &Advisor{
client: clt,
}
}

type ListReportsOptions struct {
Queries []string
Total bool
enabledSetters map[string]bool
}
func (options ListReportsOptions) New() *ListReportsOptions {
options.enabledSetters = map[string]bool{
"Queries": false,
"Total": false,
}
return &options
}
type ListReportsOption func(*ListReportsOptions)
func (srv *Advisor) WithListReportsQueries(v []string) ListReportsOption {
return func(o *ListReportsOptions) {
o.Queries = v
o.enabledSetters["Queries"] = true
}
}
func (srv *Advisor) WithListReportsTotal(v bool) ListReportsOption {
return func(o *ListReportsOptions) {
o.Total = v
o.enabledSetters["Total"] = true
}
}

// ListReports get a list of all the project's analyzer reports. You can use
// the query params to filter your results.
func (srv *Advisor) ListReports(optionalSetters ...ListReportsOption)(*models.ReportList, error) {
path := "/reports"
options := ListReportsOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
if options.enabledSetters["Queries"] {
params["queries"] = options.Queries
}
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.ReportList{}.New(bytes)

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

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

}

// GetReport get an analyzer report by its unique ID. The response includes
// the report's metadata and the nested insights it produced.
func (srv *Advisor) GetReport(ReportId string)(*models.Report, error) {
r := strings.NewReplacer("{reportId}", ReportId)
path := r.Replace("/reports/{reportId}")
params := map[string]interface{}{}
params["reportId"] = ReportId
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.Report{}.New(bytes)

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

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

}

// DeleteReport delete an analyzer report by its unique ID. Nested insights
// and CTA metadata are removed asynchronously by the deletes worker.
func (srv *Advisor) DeleteReport(ReportId string)(*interface{}, error) {
r := strings.NewReplacer("{reportId}", ReportId)
path := r.Replace("/reports/{reportId}")
params := map[string]interface{}{}
params["reportId"] = ReportId
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 ListInsightsOptions struct {
Queries []string
Total bool
enabledSetters map[string]bool
}
func (options ListInsightsOptions) New() *ListInsightsOptions {
options.enabledSetters = map[string]bool{
"Queries": false,
"Total": false,
}
return &options
}
type ListInsightsOption func(*ListInsightsOptions)
func (srv *Advisor) WithListInsightsQueries(v []string) ListInsightsOption {
return func(o *ListInsightsOptions) {
o.Queries = v
o.enabledSetters["Queries"] = true
}
}
func (srv *Advisor) WithListInsightsTotal(v bool) ListInsightsOption {
return func(o *ListInsightsOptions) {
o.Total = v
o.enabledSetters["Total"] = true
}
}

// ListInsights list the insights produced under a single analyzer report. You
// can use the query params to filter your results further.
func (srv *Advisor) ListInsights(ReportId string, optionalSetters ...ListInsightsOption)(*models.InsightList, error) {
r := strings.NewReplacer("{reportId}", ReportId)
path := r.Replace("/reports/{reportId}/insights")
options := ListInsightsOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
params["reportId"] = ReportId
if options.enabledSetters["Queries"] {
params["queries"] = options.Queries
}
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.InsightList{}.New(bytes)

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

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

}

// GetInsight get an insight by its unique ID, scoped to its parent report.
func (srv *Advisor) GetInsight(ReportId string, InsightId string)(*models.Insight, error) {
r := strings.NewReplacer("{reportId}", ReportId, "{insightId}", InsightId)
path := r.Replace("/reports/{reportId}/insights/{insightId}")
params := map[string]interface{}{}
params["reportId"] = ReportId
params["insightId"] = InsightId
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.Insight{}.New(bytes)

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

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

}
Loading
Loading