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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 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

## v0.14.0

* Add `total` parameter to list queries allowing skipping counting rows in a table for improved performance
Expand Down
8 changes: 4 additions & 4 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func (srv *Account) DeleteMFAAuthenticator(Type string)(*interface{}, error) {
//
// Deprecated: This API has been deprecated since 1.8.0. Please use `Account.createMFAChallenge` instead.
func (srv *Account) CreateMfaChallenge(Factor string)(*models.MfaChallenge, error) {
path := "/account/mfa/challenge"
path := "/account/mfa/challenges"
params := map[string]interface{}{}
params["factor"] = Factor
headers := map[string]interface{}{
Expand Down Expand Up @@ -672,7 +672,7 @@ func (srv *Account) CreateMfaChallenge(Factor string)(*models.MfaChallenge, erro
// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge)
// method.
func (srv *Account) CreateMFAChallenge(Factor string)(*models.MfaChallenge, error) {
path := "/account/mfa/challenge"
path := "/account/mfa/challenges"
params := map[string]interface{}{}
params["factor"] = Factor
headers := map[string]interface{}{
Expand Down Expand Up @@ -712,7 +712,7 @@ func (srv *Account) CreateMFAChallenge(Factor string)(*models.MfaChallenge, erro
//
// Deprecated: This API has been deprecated since 1.8.0. Please use `Account.updateMFAChallenge` instead.
func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*models.Session, error) {
path := "/account/mfa/challenge"
path := "/account/mfa/challenges"
params := map[string]interface{}{}
params["challengeId"] = ChallengeId
params["otp"] = Otp
Expand Down Expand Up @@ -751,7 +751,7 @@ func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*models.S
// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge)
// method.
func (srv *Account) UpdateMFAChallenge(ChallengeId string, Otp string)(*models.Session, error) {
path := "/account/mfa/challenge"
path := "/account/mfa/challenges"
params := map[string]interface{}{}
params["challengeId"] = ChallengeId
params["otp"] = Otp
Expand Down
264 changes: 264 additions & 0 deletions avatars/avatars.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,267 @@ func (srv *Avatars) GetQR(Text string, optionalSetters ...GetQROption)(*[]byte,
return &parsed, nil

}
type GetScreenshotOptions struct {
Headers interface{}
ViewportWidth int
ViewportHeight int
Scale float64
Theme string
UserAgent string
Fullpage bool
Locale string
Timezone string
Latitude float64
Longitude float64
Accuracy float64
Touch bool
Permissions []string
Sleep int
Width int
Height int
Quality int
Output string
enabledSetters map[string]bool
}
func (options GetScreenshotOptions) New() *GetScreenshotOptions {
options.enabledSetters = map[string]bool{
"Headers": false,
"ViewportWidth": false,
"ViewportHeight": false,
"Scale": false,
"Theme": false,
"UserAgent": false,
"Fullpage": false,
"Locale": false,
"Timezone": false,
"Latitude": false,
"Longitude": false,
"Accuracy": false,
"Touch": false,
"Permissions": false,
"Sleep": false,
"Width": false,
"Height": false,
"Quality": false,
"Output": false,
}
return &options
}
type GetScreenshotOption func(*GetScreenshotOptions)
func (srv *Avatars) WithGetScreenshotHeaders(v interface{}) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Headers = v
o.enabledSetters["Headers"] = true
}
}
func (srv *Avatars) WithGetScreenshotViewportWidth(v int) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.ViewportWidth = v
o.enabledSetters["ViewportWidth"] = true
}
}
func (srv *Avatars) WithGetScreenshotViewportHeight(v int) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.ViewportHeight = v
o.enabledSetters["ViewportHeight"] = true
}
}
func (srv *Avatars) WithGetScreenshotScale(v float64) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Scale = v
o.enabledSetters["Scale"] = true
}
}
func (srv *Avatars) WithGetScreenshotTheme(v string) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Theme = v
o.enabledSetters["Theme"] = true
}
}
func (srv *Avatars) WithGetScreenshotUserAgent(v string) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.UserAgent = v
o.enabledSetters["UserAgent"] = true
}
}
func (srv *Avatars) WithGetScreenshotFullpage(v bool) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Fullpage = v
o.enabledSetters["Fullpage"] = true
}
}
func (srv *Avatars) WithGetScreenshotLocale(v string) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Locale = v
o.enabledSetters["Locale"] = true
}
}
func (srv *Avatars) WithGetScreenshotTimezone(v string) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Timezone = v
o.enabledSetters["Timezone"] = true
}
}
func (srv *Avatars) WithGetScreenshotLatitude(v float64) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Latitude = v
o.enabledSetters["Latitude"] = true
}
}
func (srv *Avatars) WithGetScreenshotLongitude(v float64) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Longitude = v
o.enabledSetters["Longitude"] = true
}
}
func (srv *Avatars) WithGetScreenshotAccuracy(v float64) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Accuracy = v
o.enabledSetters["Accuracy"] = true
}
}
func (srv *Avatars) WithGetScreenshotTouch(v bool) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Touch = v
o.enabledSetters["Touch"] = true
}
}
func (srv *Avatars) WithGetScreenshotPermissions(v []string) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Permissions = v
o.enabledSetters["Permissions"] = true
}
}
func (srv *Avatars) WithGetScreenshotSleep(v int) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Sleep = v
o.enabledSetters["Sleep"] = true
}
}
func (srv *Avatars) WithGetScreenshotWidth(v int) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Width = v
o.enabledSetters["Width"] = true
}
}
func (srv *Avatars) WithGetScreenshotHeight(v int) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Height = v
o.enabledSetters["Height"] = true
}
}
func (srv *Avatars) WithGetScreenshotQuality(v int) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Quality = v
o.enabledSetters["Quality"] = true
}
}
func (srv *Avatars) WithGetScreenshotOutput(v string) GetScreenshotOption {
return func(o *GetScreenshotOptions) {
o.Output = v
o.enabledSetters["Output"] = true
}
}

// GetScreenshot use this endpoint to capture a screenshot of any website URL.
// This endpoint uses a headless browser to render the webpage and capture it
// as an image.
//
// You can configure the browser viewport size, theme, user agent,
// geolocation, permissions, and more. Capture either just the viewport or the
// full page scroll.
//
// When width and height are specified, the image is resized accordingly. If
// both dimensions are 0, the API provides an image at original size. If
// dimensions are not specified, the default viewport size is 1280x720px.
func (srv *Avatars) GetScreenshot(Url string, optionalSetters ...GetScreenshotOption)(*[]byte, error) {
path := "/avatars/screenshots"
options := GetScreenshotOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
params["url"] = Url
if options.enabledSetters["Headers"] {
params["headers"] = options.Headers
}
if options.enabledSetters["ViewportWidth"] {
params["viewportWidth"] = options.ViewportWidth
}
if options.enabledSetters["ViewportHeight"] {
params["viewportHeight"] = options.ViewportHeight
}
if options.enabledSetters["Scale"] {
params["scale"] = options.Scale
}
if options.enabledSetters["Theme"] {
params["theme"] = options.Theme
}
if options.enabledSetters["UserAgent"] {
params["userAgent"] = options.UserAgent
}
if options.enabledSetters["Fullpage"] {
params["fullpage"] = options.Fullpage
}
if options.enabledSetters["Locale"] {
params["locale"] = options.Locale
}
if options.enabledSetters["Timezone"] {
params["timezone"] = options.Timezone
}
if options.enabledSetters["Latitude"] {
params["latitude"] = options.Latitude
}
if options.enabledSetters["Longitude"] {
params["longitude"] = options.Longitude
}
if options.enabledSetters["Accuracy"] {
params["accuracy"] = options.Accuracy
}
if options.enabledSetters["Touch"] {
params["touch"] = options.Touch
}
if options.enabledSetters["Permissions"] {
params["permissions"] = options.Permissions
}
if options.enabledSetters["Sleep"] {
params["sleep"] = options.Sleep
}
if options.enabledSetters["Width"] {
params["width"] = options.Width
}
if options.enabledSetters["Height"] {
params["height"] = options.Height
}
if options.enabledSetters["Quality"] {
params["quality"] = options.Quality
}
if options.enabledSetters["Output"] {
params["output"] = options.Output
}
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))

var parsed []byte

err = json.Unmarshal(bytes, &parsed)
if err != nil {
return nil, err
}
return &parsed, nil
}
var parsed []byte
parsed, ok := resp.Result.([]byte)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.14.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.15.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"x-sdk-name": "Go",
"x-sdk-platform": "server",
"x-sdk-language": "go",
"x-sdk-version": "v0.14.0",
"x-sdk-version": "v0.15.0",
}
httpClient, err := GetDefaultClient(defaultTimeout)
if err != nil {
Expand Down
41 changes: 41 additions & 0 deletions docs/examples/avatars/get-screenshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"github.com/appwrite/sdk-for-go/client"
"github.com/appwrite/sdk-for-go/avatars"
)

client := client.New(
client.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1")
client.WithProject("<YOUR_PROJECT_ID>")
client.WithSession("")
)

service := avatars.New(client)

response, error := service.GetScreenshot(
"https://example.com",
avatars.WithGetScreenshotHeaders(map[string]interface{}{
"Authorization": "Bearer token123",
"X-Custom-Header": "value"
}),
avatars.WithGetScreenshotViewportWidth(1920),
avatars.WithGetScreenshotViewportHeight(1080),
avatars.WithGetScreenshotScale(2),
avatars.WithGetScreenshotTheme("dark"),
avatars.WithGetScreenshotUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15"),
avatars.WithGetScreenshotFullpage(true),
avatars.WithGetScreenshotLocale("en-US"),
avatars.WithGetScreenshotTimezone("America/New_York"),
avatars.WithGetScreenshotLatitude(37.7749),
avatars.WithGetScreenshotLongitude(-122.4194),
avatars.WithGetScreenshotAccuracy(100),
avatars.WithGetScreenshotTouch(true),
avatars.WithGetScreenshotPermissions(interface{}{"geolocation","notifications"}),
avatars.WithGetScreenshotSleep(3),
avatars.WithGetScreenshotWidth(800),
avatars.WithGetScreenshotHeight(600),
avatars.WithGetScreenshotQuality(85),
avatars.WithGetScreenshotOutput("jpeg"),
)
3 changes: 2 additions & 1 deletion docs/examples/functions/create-template-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ response, error := service.CreateTemplateDeployment(
"<REPOSITORY>",
"<OWNER>",
"<ROOT_DIRECTORY>",
"<VERSION>",
"commit",
"<REFERENCE>",
functions.WithCreateTemplateDeploymentActivate(false),
)
3 changes: 2 additions & 1 deletion docs/examples/sites/create-template-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ response, error := service.CreateTemplateDeployment(
"<REPOSITORY>",
"<OWNER>",
"<ROOT_DIRECTORY>",
"<VERSION>",
"branch",
"<REFERENCE>",
sites.WithCreateTemplateDeploymentActivate(false),
)
1 change: 1 addition & 0 deletions docs/examples/storage/create-bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ response, error := service.CreateBucket(
storage.WithCreateBucketCompression("none"),
storage.WithCreateBucketEncryption(false),
storage.WithCreateBucketAntivirus(false),
storage.WithCreateBucketTransformations(false),
)
Loading