From 748203e5536c271c82c7052c9e111278775a5503 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 3 Jul 2024 17:07:53 +0200 Subject: [PATCH] feat: 1.6.x preview --- CHANGELOG.md | 4 + LICENSE | 12 + README.md | 89 + account/account.go | 1666 +++++++ avatars/avatars.go | 557 +++ client/client.go | 492 ++ databases/databases.go | 2283 ++++++++++ .../account/create-anonymous-session.md | 24 + .../account/create-email-password-session.md | 26 + docs/examples/account/create-email-token.md | 27 + docs/examples/account/create-j-w-t.md | 24 + .../account/create-magic-u-r-l-token.md | 28 + .../account/create-mfa-authenticator.md | 26 + docs/examples/account/create-mfa-challenge.md | 25 + .../account/create-mfa-recovery-codes.md | 25 + docs/examples/account/create-o-auth2token.md | 28 + docs/examples/account/create-phone-token.md | 26 + .../account/create-phone-verification.md | 25 + docs/examples/account/create-recovery.md | 27 + docs/examples/account/create-session.md | 26 + docs/examples/account/create-verification.md | 26 + docs/examples/account/create.md | 28 + docs/examples/account/delete-identity.md | 26 + .../account/delete-mfa-authenticator.md | 27 + docs/examples/account/delete-session.md | 26 + docs/examples/account/delete-sessions.md | 25 + .../account/get-mfa-recovery-codes.md | 25 + docs/examples/account/get-prefs.md | 25 + docs/examples/account/get-session.md | 26 + docs/examples/account/get.md | 25 + docs/examples/account/list-identities.md | 26 + docs/examples/account/list-logs.md | 26 + docs/examples/account/list-mfa-factors.md | 25 + docs/examples/account/list-sessions.md | 25 + docs/examples/account/update-email.md | 27 + docs/examples/account/update-m-f-a.md | 26 + .../account/update-magic-u-r-l-session.md | 26 + .../account/update-mfa-authenticator.md | 27 + docs/examples/account/update-mfa-challenge.md | 27 + .../account/update-mfa-recovery-codes.md | 25 + docs/examples/account/update-name.md | 26 + docs/examples/account/update-password.md | 27 + docs/examples/account/update-phone-session.md | 26 + .../account/update-phone-verification.md | 27 + docs/examples/account/update-phone.md | 27 + docs/examples/account/update-prefs.md | 26 + docs/examples/account/update-recovery.md | 28 + docs/examples/account/update-session.md | 26 + docs/examples/account/update-status.md | 25 + docs/examples/account/update-verification.md | 27 + docs/examples/avatars/get-browser.md | 29 + docs/examples/avatars/get-credit-card.md | 29 + docs/examples/avatars/get-favicon.md | 26 + docs/examples/avatars/get-flag.md | 29 + docs/examples/avatars/get-image.md | 28 + docs/examples/avatars/get-initials.md | 29 + docs/examples/avatars/get-q-r.md | 29 + .../databases/create-boolean-attribute.md | 31 + docs/examples/databases/create-collection.md | 31 + .../databases/create-datetime-attribute.md | 31 + docs/examples/databases/create-document.md | 30 + .../databases/create-email-attribute.md | 31 + .../databases/create-enum-attribute.md | 32 + .../databases/create-float-attribute.md | 33 + docs/examples/databases/create-index.md | 31 + .../databases/create-integer-attribute.md | 33 + .../examples/databases/create-ip-attribute.md | 31 + .../create-relationship-attribute.md | 33 + .../databases/create-string-attribute.md | 33 + .../databases/create-url-attribute.md | 31 + docs/examples/databases/create.md | 28 + docs/examples/databases/delete-attribute.md | 28 + docs/examples/databases/delete-collection.md | 27 + docs/examples/databases/delete-document.md | 28 + docs/examples/databases/delete-index.md | 28 + docs/examples/databases/delete.md | 26 + docs/examples/databases/get-attribute.md | 28 + docs/examples/databases/get-collection.md | 27 + docs/examples/databases/get-document.md | 29 + docs/examples/databases/get-index.md | 28 + docs/examples/databases/get.md | 26 + docs/examples/databases/list-attributes.md | 28 + docs/examples/databases/list-collections.md | 28 + docs/examples/databases/list-documents.md | 28 + docs/examples/databases/list-indexes.md | 28 + docs/examples/databases/list.md | 27 + .../databases/update-boolean-attribute.md | 30 + docs/examples/databases/update-collection.md | 31 + .../databases/update-datetime-attribute.md | 30 + docs/examples/databases/update-document.md | 30 + .../databases/update-email-attribute.md | 30 + .../databases/update-enum-attribute.md | 31 + .../databases/update-float-attribute.md | 32 + .../databases/update-integer-attribute.md | 32 + .../examples/databases/update-ip-attribute.md | 30 + .../update-relationship-attribute.md | 29 + .../databases/update-string-attribute.md | 30 + .../databases/update-url-attribute.md | 30 + docs/examples/databases/update.md | 28 + docs/examples/functions/create-build.md | 28 + docs/examples/functions/create-deployment.md | 30 + docs/examples/functions/create-execution.md | 32 + docs/examples/functions/create-variable.md | 28 + docs/examples/functions/create.md | 46 + docs/examples/functions/delete-deployment.md | 27 + docs/examples/functions/delete-execution.md | 27 + docs/examples/functions/delete-variable.md | 27 + docs/examples/functions/delete.md | 26 + .../examples/functions/download-deployment.md | 27 + docs/examples/functions/get-deployment.md | 27 + docs/examples/functions/get-execution.md | 27 + docs/examples/functions/get-variable.md | 27 + docs/examples/functions/get.md | 26 + docs/examples/functions/list-deployments.md | 28 + docs/examples/functions/list-executions.md | 28 + docs/examples/functions/list-runtimes.md | 25 + docs/examples/functions/list-variables.md | 26 + docs/examples/functions/list.md | 27 + .../functions/update-deployment-build.md | 27 + docs/examples/functions/update-deployment.md | 27 + docs/examples/functions/update-variable.md | 29 + docs/examples/functions/update.md | 42 + docs/examples/graphql/mutation.md | 26 + docs/examples/graphql/query.md | 26 + docs/examples/health/get-antivirus.md | 25 + docs/examples/health/get-cache.md | 25 + docs/examples/health/get-certificate.md | 26 + docs/examples/health/get-d-b.md | 25 + docs/examples/health/get-failed-jobs.md | 27 + docs/examples/health/get-pub-sub.md | 25 + docs/examples/health/get-queue-builds.md | 26 + .../examples/health/get-queue-certificates.md | 26 + docs/examples/health/get-queue-databases.md | 27 + docs/examples/health/get-queue-deletes.md | 26 + docs/examples/health/get-queue-functions.md | 26 + docs/examples/health/get-queue-logs.md | 26 + docs/examples/health/get-queue-mails.md | 26 + docs/examples/health/get-queue-messaging.md | 26 + docs/examples/health/get-queue-migrations.md | 26 + docs/examples/health/get-queue-usage-dump.md | 26 + docs/examples/health/get-queue-usage.md | 26 + docs/examples/health/get-queue-webhooks.md | 26 + docs/examples/health/get-queue.md | 25 + docs/examples/health/get-storage-local.md | 25 + docs/examples/health/get-storage.md | 25 + docs/examples/health/get-time.md | 25 + docs/examples/health/get.md | 25 + docs/examples/locale/get.md | 25 + docs/examples/locale/list-codes.md | 25 + docs/examples/locale/list-continents.md | 25 + docs/examples/locale/list-countries-e-u.md | 25 + docs/examples/locale/list-countries-phones.md | 25 + docs/examples/locale/list-countries.md | 25 + docs/examples/locale/list-currencies.md | 25 + docs/examples/locale/list-languages.md | 25 + .../messaging/create-apns-provider.md | 33 + docs/examples/messaging/create-email.md | 37 + .../examples/messaging/create-fcm-provider.md | 29 + .../messaging/create-mailgun-provider.md | 35 + .../messaging/create-msg91provider.md | 31 + docs/examples/messaging/create-push.md | 41 + .../messaging/create-sendgrid-provider.md | 33 + docs/examples/messaging/create-sms.md | 32 + .../messaging/create-smtp-provider.md | 39 + docs/examples/messaging/create-subscriber.md | 28 + .../messaging/create-telesign-provider.md | 31 + .../messaging/create-textmagic-provider.md | 31 + docs/examples/messaging/create-topic.md | 28 + .../messaging/create-twilio-provider.md | 31 + .../messaging/create-vonage-provider.md | 31 + docs/examples/messaging/delete-provider.md | 26 + docs/examples/messaging/delete-subscriber.md | 27 + docs/examples/messaging/delete-topic.md | 26 + docs/examples/messaging/delete.md | 26 + docs/examples/messaging/get-message.md | 26 + docs/examples/messaging/get-provider.md | 26 + docs/examples/messaging/get-subscriber.md | 27 + docs/examples/messaging/get-topic.md | 26 + docs/examples/messaging/list-message-logs.md | 27 + docs/examples/messaging/list-messages.md | 27 + docs/examples/messaging/list-provider-logs.md | 27 + docs/examples/messaging/list-providers.md | 27 + .../messaging/list-subscriber-logs.md | 27 + docs/examples/messaging/list-subscribers.md | 28 + docs/examples/messaging/list-targets.md | 27 + docs/examples/messaging/list-topic-logs.md | 27 + docs/examples/messaging/list-topics.md | 27 + .../messaging/update-apns-provider.md | 33 + docs/examples/messaging/update-email.md | 37 + .../examples/messaging/update-fcm-provider.md | 29 + .../messaging/update-mailgun-provider.md | 35 + .../messaging/update-msg91provider.md | 31 + docs/examples/messaging/update-push.md | 41 + .../messaging/update-sendgrid-provider.md | 33 + docs/examples/messaging/update-sms.md | 32 + .../messaging/update-smtp-provider.md | 39 + .../messaging/update-telesign-provider.md | 31 + .../messaging/update-textmagic-provider.md | 31 + docs/examples/messaging/update-topic.md | 28 + .../messaging/update-twilio-provider.md | 31 + .../messaging/update-vonage-provider.md | 31 + docs/examples/storage/create-bucket.md | 35 + docs/examples/storage/create-file.md | 29 + docs/examples/storage/delete-bucket.md | 26 + docs/examples/storage/delete-file.md | 27 + docs/examples/storage/get-bucket.md | 26 + docs/examples/storage/get-file-download.md | 27 + docs/examples/storage/get-file-preview.md | 38 + docs/examples/storage/get-file-view.md | 27 + docs/examples/storage/get-file.md | 27 + docs/examples/storage/list-buckets.md | 27 + docs/examples/storage/list-files.md | 28 + docs/examples/storage/update-bucket.md | 35 + docs/examples/storage/update-file.md | 29 + docs/examples/teams/create-membership.md | 32 + docs/examples/teams/create.md | 28 + docs/examples/teams/delete-membership.md | 27 + docs/examples/teams/delete.md | 26 + docs/examples/teams/get-membership.md | 27 + docs/examples/teams/get-prefs.md | 26 + docs/examples/teams/get.md | 26 + docs/examples/teams/list-memberships.md | 28 + docs/examples/teams/list.md | 27 + .../teams/update-membership-status.md | 29 + docs/examples/teams/update-membership.md | 28 + docs/examples/teams/update-name.md | 27 + docs/examples/teams/update-prefs.md | 27 + docs/examples/users/create-argon2user.md | 29 + docs/examples/users/create-bcrypt-user.md | 29 + docs/examples/users/create-j-w-t.md | 28 + docs/examples/users/create-m-d5user.md | 29 + .../users/create-mfa-recovery-codes.md | 26 + docs/examples/users/create-p-h-pass-user.md | 29 + docs/examples/users/create-s-h-a-user.md | 30 + .../users/create-scrypt-modified-user.md | 32 + docs/examples/users/create-scrypt-user.md | 34 + docs/examples/users/create-session.md | 26 + docs/examples/users/create-target.md | 31 + docs/examples/users/create-token.md | 28 + docs/examples/users/create.md | 30 + docs/examples/users/delete-identity.md | 26 + .../users/delete-mfa-authenticator.md | 27 + docs/examples/users/delete-session.md | 27 + docs/examples/users/delete-sessions.md | 26 + docs/examples/users/delete-target.md | 27 + docs/examples/users/delete.md | 26 + docs/examples/users/get-mfa-recovery-codes.md | 26 + docs/examples/users/get-prefs.md | 26 + docs/examples/users/get-target.md | 27 + docs/examples/users/get.md | 26 + docs/examples/users/list-identities.md | 27 + docs/examples/users/list-logs.md | 27 + docs/examples/users/list-memberships.md | 26 + docs/examples/users/list-mfa-factors.md | 26 + docs/examples/users/list-sessions.md | 26 + docs/examples/users/list-targets.md | 27 + docs/examples/users/list.md | 27 + .../users/update-email-verification.md | 27 + docs/examples/users/update-email.md | 27 + docs/examples/users/update-labels.md | 27 + .../users/update-mfa-recovery-codes.md | 26 + docs/examples/users/update-mfa.md | 27 + docs/examples/users/update-name.md | 27 + docs/examples/users/update-password.md | 27 + .../users/update-phone-verification.md | 27 + docs/examples/users/update-phone.md | 27 + docs/examples/users/update-prefs.md | 27 + docs/examples/users/update-status.md | 27 + docs/examples/users/update-target.md | 30 + example/main.go | 41 + file/inputFile.go | 15 + functions/functions.go | 1419 ++++++ go.mod | 3 + graphql/graphql.go | 80 + health/health.go | 1054 +++++ id/id.go | 23 + locale/locale.go | 258 ++ messaging/messaging.go | 4038 +++++++++++++++++ models/algoargon2.go | 15 + models/algobcrypt.go | 9 + models/algomd5.go | 9 + models/algophpass.go | 9 + models/algoscrypt.go | 17 + models/algoscryptmodified.go | 15 + models/algosha.go | 9 + models/attributeboolean.go | 24 + models/attributedatetime.go | 25 + models/attributeemail.go | 26 + models/attributeenum.go | 28 + models/attributefloat.go | 28 + models/attributeinteger.go | 28 + models/attributeip.go | 26 + models/attributelist.go | 11 + models/attributerelationship.go | 33 + models/attributestring.go | 26 + models/attributeurl.go | 26 + models/bucket.go | 35 + models/bucketlist.go | 11 + models/build.go | 30 + models/collection.go | 31 + models/collectionlist.go | 11 + models/continent.go | 11 + models/continentlist.go | 11 + models/country.go | 11 + models/countrylist.go | 11 + models/currency.go | 22 + models/currencylist.go | 11 + models/database.go | 19 + models/databaselist.go | 11 + models/deployment.go | 54 + models/deploymentlist.go | 11 + models/document.go | 22 + models/documentlist.go | 11 + models/execution.go | 50 + models/executionlist.go | 11 + models/file.go | 30 + models/filelist.go | 11 + models/function.go | 59 + models/functionlist.go | 11 + models/headers.go | 11 + models/healthantivirus.go | 11 + models/healthcertificate.go | 19 + models/healthqueue.go | 9 + models/healthstatus.go | 13 + models/healthtime.go | 13 + models/identity.go | 27 + models/identitylist.go | 11 + models/index.go | 21 + models/indexlist.go | 11 + models/jwt.go | 9 + models/language.go | 13 + models/languagelist.go | 11 + models/locale.go | 25 + models/localecode.go | 12 + models/localecodelist.go | 11 + models/log.go | 51 + models/loglist.go | 11 + models/membership.go | 36 + models/membershiplist.go | 11 + models/message.go | 33 + models/messagelist.go | 11 + models/mfachallenge.go | 15 + models/mfafactors.go | 15 + models/mfarecoverycodes.go | 9 + models/mfatype.go | 11 + models/phone.go | 13 + models/phonelist.go | 11 + models/preferences.go | 9 + models/provider.go | 25 + models/providerlist.go | 11 + models/runtime.go | 21 + models/runtimelist.go | 11 + models/session.go | 69 + models/sessionlist.go | 11 + models/subscriber.go | 26 + models/subscriberlist.go | 11 + models/target.go | 24 + models/targetlist.go | 11 + models/team.go | 19 + models/teamlist.go | 11 + models/token.go | 22 + models/topic.go | 23 + models/topiclist.go | 11 + models/user.go | 47 + models/userlist.go | 11 + models/variable.go | 23 + models/variablelist.go | 11 + permission/permission.go | 23 + query/query.go | 242 + role/role.go | 42 + storage/storage.go | 926 ++++ teams/teams.go | 625 +++ users/users.go | 1892 ++++++++ 373 files changed, 24879 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 account/account.go create mode 100644 avatars/avatars.go create mode 100644 client/client.go create mode 100644 databases/databases.go create mode 100644 docs/examples/account/create-anonymous-session.md create mode 100644 docs/examples/account/create-email-password-session.md create mode 100644 docs/examples/account/create-email-token.md create mode 100644 docs/examples/account/create-j-w-t.md create mode 100644 docs/examples/account/create-magic-u-r-l-token.md create mode 100644 docs/examples/account/create-mfa-authenticator.md create mode 100644 docs/examples/account/create-mfa-challenge.md create mode 100644 docs/examples/account/create-mfa-recovery-codes.md create mode 100644 docs/examples/account/create-o-auth2token.md create mode 100644 docs/examples/account/create-phone-token.md create mode 100644 docs/examples/account/create-phone-verification.md create mode 100644 docs/examples/account/create-recovery.md create mode 100644 docs/examples/account/create-session.md create mode 100644 docs/examples/account/create-verification.md create mode 100644 docs/examples/account/create.md create mode 100644 docs/examples/account/delete-identity.md create mode 100644 docs/examples/account/delete-mfa-authenticator.md create mode 100644 docs/examples/account/delete-session.md create mode 100644 docs/examples/account/delete-sessions.md create mode 100644 docs/examples/account/get-mfa-recovery-codes.md create mode 100644 docs/examples/account/get-prefs.md create mode 100644 docs/examples/account/get-session.md create mode 100644 docs/examples/account/get.md create mode 100644 docs/examples/account/list-identities.md create mode 100644 docs/examples/account/list-logs.md create mode 100644 docs/examples/account/list-mfa-factors.md create mode 100644 docs/examples/account/list-sessions.md create mode 100644 docs/examples/account/update-email.md create mode 100644 docs/examples/account/update-m-f-a.md create mode 100644 docs/examples/account/update-magic-u-r-l-session.md create mode 100644 docs/examples/account/update-mfa-authenticator.md create mode 100644 docs/examples/account/update-mfa-challenge.md create mode 100644 docs/examples/account/update-mfa-recovery-codes.md create mode 100644 docs/examples/account/update-name.md create mode 100644 docs/examples/account/update-password.md create mode 100644 docs/examples/account/update-phone-session.md create mode 100644 docs/examples/account/update-phone-verification.md create mode 100644 docs/examples/account/update-phone.md create mode 100644 docs/examples/account/update-prefs.md create mode 100644 docs/examples/account/update-recovery.md create mode 100644 docs/examples/account/update-session.md create mode 100644 docs/examples/account/update-status.md create mode 100644 docs/examples/account/update-verification.md create mode 100644 docs/examples/avatars/get-browser.md create mode 100644 docs/examples/avatars/get-credit-card.md create mode 100644 docs/examples/avatars/get-favicon.md create mode 100644 docs/examples/avatars/get-flag.md create mode 100644 docs/examples/avatars/get-image.md create mode 100644 docs/examples/avatars/get-initials.md create mode 100644 docs/examples/avatars/get-q-r.md create mode 100644 docs/examples/databases/create-boolean-attribute.md create mode 100644 docs/examples/databases/create-collection.md create mode 100644 docs/examples/databases/create-datetime-attribute.md create mode 100644 docs/examples/databases/create-document.md create mode 100644 docs/examples/databases/create-email-attribute.md create mode 100644 docs/examples/databases/create-enum-attribute.md create mode 100644 docs/examples/databases/create-float-attribute.md create mode 100644 docs/examples/databases/create-index.md create mode 100644 docs/examples/databases/create-integer-attribute.md create mode 100644 docs/examples/databases/create-ip-attribute.md create mode 100644 docs/examples/databases/create-relationship-attribute.md create mode 100644 docs/examples/databases/create-string-attribute.md create mode 100644 docs/examples/databases/create-url-attribute.md create mode 100644 docs/examples/databases/create.md create mode 100644 docs/examples/databases/delete-attribute.md create mode 100644 docs/examples/databases/delete-collection.md create mode 100644 docs/examples/databases/delete-document.md create mode 100644 docs/examples/databases/delete-index.md create mode 100644 docs/examples/databases/delete.md create mode 100644 docs/examples/databases/get-attribute.md create mode 100644 docs/examples/databases/get-collection.md create mode 100644 docs/examples/databases/get-document.md create mode 100644 docs/examples/databases/get-index.md create mode 100644 docs/examples/databases/get.md create mode 100644 docs/examples/databases/list-attributes.md create mode 100644 docs/examples/databases/list-collections.md create mode 100644 docs/examples/databases/list-documents.md create mode 100644 docs/examples/databases/list-indexes.md create mode 100644 docs/examples/databases/list.md create mode 100644 docs/examples/databases/update-boolean-attribute.md create mode 100644 docs/examples/databases/update-collection.md create mode 100644 docs/examples/databases/update-datetime-attribute.md create mode 100644 docs/examples/databases/update-document.md create mode 100644 docs/examples/databases/update-email-attribute.md create mode 100644 docs/examples/databases/update-enum-attribute.md create mode 100644 docs/examples/databases/update-float-attribute.md create mode 100644 docs/examples/databases/update-integer-attribute.md create mode 100644 docs/examples/databases/update-ip-attribute.md create mode 100644 docs/examples/databases/update-relationship-attribute.md create mode 100644 docs/examples/databases/update-string-attribute.md create mode 100644 docs/examples/databases/update-url-attribute.md create mode 100644 docs/examples/databases/update.md create mode 100644 docs/examples/functions/create-build.md create mode 100644 docs/examples/functions/create-deployment.md create mode 100644 docs/examples/functions/create-execution.md create mode 100644 docs/examples/functions/create-variable.md create mode 100644 docs/examples/functions/create.md create mode 100644 docs/examples/functions/delete-deployment.md create mode 100644 docs/examples/functions/delete-execution.md create mode 100644 docs/examples/functions/delete-variable.md create mode 100644 docs/examples/functions/delete.md create mode 100644 docs/examples/functions/download-deployment.md create mode 100644 docs/examples/functions/get-deployment.md create mode 100644 docs/examples/functions/get-execution.md create mode 100644 docs/examples/functions/get-variable.md create mode 100644 docs/examples/functions/get.md create mode 100644 docs/examples/functions/list-deployments.md create mode 100644 docs/examples/functions/list-executions.md create mode 100644 docs/examples/functions/list-runtimes.md create mode 100644 docs/examples/functions/list-variables.md create mode 100644 docs/examples/functions/list.md create mode 100644 docs/examples/functions/update-deployment-build.md create mode 100644 docs/examples/functions/update-deployment.md create mode 100644 docs/examples/functions/update-variable.md create mode 100644 docs/examples/functions/update.md create mode 100644 docs/examples/graphql/mutation.md create mode 100644 docs/examples/graphql/query.md create mode 100644 docs/examples/health/get-antivirus.md create mode 100644 docs/examples/health/get-cache.md create mode 100644 docs/examples/health/get-certificate.md create mode 100644 docs/examples/health/get-d-b.md create mode 100644 docs/examples/health/get-failed-jobs.md create mode 100644 docs/examples/health/get-pub-sub.md create mode 100644 docs/examples/health/get-queue-builds.md create mode 100644 docs/examples/health/get-queue-certificates.md create mode 100644 docs/examples/health/get-queue-databases.md create mode 100644 docs/examples/health/get-queue-deletes.md create mode 100644 docs/examples/health/get-queue-functions.md create mode 100644 docs/examples/health/get-queue-logs.md create mode 100644 docs/examples/health/get-queue-mails.md create mode 100644 docs/examples/health/get-queue-messaging.md create mode 100644 docs/examples/health/get-queue-migrations.md create mode 100644 docs/examples/health/get-queue-usage-dump.md create mode 100644 docs/examples/health/get-queue-usage.md create mode 100644 docs/examples/health/get-queue-webhooks.md create mode 100644 docs/examples/health/get-queue.md create mode 100644 docs/examples/health/get-storage-local.md create mode 100644 docs/examples/health/get-storage.md create mode 100644 docs/examples/health/get-time.md create mode 100644 docs/examples/health/get.md create mode 100644 docs/examples/locale/get.md create mode 100644 docs/examples/locale/list-codes.md create mode 100644 docs/examples/locale/list-continents.md create mode 100644 docs/examples/locale/list-countries-e-u.md create mode 100644 docs/examples/locale/list-countries-phones.md create mode 100644 docs/examples/locale/list-countries.md create mode 100644 docs/examples/locale/list-currencies.md create mode 100644 docs/examples/locale/list-languages.md create mode 100644 docs/examples/messaging/create-apns-provider.md create mode 100644 docs/examples/messaging/create-email.md create mode 100644 docs/examples/messaging/create-fcm-provider.md create mode 100644 docs/examples/messaging/create-mailgun-provider.md create mode 100644 docs/examples/messaging/create-msg91provider.md create mode 100644 docs/examples/messaging/create-push.md create mode 100644 docs/examples/messaging/create-sendgrid-provider.md create mode 100644 docs/examples/messaging/create-sms.md create mode 100644 docs/examples/messaging/create-smtp-provider.md create mode 100644 docs/examples/messaging/create-subscriber.md create mode 100644 docs/examples/messaging/create-telesign-provider.md create mode 100644 docs/examples/messaging/create-textmagic-provider.md create mode 100644 docs/examples/messaging/create-topic.md create mode 100644 docs/examples/messaging/create-twilio-provider.md create mode 100644 docs/examples/messaging/create-vonage-provider.md create mode 100644 docs/examples/messaging/delete-provider.md create mode 100644 docs/examples/messaging/delete-subscriber.md create mode 100644 docs/examples/messaging/delete-topic.md create mode 100644 docs/examples/messaging/delete.md create mode 100644 docs/examples/messaging/get-message.md create mode 100644 docs/examples/messaging/get-provider.md create mode 100644 docs/examples/messaging/get-subscriber.md create mode 100644 docs/examples/messaging/get-topic.md create mode 100644 docs/examples/messaging/list-message-logs.md create mode 100644 docs/examples/messaging/list-messages.md create mode 100644 docs/examples/messaging/list-provider-logs.md create mode 100644 docs/examples/messaging/list-providers.md create mode 100644 docs/examples/messaging/list-subscriber-logs.md create mode 100644 docs/examples/messaging/list-subscribers.md create mode 100644 docs/examples/messaging/list-targets.md create mode 100644 docs/examples/messaging/list-topic-logs.md create mode 100644 docs/examples/messaging/list-topics.md create mode 100644 docs/examples/messaging/update-apns-provider.md create mode 100644 docs/examples/messaging/update-email.md create mode 100644 docs/examples/messaging/update-fcm-provider.md create mode 100644 docs/examples/messaging/update-mailgun-provider.md create mode 100644 docs/examples/messaging/update-msg91provider.md create mode 100644 docs/examples/messaging/update-push.md create mode 100644 docs/examples/messaging/update-sendgrid-provider.md create mode 100644 docs/examples/messaging/update-sms.md create mode 100644 docs/examples/messaging/update-smtp-provider.md create mode 100644 docs/examples/messaging/update-telesign-provider.md create mode 100644 docs/examples/messaging/update-textmagic-provider.md create mode 100644 docs/examples/messaging/update-topic.md create mode 100644 docs/examples/messaging/update-twilio-provider.md create mode 100644 docs/examples/messaging/update-vonage-provider.md create mode 100644 docs/examples/storage/create-bucket.md create mode 100644 docs/examples/storage/create-file.md create mode 100644 docs/examples/storage/delete-bucket.md create mode 100644 docs/examples/storage/delete-file.md create mode 100644 docs/examples/storage/get-bucket.md create mode 100644 docs/examples/storage/get-file-download.md create mode 100644 docs/examples/storage/get-file-preview.md create mode 100644 docs/examples/storage/get-file-view.md create mode 100644 docs/examples/storage/get-file.md create mode 100644 docs/examples/storage/list-buckets.md create mode 100644 docs/examples/storage/list-files.md create mode 100644 docs/examples/storage/update-bucket.md create mode 100644 docs/examples/storage/update-file.md create mode 100644 docs/examples/teams/create-membership.md create mode 100644 docs/examples/teams/create.md create mode 100644 docs/examples/teams/delete-membership.md create mode 100644 docs/examples/teams/delete.md create mode 100644 docs/examples/teams/get-membership.md create mode 100644 docs/examples/teams/get-prefs.md create mode 100644 docs/examples/teams/get.md create mode 100644 docs/examples/teams/list-memberships.md create mode 100644 docs/examples/teams/list.md create mode 100644 docs/examples/teams/update-membership-status.md create mode 100644 docs/examples/teams/update-membership.md create mode 100644 docs/examples/teams/update-name.md create mode 100644 docs/examples/teams/update-prefs.md create mode 100644 docs/examples/users/create-argon2user.md create mode 100644 docs/examples/users/create-bcrypt-user.md create mode 100644 docs/examples/users/create-j-w-t.md create mode 100644 docs/examples/users/create-m-d5user.md create mode 100644 docs/examples/users/create-mfa-recovery-codes.md create mode 100644 docs/examples/users/create-p-h-pass-user.md create mode 100644 docs/examples/users/create-s-h-a-user.md create mode 100644 docs/examples/users/create-scrypt-modified-user.md create mode 100644 docs/examples/users/create-scrypt-user.md create mode 100644 docs/examples/users/create-session.md create mode 100644 docs/examples/users/create-target.md create mode 100644 docs/examples/users/create-token.md create mode 100644 docs/examples/users/create.md create mode 100644 docs/examples/users/delete-identity.md create mode 100644 docs/examples/users/delete-mfa-authenticator.md create mode 100644 docs/examples/users/delete-session.md create mode 100644 docs/examples/users/delete-sessions.md create mode 100644 docs/examples/users/delete-target.md create mode 100644 docs/examples/users/delete.md create mode 100644 docs/examples/users/get-mfa-recovery-codes.md create mode 100644 docs/examples/users/get-prefs.md create mode 100644 docs/examples/users/get-target.md create mode 100644 docs/examples/users/get.md create mode 100644 docs/examples/users/list-identities.md create mode 100644 docs/examples/users/list-logs.md create mode 100644 docs/examples/users/list-memberships.md create mode 100644 docs/examples/users/list-mfa-factors.md create mode 100644 docs/examples/users/list-sessions.md create mode 100644 docs/examples/users/list-targets.md create mode 100644 docs/examples/users/list.md create mode 100644 docs/examples/users/update-email-verification.md create mode 100644 docs/examples/users/update-email.md create mode 100644 docs/examples/users/update-labels.md create mode 100644 docs/examples/users/update-mfa-recovery-codes.md create mode 100644 docs/examples/users/update-mfa.md create mode 100644 docs/examples/users/update-name.md create mode 100644 docs/examples/users/update-password.md create mode 100644 docs/examples/users/update-phone-verification.md create mode 100644 docs/examples/users/update-phone.md create mode 100644 docs/examples/users/update-prefs.md create mode 100644 docs/examples/users/update-status.md create mode 100644 docs/examples/users/update-target.md create mode 100644 example/main.go create mode 100644 file/inputFile.go create mode 100644 functions/functions.go create mode 100644 go.mod create mode 100644 graphql/graphql.go create mode 100644 health/health.go create mode 100644 id/id.go create mode 100644 locale/locale.go create mode 100644 messaging/messaging.go create mode 100644 models/algoargon2.go create mode 100644 models/algobcrypt.go create mode 100644 models/algomd5.go create mode 100644 models/algophpass.go create mode 100644 models/algoscrypt.go create mode 100644 models/algoscryptmodified.go create mode 100644 models/algosha.go create mode 100644 models/attributeboolean.go create mode 100644 models/attributedatetime.go create mode 100644 models/attributeemail.go create mode 100644 models/attributeenum.go create mode 100644 models/attributefloat.go create mode 100644 models/attributeinteger.go create mode 100644 models/attributeip.go create mode 100644 models/attributelist.go create mode 100644 models/attributerelationship.go create mode 100644 models/attributestring.go create mode 100644 models/attributeurl.go create mode 100644 models/bucket.go create mode 100644 models/bucketlist.go create mode 100644 models/build.go create mode 100644 models/collection.go create mode 100644 models/collectionlist.go create mode 100644 models/continent.go create mode 100644 models/continentlist.go create mode 100644 models/country.go create mode 100644 models/countrylist.go create mode 100644 models/currency.go create mode 100644 models/currencylist.go create mode 100644 models/database.go create mode 100644 models/databaselist.go create mode 100644 models/deployment.go create mode 100644 models/deploymentlist.go create mode 100644 models/document.go create mode 100644 models/documentlist.go create mode 100644 models/execution.go create mode 100644 models/executionlist.go create mode 100644 models/file.go create mode 100644 models/filelist.go create mode 100644 models/function.go create mode 100644 models/functionlist.go create mode 100644 models/headers.go create mode 100644 models/healthantivirus.go create mode 100644 models/healthcertificate.go create mode 100644 models/healthqueue.go create mode 100644 models/healthstatus.go create mode 100644 models/healthtime.go create mode 100644 models/identity.go create mode 100644 models/identitylist.go create mode 100644 models/index.go create mode 100644 models/indexlist.go create mode 100644 models/jwt.go create mode 100644 models/language.go create mode 100644 models/languagelist.go create mode 100644 models/locale.go create mode 100644 models/localecode.go create mode 100644 models/localecodelist.go create mode 100644 models/log.go create mode 100644 models/loglist.go create mode 100644 models/membership.go create mode 100644 models/membershiplist.go create mode 100644 models/message.go create mode 100644 models/messagelist.go create mode 100644 models/mfachallenge.go create mode 100644 models/mfafactors.go create mode 100644 models/mfarecoverycodes.go create mode 100644 models/mfatype.go create mode 100644 models/phone.go create mode 100644 models/phonelist.go create mode 100644 models/preferences.go create mode 100644 models/provider.go create mode 100644 models/providerlist.go create mode 100644 models/runtime.go create mode 100644 models/runtimelist.go create mode 100644 models/session.go create mode 100644 models/sessionlist.go create mode 100644 models/subscriber.go create mode 100644 models/subscriberlist.go create mode 100644 models/target.go create mode 100644 models/targetlist.go create mode 100644 models/team.go create mode 100644 models/teamlist.go create mode 100644 models/token.go create mode 100644 models/topic.go create mode 100644 models/topiclist.go create mode 100644 models/user.go create mode 100644 models/userlist.go create mode 100644 models/variable.go create mode 100644 models/variablelist.go create mode 100644 permission/permission.go create mode 100644 query/query.go create mode 100644 role/role.go create mode 100644 storage/storage.go create mode 100644 teams/teams.go create mode 100644 users/users.go diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..10d46c7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# # Change Log + +## 4.0.1 + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5479bb8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (c) 2024 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: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6770ab7 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +# 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.5.7-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.6.x. 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](https://github.com/appwrite/appwrite/raw/main/public/images/github.png) + +## Installation + +To install using `go get`: + +```bash +go get github.com/appwrite/sdk-for-go +``` + +## Testing the SDK + +* clone this repo. +* create a project and within this project a collection. +* configure the documents in the collection to have a _key_ = __hello__. +* Then inject these environment variables: + + ```bash + export YOUR_ENDPOINT=https://appwrite.io/v1 + export YOUR_PROJECT_ID=6…8 + export YOUR_KEY="7055781…cd95" + export COLLECTION_ID=616a095b20180 + ``` + +Create `main.go` file with: + +```go +package main + +import ( + "log" + "os" + "time" + + "github.com/appwrite/sdk-for-go/sdk-for-go" +) + +func main() { + client := sdk-for-go.NewClient(10 * time.Second) + client.SetEndpoint(os.Getenv("YOUR_ENDPOINT")) + client.SetProject(os.Getenv("YOUR_PROJECT_ID")) + client.SetKey(os.Getenv("YOUR_KEY")) + + db := sdk-for-go.NewDatabase(client) + data := map[string]string{ + "hello": "world", + } + var EmptyArray = []interface{}{} + doc, err := db.CreateDocument( + os.Getenv("COLLECTION_ID"), + data, + EmptyArray, + EmptyArray, + "", + "", + "", + ) + if err != nil { + log.Printf("Error creating document: %v", err) + } + log.Printf("Created document: %v", doc) +} +``` + +* After that, run the following + + > % go run main.go + > 2021/10/16 03:41:17 Created document: map[$collection:616a095b20180 $id:616a2dbd4df16 $permissions:map[read:[] write:[]] hello:world] + + +## Contribution + +This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request. + +## License + +Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. diff --git a/account/account.go b/account/account.go new file mode 100644 index 0000000..9b080f7 --- /dev/null +++ b/account/account.go @@ -0,0 +1,1666 @@ +package account + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Account service +type Account struct { + client client.Client +} + +func NewAccount(clt client.Client) *Account { + return &Account{ + client: clt, + } +} + + +// Get get the currently logged in user. +func (srv *Account) Get()(*models.User, error) { + path := "/account" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func WithCreateName(v string) CreateOption { + return func(o *CreateOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// Create use this endpoint to allow a new user to register a new account in +// your project. After the user registration completes successfully, you can +// use the +// [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) +// route to start verifying the user email address. To allow the new user to +// login to their new account, you need to create a new [account +// session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). +func (srv *Account) Create(UserId string, Email string, Password string, optionalSetters ...CreateOption)(*models.User, error) { + path := "/account" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateEmail update currently logged in user account email address. After +// changing user address, the user confirmation status will get reset. A new +// confirmation email is not sent automatically however you can use the send +// confirmation email endpoint again to send the confirmation email. For +// security measures, user password is required to complete this request. +// This endpoint can also be used to convert an anonymous account to a normal +// one, by passing an email address and a new password. +func (srv *Account) UpdateEmail(Email string, Password string)(*models.User, error) { + path := "/account/email" + params := map[string]interface{}{} + params["email"] = Email + params["password"] = Password + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListIdentitiesOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListIdentitiesOptions) New() *ListIdentitiesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListIdentitiesOption func(*ListIdentitiesOptions) +func WithListIdentitiesQueries(v []interface{}) ListIdentitiesOption { + return func(o *ListIdentitiesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListIdentities get the list of identities for the currently logged in user. +func (srv *Account) ListIdentities(optionalSetters ...ListIdentitiesOption)(*models.IdentityList, error) { + path := "/account/identities" + options := ListIdentitiesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.IdentityList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.IdentityList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteIdentity delete an identity by its unique ID. +func (srv *Account) DeleteIdentity(IdentityId string)(*interface{}, error) { + r := strings.NewReplacer("{identityId}", IdentityId) + path := r.Replace("/account/identities/{identityId}") + params := map[string]interface{}{} + params["identityId"] = IdentityId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// 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) { + path := "/account/jwts" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Jwt + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Jwt) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListLogsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListLogsOptions) New() *ListLogsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListLogsOption func(*ListLogsOptions) +func WithListLogsQueries(v []interface{}) ListLogsOption { + return func(o *ListLogsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListLogs get the list of latest security activity logs for the currently +// logged in user. Each log returns user IP address, location and date and +// time of log. +func (srv *Account) ListLogs(optionalSetters ...ListLogsOption)(*models.LogList, error) { + path := "/account/logs" + options := ListLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LogList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LogList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMFA enable or disable MFA on an account. +func (srv *Account) UpdateMFA(Mfa bool)(*models.User, error) { + path := "/account/mfa" + params := map[string]interface{}{} + params["mfa"] = Mfa + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateMfaAuthenticator add an authenticator app to be used as an MFA +// factor. Verify the authenticator using the [verify +// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) +// method. +func (srv *Account) CreateMfaAuthenticator(Type string)(*models.MfaType, error) { + r := strings.NewReplacer("{type}", Type) + path := r.Replace("/account/mfa/authenticators/{type}") + params := map[string]interface{}{} + params["type"] = Type + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaType + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaType) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMfaAuthenticator verify an authenticator app after adding it using +// the [add +// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) +// method. +func (srv *Account) UpdateMfaAuthenticator(Type string, Otp string)(*models.User, error) { + r := strings.NewReplacer("{type}", Type) + path := r.Replace("/account/mfa/authenticators/{type}") + params := map[string]interface{}{} + params["type"] = Type + params["otp"] = Otp + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteMfaAuthenticator delete an authenticator for a user by ID. +func (srv *Account) DeleteMfaAuthenticator(Type string, Otp string)(*interface{}, error) { + r := strings.NewReplacer("{type}", Type) + path := r.Replace("/account/mfa/authenticators/{type}") + params := map[string]interface{}{} + params["type"] = Type + params["otp"] = Otp + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateMfaChallenge begin the process of MFA verification after sign-in. +// Finish the flow with +// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) +// method. +func (srv *Account) CreateMfaChallenge(Factor string)(*models.MfaChallenge, error) { + path := "/account/mfa/challenge" + params := map[string]interface{}{} + params["factor"] = Factor + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaChallenge + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaChallenge) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMfaChallenge complete the MFA challenge by providing the one-time +// password. Finish the process of MFA verification by providing the one-time +// password. To begin the flow, use +// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) +// method. +func (srv *Account) UpdateMfaChallenge(ChallengeId string, Otp string)(*interface{}, error) { + path := "/account/mfa/challenge" + params := map[string]interface{}{} + params["challengeId"] = ChallengeId + params["otp"] = Otp + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListMfaFactors list the factors available on the account to be used as a +// MFA challange. +func (srv *Account) ListMfaFactors()(*models.MfaFactors, error) { + path := "/account/mfa/factors" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaFactors + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaFactors) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetMfaRecoveryCodes get recovery codes that can be used as backup for MFA +// flow. Before getting codes, they must be generated using +// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) +// method. An OTP challenge is required to read recovery codes. +func (srv *Account) GetMfaRecoveryCodes()(*models.MfaRecoveryCodes, error) { + path := "/account/mfa/recovery-codes" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaRecoveryCodes + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaRecoveryCodes) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateMfaRecoveryCodes generate recovery codes as backup for MFA flow. It's +// recommended to generate and show then immediately after user successfully +// adds their authehticator. Recovery codes can be used as a MFA verification +// type in +// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) +// method. +func (srv *Account) CreateMfaRecoveryCodes()(*models.MfaRecoveryCodes, error) { + path := "/account/mfa/recovery-codes" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaRecoveryCodes + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaRecoveryCodes) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMfaRecoveryCodes regenerate recovery codes that can be used as backup +// for MFA flow. Before regenerating codes, they must be first generated using +// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) +// method. An OTP challenge is required to regenreate recovery codes. +func (srv *Account) UpdateMfaRecoveryCodes()(*models.MfaRecoveryCodes, error) { + path := "/account/mfa/recovery-codes" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaRecoveryCodes + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaRecoveryCodes) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateName update currently logged in user account name. +func (srv *Account) UpdateName(Name string)(*models.User, error) { + path := "/account/name" + params := map[string]interface{}{} + params["name"] = Name + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdatePasswordOptions struct { + OldPassword string + enabledSetters map[string]bool +} +func (options UpdatePasswordOptions) New() *UpdatePasswordOptions { + options.enabledSetters = map[string]bool{ + "OldPassword": false, + } + return &options +} +type UpdatePasswordOption func(*UpdatePasswordOptions) +func WithUpdatePasswordOldPassword(v string) UpdatePasswordOption { + return func(o *UpdatePasswordOptions) { + o.OldPassword = v + o.enabledSetters["OldPassword"] = true + } +} + +// UpdatePassword update currently logged in user password. For validation, +// user is required to pass in the new password, and the old password. For +// users created with OAuth, Team Invites and Magic URL, oldPassword is +// optional. +func (srv *Account) UpdatePassword(Password string, optionalSetters ...UpdatePasswordOption)(*models.User, error) { + path := "/account/password" + options := UpdatePasswordOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["password"] = Password + if options.enabledSetters["OldPassword"] { + params["oldPassword"] = options.OldPassword + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePhone update the currently logged in user's phone number. After +// updating the phone number, the phone verification status will be reset. A +// confirmation SMS is not sent automatically, however you can use the [POST +// /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) +// endpoint to send a confirmation SMS. +func (srv *Account) UpdatePhone(Phone string, Password string)(*models.User, error) { + path := "/account/phone" + params := map[string]interface{}{} + params["phone"] = Phone + params["password"] = Password + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPrefs get the preferences as a key-value object for the currently logged +// in user. +func (srv *Account) GetPrefs()(*models.Preferences, error) { + path := "/account/prefs" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Preferences + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Preferences) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePrefs update currently logged in user account preferences. The object +// you pass is stored as is, and replaces any previous value. The maximum +// allowed prefs size is 64kB and throws error if exceeded. +func (srv *Account) UpdatePrefs(Prefs interface{})(*models.User, error) { + path := "/account/prefs" + params := map[string]interface{}{} + params["prefs"] = Prefs + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateRecovery sends the user an email with a temporary secret key for +// password reset. When the user clicks the confirmation link he is redirected +// back to your app password reset URL with the secret key and email address +// values attached to the URL query string. Use the query string params to +// submit a request to the [PUT +// /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) +// endpoint to complete the process. The verification link sent to the user's +// email address is valid for 1 hour. +func (srv *Account) CreateRecovery(Email string, Url string)(*models.Token, error) { + path := "/account/recovery" + params := map[string]interface{}{} + params["email"] = Email + params["url"] = Url + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateRecovery use this endpoint to complete the user account password +// reset. Both the **userId** and **secret** arguments will be passed as query +// parameters to the redirect URL you have provided when sending your request +// to the [POST +// /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) +// endpoint. +// +// Please note that in order to avoid a [Redirect +// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) +// the only valid redirect URLs are the ones from domains you have set when +// adding your platforms in the console interface. +func (srv *Account) UpdateRecovery(UserId string, Secret string, Password string)(*models.Token, error) { + path := "/account/recovery" + params := map[string]interface{}{} + params["userId"] = UserId + params["secret"] = Secret + params["password"] = Password + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListSessions get the list of active sessions across different devices for +// the currently logged in user. +func (srv *Account) ListSessions()(*models.SessionList, error) { + path := "/account/sessions" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.SessionList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.SessionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteSessions delete all sessions from the user account and remove any +// sessions cookies from the end client. +func (srv *Account) DeleteSessions()(*interface{}, error) { + path := "/account/sessions" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateAnonymousSession use this endpoint to allow a new user to register an +// anonymous account in your project. This route will also create a new +// session for the user. To allow the new user to convert an anonymous account +// to a normal account, you need to update its [email and +// password](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) +// or create an [OAuth2 +// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). +func (srv *Account) CreateAnonymousSession()(*models.Session, error) { + path := "/account/sessions/anonymous" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateEmailPasswordSession allow the user to login into their account by +// providing a valid email and password combination. This route will create a +// new session for the user. +// +// A user is limited to 10 active sessions at a time by default. [Learn more +// about session +// limits](https://appwrite.io/docs/authentication-security#limits). +func (srv *Account) CreateEmailPasswordSession(Email string, Password string)(*models.Session, error) { + path := "/account/sessions/email" + params := map[string]interface{}{} + params["email"] = Email + params["password"] = Password + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMagicURLSession use this endpoint to create a session from token. +// Provide the **userId** and **secret** parameters from the successful +// response of authentication flows initiated by token creation. For example, +// magic URL and phone login. +func (srv *Account) UpdateMagicURLSession(UserId string, Secret string)(*models.Session, error) { + path := "/account/sessions/magic-url" + params := map[string]interface{}{} + params["userId"] = UserId + params["secret"] = Secret + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePhoneSession use this endpoint to create a session from token. +// Provide the **userId** and **secret** parameters from the successful +// response of authentication flows initiated by token creation. For example, +// magic URL and phone login. +func (srv *Account) UpdatePhoneSession(UserId string, Secret string)(*models.Session, error) { + path := "/account/sessions/phone" + params := map[string]interface{}{} + params["userId"] = UserId + params["secret"] = Secret + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateSession use this endpoint to create a session from token. Provide the +// **userId** and **secret** parameters from the successful response of +// authentication flows initiated by token creation. For example, magic URL +// and phone login. +func (srv *Account) CreateSession(UserId string, Secret string)(*models.Session, error) { + path := "/account/sessions/token" + params := map[string]interface{}{} + params["userId"] = UserId + params["secret"] = Secret + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetSession use this endpoint to get a logged in user's session using a +// Session ID. Inputting 'current' will return the current session being used. +func (srv *Account) GetSession(SessionId string)(*models.Session, error) { + r := strings.NewReplacer("{sessionId}", SessionId) + path := r.Replace("/account/sessions/{sessionId}") + params := map[string]interface{}{} + params["sessionId"] = SessionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateSession use this endpoint to extend a session's length. Extending a +// session is useful when session expiry is short. If the session was created +// using an OAuth provider, this endpoint refreshes the access token from the +// provider. +func (srv *Account) UpdateSession(SessionId string)(*models.Session, error) { + r := strings.NewReplacer("{sessionId}", SessionId) + path := r.Replace("/account/sessions/{sessionId}") + params := map[string]interface{}{} + params["sessionId"] = SessionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteSession logout the user. Use 'current' as the session ID to logout on +// this device, use a session ID to logout on another device. If you're +// looking to logout the user on all devices, use [Delete +// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) +// instead. +func (srv *Account) DeleteSession(SessionId string)(*interface{}, error) { + r := strings.NewReplacer("{sessionId}", SessionId) + path := r.Replace("/account/sessions/{sessionId}") + params := map[string]interface{}{} + params["sessionId"] = SessionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateStatus block the currently logged in user account. Behind the scene, +// the user record is not deleted but permanently blocked from any access. To +// completely delete a user, use the Users API instead. +func (srv *Account) UpdateStatus()(*models.User, error) { + path := "/account/status" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateEmailTokenOptions struct { + Phrase bool + enabledSetters map[string]bool +} +func (options CreateEmailTokenOptions) New() *CreateEmailTokenOptions { + options.enabledSetters = map[string]bool{ + "Phrase": false, + } + return &options +} +type CreateEmailTokenOption func(*CreateEmailTokenOptions) +func WithCreateEmailTokenPhrase(v bool) CreateEmailTokenOption { + return func(o *CreateEmailTokenOptions) { + o.Phrase = v + o.enabledSetters["Phrase"] = true + } +} + +// CreateEmailToken sends the user an email with a secret key for creating a +// session. If the provided user ID has not be registered, a new user will be +// created. Use the returned user ID and secret and submit a request to the +// [POST +// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) +// endpoint to complete the login process. The secret sent to the user's email +// is valid for 15 minutes. +// +// A user is limited to 10 active sessions at a time by default. [Learn more +// about session +// limits](https://appwrite.io/docs/authentication-security#limits). +func (srv *Account) CreateEmailToken(UserId string, Email string, optionalSetters ...CreateEmailTokenOption)(*models.Token, error) { + path := "/account/tokens/email" + options := CreateEmailTokenOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + if options.enabledSetters["Phrase"] { + params["phrase"] = options.Phrase + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateMagicURLTokenOptions struct { + Url string + Phrase bool + enabledSetters map[string]bool +} +func (options CreateMagicURLTokenOptions) New() *CreateMagicURLTokenOptions { + options.enabledSetters = map[string]bool{ + "Url": false, + "Phrase": false, + } + return &options +} +type CreateMagicURLTokenOption func(*CreateMagicURLTokenOptions) +func WithCreateMagicURLTokenUrl(v string) CreateMagicURLTokenOption { + return func(o *CreateMagicURLTokenOptions) { + o.Url = v + o.enabledSetters["Url"] = true + } +} +func WithCreateMagicURLTokenPhrase(v bool) CreateMagicURLTokenOption { + return func(o *CreateMagicURLTokenOptions) { + o.Phrase = v + o.enabledSetters["Phrase"] = true + } +} + +// CreateMagicURLToken sends the user an email with a secret key for creating +// a session. If the provided user ID has not been registered, a new user will +// be created. When the user clicks the link in the email, the user is +// redirected back to the URL you provided with the secret key and userId +// values attached to the URL query string. Use the query string parameters to +// submit a request to the [POST +// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) +// endpoint to complete the login process. The link sent to the user's email +// address is valid for 1 hour. If you are on a mobile device you can leave +// the URL parameter empty, so that the login completion will be handled by +// your Appwrite instance by default. +// +// A user is limited to 10 active sessions at a time by default. [Learn more +// about session +// limits](https://appwrite.io/docs/authentication-security#limits). +func (srv *Account) CreateMagicURLToken(UserId string, Email string, optionalSetters ...CreateMagicURLTokenOption)(*models.Token, error) { + path := "/account/tokens/magic-url" + options := CreateMagicURLTokenOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + if options.enabledSetters["Url"] { + params["url"] = options.Url + } + if options.enabledSetters["Phrase"] { + params["phrase"] = options.Phrase + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateOAuth2TokenOptions struct { + Success string + Failure string + Scopes []interface{} + enabledSetters map[string]bool +} +func (options CreateOAuth2TokenOptions) New() *CreateOAuth2TokenOptions { + options.enabledSetters = map[string]bool{ + "Success": false, + "Failure": false, + "Scopes": false, + } + return &options +} +type CreateOAuth2TokenOption func(*CreateOAuth2TokenOptions) +func WithCreateOAuth2TokenSuccess(v string) CreateOAuth2TokenOption { + return func(o *CreateOAuth2TokenOptions) { + o.Success = v + o.enabledSetters["Success"] = true + } +} +func WithCreateOAuth2TokenFailure(v string) CreateOAuth2TokenOption { + return func(o *CreateOAuth2TokenOptions) { + o.Failure = v + o.enabledSetters["Failure"] = true + } +} +func WithCreateOAuth2TokenScopes(v []interface{}) CreateOAuth2TokenOption { + return func(o *CreateOAuth2TokenOptions) { + o.Scopes = v + o.enabledSetters["Scopes"] = true + } +} + +// CreateOAuth2Token allow the user to login to their account using the OAuth2 +// provider of their choice. Each OAuth2 provider should be enabled from the +// Appwrite console first. Use the success and failure arguments to provide a +// redirect URL's back to your app when login is completed. +// +// If authentication succeeds, `userId` and `secret` of a token will be +// appended to the success URL as query parameters. These can be used to +// create a new session using the [Create +// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) +// endpoint. +// +// A user is limited to 10 active sessions at a time by default. [Learn more +// about session +// limits](https://appwrite.io/docs/authentication-security#limits). +func (srv *Account) CreateOAuth2Token(Provider string, optionalSetters ...CreateOAuth2TokenOption)(*bool, error) { + r := strings.NewReplacer("{provider}", Provider) + path := r.Replace("/account/tokens/oauth2/{provider}") + options := CreateOAuth2TokenOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["provider"] = Provider + if options.enabledSetters["Success"] { + params["success"] = options.Success + } + if options.enabledSetters["Failure"] { + params["failure"] = options.Failure + } + if options.enabledSetters["Scopes"] { + params["scopes"] = options.Scopes + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed bool + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(bool) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreatePhoneToken sends the user an SMS with a secret key for creating a +// session. If the provided user ID has not be registered, a new user will be +// created. Use the returned user ID and secret and submit a request to the +// [POST +// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) +// endpoint to complete the login process. The secret sent to the user's phone +// is valid for 15 minutes. +// +// A user is limited to 10 active sessions at a time by default. [Learn more +// about session +// limits](https://appwrite.io/docs/authentication-security#limits). +func (srv *Account) CreatePhoneToken(UserId string, Phone string)(*models.Token, error) { + path := "/account/tokens/phone" + params := map[string]interface{}{} + params["userId"] = UserId + params["phone"] = Phone + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateVerification use this endpoint to send a verification message to your +// user email address to confirm they are the valid owners of that address. +// Both the **userId** and **secret** arguments will be passed as query +// parameters to the URL you have provided to be attached to the verification +// email. The provided URL should redirect the user back to your app and allow +// you to complete the verification process by verifying both the **userId** +// and **secret** parameters. Learn more about how to [complete the +// verification +// process](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). +// The verification link sent to the user's email address is valid for 7 days. +// +// Please note that in order to avoid a [Redirect +// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), +// the only valid redirect URLs are the ones from domains you have set when +// adding your platforms in the console interface. +func (srv *Account) CreateVerification(Url string)(*models.Token, error) { + path := "/account/verification" + params := map[string]interface{}{} + params["url"] = Url + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateVerification use this endpoint to complete the user email +// verification process. Use both the **userId** and **secret** parameters +// that were attached to your app URL to verify the user email ownership. If +// confirmed this route will return a 200 status code. +func (srv *Account) UpdateVerification(UserId string, Secret string)(*models.Token, error) { + path := "/account/verification" + params := map[string]interface{}{} + params["userId"] = UserId + params["secret"] = Secret + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreatePhoneVerification use this endpoint to send a verification SMS to the +// currently logged in user. This endpoint is meant for use after updating a +// user's phone number using the +// [accountUpdatePhone](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) +// endpoint. Learn more about how to [complete the verification +// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). +// The verification code sent to the user's phone number is valid for 15 +// minutes. +func (srv *Account) CreatePhoneVerification()(*models.Token, error) { + path := "/account/verification/phone" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePhoneVerification use this endpoint to complete the user phone +// verification process. Use the **userId** and **secret** that were sent to +// your user's phone number to verify the user email ownership. If confirmed +// this route will return a 200 status code. +func (srv *Account) UpdatePhoneVerification(UserId string, Secret string)(*models.Token, error) { + path := "/account/verification/phone" + params := map[string]interface{}{} + params["userId"] = UserId + params["secret"] = Secret + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/avatars/avatars.go b/avatars/avatars.go new file mode 100644 index 0000000..679ed63 --- /dev/null +++ b/avatars/avatars.go @@ -0,0 +1,557 @@ +package avatars + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "strings" +) + +// Avatars service +type Avatars struct { + client client.Client +} + +func NewAvatars(clt client.Client) *Avatars { + return &Avatars{ + client: clt, + } +} + + +type GetBrowserOptions struct { + Width int + Height int + Quality int + enabledSetters map[string]bool +} +func (options GetBrowserOptions) New() *GetBrowserOptions { + options.enabledSetters = map[string]bool{ + "Width": false, + "Height": false, + "Quality": false, + } + return &options +} +type GetBrowserOption func(*GetBrowserOptions) +func WithGetBrowserWidth(v int) GetBrowserOption { + return func(o *GetBrowserOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func WithGetBrowserHeight(v int) GetBrowserOption { + return func(o *GetBrowserOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} +func WithGetBrowserQuality(v int) GetBrowserOption { + return func(o *GetBrowserOptions) { + o.Quality = v + o.enabledSetters["Quality"] = true + } +} + +// GetBrowser you can use this endpoint to show different browser icons to +// your users. The code argument receives the browser code as it appears in +// your user [GET +// /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) +// endpoint. Use width, height and quality arguments to change the output +// settings. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +func (srv *Avatars) GetBrowser(Code string, optionalSetters ...GetBrowserOption)(*[]byte, error) { + r := strings.NewReplacer("{code}", Code) + path := r.Replace("/avatars/browsers/{code}") + options := GetBrowserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["code"] = Code + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + if options.enabledSetters["Quality"] { + params["quality"] = options.Quality + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetCreditCardOptions struct { + Width int + Height int + Quality int + enabledSetters map[string]bool +} +func (options GetCreditCardOptions) New() *GetCreditCardOptions { + options.enabledSetters = map[string]bool{ + "Width": false, + "Height": false, + "Quality": false, + } + return &options +} +type GetCreditCardOption func(*GetCreditCardOptions) +func WithGetCreditCardWidth(v int) GetCreditCardOption { + return func(o *GetCreditCardOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func WithGetCreditCardHeight(v int) GetCreditCardOption { + return func(o *GetCreditCardOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} +func WithGetCreditCardQuality(v int) GetCreditCardOption { + return func(o *GetCreditCardOptions) { + o.Quality = v + o.enabledSetters["Quality"] = true + } +} + +// GetCreditCard the credit card endpoint will return you the icon of the +// credit card provider you need. Use width, height and quality arguments to +// change the output settings. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +func (srv *Avatars) GetCreditCard(Code string, optionalSetters ...GetCreditCardOption)(*[]byte, error) { + r := strings.NewReplacer("{code}", Code) + path := r.Replace("/avatars/credit-cards/{code}") + options := GetCreditCardOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["code"] = Code + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + if options.enabledSetters["Quality"] { + params["quality"] = options.Quality + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetFavicon use this endpoint to fetch the favorite icon (AKA favicon) of +// any remote website URL. +func (srv *Avatars) GetFavicon(Url string)(*[]byte, error) { + path := "/avatars/favicon" + params := map[string]interface{}{} + params["url"] = Url + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetFlagOptions struct { + Width int + Height int + Quality int + enabledSetters map[string]bool +} +func (options GetFlagOptions) New() *GetFlagOptions { + options.enabledSetters = map[string]bool{ + "Width": false, + "Height": false, + "Quality": false, + } + return &options +} +type GetFlagOption func(*GetFlagOptions) +func WithGetFlagWidth(v int) GetFlagOption { + return func(o *GetFlagOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func WithGetFlagHeight(v int) GetFlagOption { + return func(o *GetFlagOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} +func WithGetFlagQuality(v int) GetFlagOption { + return func(o *GetFlagOptions) { + o.Quality = v + o.enabledSetters["Quality"] = true + } +} + +// GetFlag you can use this endpoint to show different country flags icons to +// your users. The code argument receives the 2 letter country code. Use +// width, height and quality arguments to change the output settings. Country +// codes follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) +// standard. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +func (srv *Avatars) GetFlag(Code string, optionalSetters ...GetFlagOption)(*[]byte, error) { + r := strings.NewReplacer("{code}", Code) + path := r.Replace("/avatars/flags/{code}") + options := GetFlagOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["code"] = Code + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + if options.enabledSetters["Quality"] { + params["quality"] = options.Quality + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetImageOptions struct { + Width int + Height int + enabledSetters map[string]bool +} +func (options GetImageOptions) New() *GetImageOptions { + options.enabledSetters = map[string]bool{ + "Width": false, + "Height": false, + } + return &options +} +type GetImageOption func(*GetImageOptions) +func WithGetImageWidth(v int) GetImageOption { + return func(o *GetImageOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func WithGetImageHeight(v int) GetImageOption { + return func(o *GetImageOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} + +// GetImage use this endpoint to fetch a remote image URL and crop it to any +// image size you want. This endpoint is very useful if you need to crop and +// display remote images in your app or in case you want to make sure a 3rd +// party image is properly served using a TLS protocol. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 400x400px. +func (srv *Avatars) GetImage(Url string, optionalSetters ...GetImageOption)(*[]byte, error) { + path := "/avatars/image" + options := GetImageOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["url"] = Url + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetInitialsOptions struct { + Name string + Width int + Height int + Background string + enabledSetters map[string]bool +} +func (options GetInitialsOptions) New() *GetInitialsOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Width": false, + "Height": false, + "Background": false, + } + return &options +} +type GetInitialsOption func(*GetInitialsOptions) +func WithGetInitialsName(v string) GetInitialsOption { + return func(o *GetInitialsOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithGetInitialsWidth(v int) GetInitialsOption { + return func(o *GetInitialsOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func WithGetInitialsHeight(v int) GetInitialsOption { + return func(o *GetInitialsOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} +func WithGetInitialsBackground(v string) GetInitialsOption { + return func(o *GetInitialsOptions) { + o.Background = v + o.enabledSetters["Background"] = true + } +} + +// GetInitials use this endpoint to show your user initials avatar icon on +// your website or app. By default, this route will try to print your +// logged-in user name or email initials. You can also overwrite the user name +// if you pass the 'name' parameter. If no name is given and no user is +// logged, an empty avatar will be returned. +// +// You can use the color and background params to change the avatar colors. By +// default, a random theme will be selected. The random theme will persist for +// the user's initials when reloading the same theme will always return for +// the same initials. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +func (srv *Avatars) GetInitials(optionalSetters ...GetInitialsOption)(*[]byte, error) { + path := "/avatars/initials" + options := GetInitialsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + if options.enabledSetters["Background"] { + params["background"] = options.Background + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQROptions struct { + Size int + Margin int + Download bool + enabledSetters map[string]bool +} +func (options GetQROptions) New() *GetQROptions { + options.enabledSetters = map[string]bool{ + "Size": false, + "Margin": false, + "Download": false, + } + return &options +} +type GetQROption func(*GetQROptions) +func WithGetQRSize(v int) GetQROption { + return func(o *GetQROptions) { + o.Size = v + o.enabledSetters["Size"] = true + } +} +func WithGetQRMargin(v int) GetQROption { + return func(o *GetQROptions) { + o.Margin = v + o.enabledSetters["Margin"] = true + } +} +func WithGetQRDownload(v bool) GetQROption { + return func(o *GetQROptions) { + o.Download = v + o.enabledSetters["Download"] = true + } +} + +// GetQR converts a given plain text to a QR code image. You can use the query +// parameters to change the size and style of the resulting image. +func (srv *Avatars) GetQR(Text string, optionalSetters ...GetQROption)(*[]byte, error) { + path := "/avatars/qr" + options := GetQROptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["text"] = Text + if options.enabledSetters["Size"] { + params["size"] = options.Size + } + if options.enabledSetters["Margin"] { + params["margin"] = options.Margin + } + if options.enabledSetters["Download"] { + params["download"] = options.Download + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/client/client.go b/client/client.go new file mode 100644 index 0000000..a8649c3 --- /dev/null +++ b/client/client.go @@ -0,0 +1,492 @@ +package client + +import ( + "bytes" + "crypto/tls" + "encoding/json" + "errors" + "fmt" + "io" + "io/ioutil" + "mime/multipart" + "net/http" + "net/http/cookiejar" + "net/url" + "os" + "reflect" + "strconv" + "strings" + "time" + "runtime" + "github.com/appwrite/sdk-for-go/file" +) + +const ( + fileNameKey = "file" + defaultTimeout = 10 * time.Second + defaultChunkSize = 5 * 1024 * 1024 +) + +// AppwriteError represents an error of a client request +type AppwriteError struct { + statusCode int + message string +} + +// ClientResponse - represents the client response +type ClientResponse struct { + Status string + StatusCode int + Header http.Header + Result interface{} + Type string +} + +func (ce *AppwriteError) Error() string { + return ce.message +} + +func (ce *AppwriteError) GetMessage() string { + return ce.message +} + +func (ce *AppwriteError) GetStatusCode() int { + return ce.statusCode +} + +// Client is the client struct to access Appwrite services +type Client struct { + client *http.Client + headers map[string]string + endpoint string + timeout time.Duration + selfSigned bool + chunkSize int64 +} + +// NewClient initializes a new Appwrite client with a given timeout +func NewClient() Client { + headers := map[string]string{ + "X-Appwrite-Response-Format" : "1.5.0", + "user-agent" : fmt.Sprintf("AppwriteGoSDK/4.0.1 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "x-sdk-name": "Go", + "x-sdk-platform": "server", + "x-sdk-language": "go", + "x-sdk-version": "4.0.1", + } + httpClient, err := getDefaultClient(defaultTimeout) + if err != nil { + panic(err) + } + return Client{ + endpoint: "https://cloud.appwrite.io/v1", + client: httpClient, + timeout: defaultTimeout, + headers: headers, + chunkSize: defaultChunkSize, + } +} + +func (clt *Client) String() string { + return fmt.Sprintf("%s\n%s\n%v", clt.endpoint, clt.headers, clt.timeout) +} + +func getDefaultClient(timeout time.Duration) (*http.Client, error) { + jar, err := cookiejar.New(nil) + if err != nil { + return nil, err + } + return &http.Client{ + Jar: jar, + Timeout: timeout, + }, nil +} + +func (clt *Client) SetTimeout(timeout time.Duration) error { + clt.timeout = timeout + httpClient, err := getDefaultClient(timeout) + if err != nil { + return err + } + clt.client = httpClient + return nil +} + +// SetEndpoint sets the default endpoint to which the Client connects to +func (clt *Client) SetEndpoint(endpoint string) { + clt.endpoint = endpoint +} + +// SetSelfSigned sets the condition that specify if the Client should allow connections to a server using a self-signed certificate +func (clt *Client) SetSelfSigned(status bool) { + clt.selfSigned = status +} + +// SetChunkSize sets the chunk size for file upload +func (clt *Client) SetChunkSize(size int64) { + clt.chunkSize = size +} + +// AddHeader add a new custom header that the Client should send on each request +func (clt *Client) AddHeader(key string, value string) { + clt.headers[key] = value +} + +// Your project ID +func (clt *Client) SetProject(value string) { + clt.headers["X-Appwrite-Project"] = value +} + +// Your secret API key +func (clt *Client) SetKey(value string) { + clt.headers["X-Appwrite-Key"] = value +} + +// Your secret JSON Web Token +func (clt *Client) SetJWT(value string) { + clt.headers["X-Appwrite-JWT"] = value +} + +func (clt *Client) SetLocale(value string) { + clt.headers["X-Appwrite-Locale"] = value +} + +// The user session to authenticate with +func (clt *Client) SetSession(value string) { + clt.headers["X-Appwrite-Session"] = value +} + +// The user agent string of the client that made the request +func (clt *Client) SetForwardedUserAgent(value string) { + clt.headers["X-Forwarded-User-Agent"] = value +} + +func isFileUpload(headers map[string]interface{}) bool { + contentType, ok := headers["content-type"].(string) + if ok { + return strings.Contains(strings.ToLower(contentType), "multipart/form-data") + } + return false +} + +func (clt *Client) FileUpload(url string, headers map[string]interface{}, params map[string]interface{}, paramName string, uploadId string) (*ClientResponse, error) { + inputFile, ok := params[paramName].(file.InputFile) + if !ok { + msg := fmt.Sprintf("invalid input file. params[%s] must be of type file.InputFile", paramName) + return nil, errors.New(msg) + } + + file, err := os.Open(inputFile.Path) + if err != nil { + return nil, err + } + defer file.Close() + + fileInfo, err := file.Stat() + if err != nil { + return nil, err + } + + inputFile.Data = make([]byte, clt.chunkSize) + + var result *ClientResponse + + numChunks := fileInfo.Size() / clt.chunkSize + if fileInfo.Size()%clt.chunkSize != 0 { + numChunks++ + } + var currentChunk int64 = 0 + if uploadId != "" && uploadId != "unique()" { + resp, err := clt.Call("GET", url+"/"+uploadId, nil, nil) + if err == nil { + currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64)) + } + } + for i := currentChunk; i < numChunks; i++ { + chunkSize := clt.chunkSize + offset := int64(i) * chunkSize + if i == numChunks-1 { + chunkSize = fileInfo.Size() - offset + inputFile.Data = make([]byte, chunkSize) + } + _, err := file.ReadAt(inputFile.Data, offset) + if err != nil && err != io.EOF { + return nil, err + } + params[paramName] = inputFile + if uploadId != "" && uploadId != "unique()" { + headers["x-appwrite-id"] = uploadId + } + totalSize := fileInfo.Size() + start := offset + end := offset + clt.chunkSize - 1 + if end >= totalSize { + end = totalSize - 1 + } + headers["content-range"] = fmt.Sprintf("bytes %d-%d/%d", start, end, totalSize) + result, err = clt.Call("POST", url, headers, params) + if err != nil { + return nil, err + } + + var parsed map[string]interface{} + if strings.HasPrefix(result.Type, "application/json") { + err = json.Unmarshal([]byte(result.Result.(string)), &parsed) + if err == nil { + uploadId, _ = parsed["$id"].(string) + } + } + } + return result, nil +} + +// Call an API using Client +func (clt *Client) Call(method string, path string, headers map[string]interface{}, params map[string]interface{}) (*ClientResponse, error) { + if clt.client == nil { + // Create HTTP client + httpClient, err := getDefaultClient(clt.timeout) + if err != nil { + panic(err) + } + clt.client = httpClient + } + + if clt.selfSigned { + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } + + urlPath := clt.endpoint + path + isGet := strings.ToUpper(method) == "GET" + isPost := strings.ToUpper(method) == "POST" + isJsonRequest := headers["content-type"] == "application/json" + isFileUpload := isFileUpload(headers) + + var req *http.Request + var err error + if isFileUpload { + if !isPost { + return nil, errors.New("fileupload needs POST Request") + } + var body bytes.Buffer + writer := multipart.NewWriter(&body) + for key, val := range params { + if file, ok := val.(file.InputFile); ok { + fileName := file.Name + fileData := file.Data + fw, err := writer.CreateFormFile(key, fileName) + if err != nil { + return nil, err + } + _, err = io.Copy(fw, bytes.NewReader(fileData)) + if err != nil { + return nil, err + } + delete(params, key) + } + } + flatParams := make(map[string]string) + flatten(params, "", &flatParams) + for key, val := range flatParams { + err = writer.WriteField(key, val) + if err != nil { + return nil, err + } + } + err = writer.Close() + if err != nil { + return nil, err + } + req, err = http.NewRequest(method, urlPath, &body) + if err != nil { + return nil, err + } + headers["content-type"] = writer.FormDataContentType() + } else { + if !isGet { + var reqBody *strings.Reader + if isJsonRequest { + json, err := json.Marshal(params) + if err != nil { + return nil, err + } + reqBody = strings.NewReader(string(json)) + } else { + frm := url.Values{} + for key, val := range params { + frm.Add(key, toString(val)) + } + reqBody = strings.NewReader(frm.Encode()) + } + // Create and modify HTTP request before sending + req, err = http.NewRequest(method, urlPath, reqBody) + if err != nil { + return nil, err + } + } else { + req, err = http.NewRequest(method, urlPath, nil) + if err != nil { + return nil, err + } + } + + if isGet { + q := req.URL.Query() + for key, val := range params { + rt := reflect.TypeOf(val) + switch rt.Kind() { + case reflect.Array: + case reflect.Slice: + arr := reflect.ValueOf(val) + for i := 0; i < arr.Len(); i++ { + q.Add(fmt.Sprintf("%s[]", key), toString(arr.Index(i))) + } + default: + if strVal := toString(val); strVal != "" { + q.Add(key, strVal) + } + } + } + rawQuery := q.Encode() + req.URL.RawQuery = rawQuery + } + } + + // Set Custom headers + for key, val := range headers { + req.Header.Set(key, toString(val)) + } + + // Set Client headers + for key, val := range clt.headers { + req.Header.Set(key, toString(val)) + } + + // Make request + resp, err := clt.client.Do(req) + if err != nil { + return nil, err + } + + // Handle response + defer resp.Body.Close() + + responseData, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + contentType := resp.Header.Get("content-type") + var isJson = strings.HasPrefix(contentType, "application/json") + if isJson { + if resp.StatusCode < 200 || resp.StatusCode > 399 { + var jsonResponse map[string]interface{} + json.Unmarshal(responseData, &jsonResponse) + message, ok := jsonResponse["message"].(string) + if !ok { + message = "N/A" + } + return nil, &AppwriteError{ + statusCode: resp.StatusCode, + message: message, + } + } + return &ClientResponse{ + Status: resp.Status, + StatusCode: resp.StatusCode, + Header: resp.Header, + Result: string(responseData), + Type: contentType, + }, nil + } + + if resp.StatusCode < 200 || resp.StatusCode > 399 { + return nil, &AppwriteError{ + statusCode: resp.StatusCode, + message: string(responseData), + } + } + return &ClientResponse{ + Status: resp.Status, + StatusCode: resp.StatusCode, + Header: resp.Header, + Result: responseData, + Type: contentType, + }, nil +} + +// toString changes arg to string +func toString(arg interface{}) string { + var tmp = reflect.Indirect(reflect.ValueOf(arg)).Interface() + switch v := tmp.(type) { + case int: + return strconv.Itoa(v) + case int8: + return strconv.FormatInt(int64(v), 10) + case int16: + return strconv.FormatInt(int64(v), 10) + case int32: + return strconv.FormatInt(int64(v), 10) + case int64: + return strconv.FormatInt(v, 10) + case string: + return v + case float32: + return strconv.FormatFloat(float64(v), 'f', -1, 32) + case float64: + return strconv.FormatFloat(v, 'f', -1, 64) + case bool: + return strconv.FormatBool(v) + case reflect.Value: + return toString(v.Interface()) + case fmt.Stringer: + return v.String() + default: + return fmt.Sprintf("%s", v) + } +} + + +// 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 { + return errors.New("result is nil") + } + + paramsType := reflect.TypeOf(params) + if paramsType.Kind() == reflect.Ptr { + paramsType = paramsType.Elem() + } + switch paramsType.Kind() { + case reflect.Array: + fallthrough + case reflect.Slice: + arr := reflect.Indirect(reflect.ValueOf(params)) + for i := 0; i < arr.Len(); i++ { + currentPrefix := fmt.Sprintf("%s[%d]", prefix, i) + err := flatten(arr.Index(i).Interface(), currentPrefix, result) + if err != nil { + return err + } + } + case reflect.Map: + m := reflect.Indirect(reflect.ValueOf(params)) + for _, key := range m.MapKeys() { + var currentPrefix string + if prefix == "" { + currentPrefix = toString(key) + } else { + currentPrefix = fmt.Sprintf("%s[%s]", prefix, toString(key)) + } + err := flatten(m.MapIndex(key).Interface(), currentPrefix, result) + if err != nil { + return err + } + } + default: + if prefix == "" { + return fmt.Errorf("prefix is empty for %s", params) + } + (*result)[prefix] = toString(params) + } + return nil +} diff --git a/databases/databases.go b/databases/databases.go new file mode 100644 index 0000000..e99384c --- /dev/null +++ b/databases/databases.go @@ -0,0 +1,2283 @@ +package databases + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Databases service +type Databases struct { + client client.Client +} + +func NewDatabases(clt client.Client) *Databases { + return &Databases{ + client: clt, + } +} + + +type ListOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListOption func(*ListOptions) +func WithListQueries(v []interface{}) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListSearch(v string) ListOption { + return func(o *ListOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// List get a list of all databases from the current Appwrite project. You can +// use the search parameter to filter your results. +func (srv *Databases) List(optionalSetters ...ListOption)(*models.DatabaseList, error) { + path := "/databases" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.DatabaseList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.DatabaseList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateOptions struct { + Enabled bool + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func WithCreateEnabled(v bool) CreateOption { + return func(o *CreateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// Create create a new Database. +func (srv *Databases) Create(DatabaseId string, Name string, optionalSetters ...CreateOption)(*models.Database, error) { + path := "/databases" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["name"] = Name + 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 + } + var parsed models.Database + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a database by its unique ID. This endpoint response returns a JSON +// object with the database metadata. +func (srv *Databases) Get(DatabaseId string)(*models.Database, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/databases/{databaseId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Database + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateOptions struct { + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOptions) New() *UpdateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + } + return &options +} +type UpdateOption func(*UpdateOptions) +func WithUpdateEnabled(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// Update update a database by its unique ID. +func (srv *Databases) Update(DatabaseId string, Name string, optionalSetters ...UpdateOption)(*models.Database, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/databases/{databaseId}") + options := UpdateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["name"] = Name + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Database + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a database by its unique ID. Only API keys with with +// databases.write scope can delete a database. +func (srv *Databases) Delete(DatabaseId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/databases/{databaseId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListCollectionsOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListCollectionsOptions) New() *ListCollectionsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListCollectionsOption func(*ListCollectionsOptions) +func WithListCollectionsQueries(v []interface{}) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListCollectionsSearch(v string) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListCollections get a list of all collections that belong to the provided +// databaseId. You can use the search parameter to filter your results. +func (srv *Databases) ListCollections(DatabaseId string, optionalSetters ...ListCollectionsOption)(*models.CollectionList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/databases/{databaseId}/collections") + options := ListCollectionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.CollectionList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.CollectionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateCollectionOptions struct { + Permissions []interface{} + DocumentSecurity bool + Enabled bool + enabledSetters map[string]bool +} +func (options CreateCollectionOptions) New() *CreateCollectionOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "DocumentSecurity": false, + "Enabled": false, + } + return &options +} +type CreateCollectionOption func(*CreateCollectionOptions) +func WithCreateCollectionPermissions(v []interface{}) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func WithCreateCollectionDocumentSecurity(v bool) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.DocumentSecurity = v + o.enabledSetters["DocumentSecurity"] = true + } +} +func WithCreateCollectionEnabled(v bool) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateCollection create a new Collection. Before using this route, you +// should create a new database resource using either a [server +// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) +// API or directly from your database console. +func (srv *Databases) CreateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...CreateCollectionOption)(*models.Collection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/databases/{databaseId}/collections") + options := CreateCollectionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["name"] = Name + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["DocumentSecurity"] { + params["documentSecurity"] = options.DocumentSecurity + } + 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 + } + var parsed models.Collection + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Collection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetCollection get a collection by its unique ID. This endpoint response +// returns a JSON object with the collection metadata. +func (srv *Databases) GetCollection(DatabaseId string, CollectionId string)(*models.Collection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Collection + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Collection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateCollectionOptions struct { + Permissions []interface{} + DocumentSecurity bool + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateCollectionOptions) New() *UpdateCollectionOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "DocumentSecurity": false, + "Enabled": false, + } + return &options +} +type UpdateCollectionOption func(*UpdateCollectionOptions) +func WithUpdateCollectionPermissions(v []interface{}) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func WithUpdateCollectionDocumentSecurity(v bool) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.DocumentSecurity = v + o.enabledSetters["DocumentSecurity"] = true + } +} +func WithUpdateCollectionEnabled(v bool) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateCollection update a collection by its unique ID. +func (srv *Databases) UpdateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...UpdateCollectionOption)(*models.Collection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}") + options := UpdateCollectionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["name"] = Name + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["DocumentSecurity"] { + params["documentSecurity"] = options.DocumentSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Collection + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Collection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteCollection delete a collection by its unique ID. Only users with +// write permissions have access to delete this resource. +func (srv *Databases) DeleteCollection(DatabaseId string, CollectionId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListAttributesOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListAttributesOptions) New() *ListAttributesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListAttributesOption func(*ListAttributesOptions) +func WithListAttributesQueries(v []interface{}) ListAttributesOption { + return func(o *ListAttributesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListAttributes list attributes in the collection. +func (srv *Databases) ListAttributes(DatabaseId string, CollectionId string, optionalSetters ...ListAttributesOption)(*models.AttributeList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes") + options := ListAttributesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateBooleanAttributeOptions struct { + Default bool + Array bool + enabledSetters map[string]bool +} +func (options CreateBooleanAttributeOptions) New() *CreateBooleanAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + } + return &options +} +type CreateBooleanAttributeOption func(*CreateBooleanAttributeOptions) +func WithCreateBooleanAttributeDefault(v bool) CreateBooleanAttributeOption { + return func(o *CreateBooleanAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateBooleanAttributeArray(v bool) CreateBooleanAttributeOption { + return func(o *CreateBooleanAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateBooleanAttribute create a boolean attribute. +func (srv *Databases) CreateBooleanAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateBooleanAttributeOption)(*models.AttributeBoolean, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/boolean") + options := CreateBooleanAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeBoolean + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeBoolean) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateBooleanAttribute update a boolean attribute. Changing the `default` +// value will not update already existing documents. +func (srv *Databases) UpdateBooleanAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default bool)(*models.AttributeBoolean, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeBoolean + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeBoolean) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateDatetimeAttributeOptions struct { + Default string + Array bool + enabledSetters map[string]bool +} +func (options CreateDatetimeAttributeOptions) New() *CreateDatetimeAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + } + return &options +} +type CreateDatetimeAttributeOption func(*CreateDatetimeAttributeOptions) +func WithCreateDatetimeAttributeDefault(v string) CreateDatetimeAttributeOption { + return func(o *CreateDatetimeAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateDatetimeAttributeArray(v bool) CreateDatetimeAttributeOption { + return func(o *CreateDatetimeAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateDatetimeAttribute create a date time attribute according to the ISO +// 8601 standard. +func (srv *Databases) CreateDatetimeAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateDatetimeAttributeOption)(*models.AttributeDatetime, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/datetime") + options := CreateDatetimeAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeDatetime + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeDatetime) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateDatetimeAttribute update a date time attribute. Changing the +// `default` value will not update already existing documents. +func (srv *Databases) UpdateDatetimeAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default string)(*models.AttributeDatetime, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeDatetime + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeDatetime) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateEmailAttributeOptions struct { + Default string + Array bool + enabledSetters map[string]bool +} +func (options CreateEmailAttributeOptions) New() *CreateEmailAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + } + return &options +} +type CreateEmailAttributeOption func(*CreateEmailAttributeOptions) +func WithCreateEmailAttributeDefault(v string) CreateEmailAttributeOption { + return func(o *CreateEmailAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateEmailAttributeArray(v bool) CreateEmailAttributeOption { + return func(o *CreateEmailAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateEmailAttribute create an email attribute. +func (srv *Databases) CreateEmailAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateEmailAttributeOption)(*models.AttributeEmail, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/email") + options := CreateEmailAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeEmail + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeEmail) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateEmailAttribute update an email attribute. Changing the `default` +// value will not update already existing documents. +func (srv *Databases) UpdateEmailAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default string)(*models.AttributeEmail, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeEmail + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeEmail) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateEnumAttributeOptions struct { + Default string + Array bool + enabledSetters map[string]bool +} +func (options CreateEnumAttributeOptions) New() *CreateEnumAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + } + return &options +} +type CreateEnumAttributeOption func(*CreateEnumAttributeOptions) +func WithCreateEnumAttributeDefault(v string) CreateEnumAttributeOption { + return func(o *CreateEnumAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateEnumAttributeArray(v bool) CreateEnumAttributeOption { + return func(o *CreateEnumAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateEnumAttribute create an enumeration attribute. The `elements` param +// acts as a white-list of accepted values for this attribute. +func (srv *Databases) CreateEnumAttribute(DatabaseId string, CollectionId string, Key string, Elements []interface{}, Required bool, optionalSetters ...CreateEnumAttributeOption)(*models.AttributeEnum, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/enum") + options := CreateEnumAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["elements"] = Elements + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeEnum + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeEnum) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateEnumAttribute update an enum attribute. Changing the `default` value +// will not update already existing documents. +func (srv *Databases) UpdateEnumAttribute(DatabaseId string, CollectionId string, Key string, Elements []interface{}, Required bool, Default string)(*models.AttributeEnum, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["elements"] = Elements + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeEnum + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeEnum) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateFloatAttributeOptions struct { + Min float64 + Max float64 + Default float64 + Array bool + enabledSetters map[string]bool +} +func (options CreateFloatAttributeOptions) New() *CreateFloatAttributeOptions { + options.enabledSetters = map[string]bool{ + "Min": false, + "Max": false, + "Default": false, + "Array": false, + } + return &options +} +type CreateFloatAttributeOption func(*CreateFloatAttributeOptions) +func WithCreateFloatAttributeMin(v float64) CreateFloatAttributeOption { + return func(o *CreateFloatAttributeOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func WithCreateFloatAttributeMax(v float64) CreateFloatAttributeOption { + return func(o *CreateFloatAttributeOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func WithCreateFloatAttributeDefault(v float64) CreateFloatAttributeOption { + return func(o *CreateFloatAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateFloatAttributeArray(v bool) CreateFloatAttributeOption { + return func(o *CreateFloatAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateFloatAttribute create a float attribute. Optionally, minimum and +// maximum values can be provided. +func (srv *Databases) CreateFloatAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateFloatAttributeOption)(*models.AttributeFloat, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/float") + options := CreateFloatAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeFloat + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeFloat) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateFloatAttribute update a float attribute. Changing the `default` value +// will not update already existing documents. +func (srv *Databases) UpdateFloatAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Min float64, Max float64, Default float64)(*models.AttributeFloat, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["min"] = Min + params["max"] = Max + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeFloat + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeFloat) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateIntegerAttributeOptions struct { + Min int + Max int + Default int + Array bool + enabledSetters map[string]bool +} +func (options CreateIntegerAttributeOptions) New() *CreateIntegerAttributeOptions { + options.enabledSetters = map[string]bool{ + "Min": false, + "Max": false, + "Default": false, + "Array": false, + } + return &options +} +type CreateIntegerAttributeOption func(*CreateIntegerAttributeOptions) +func WithCreateIntegerAttributeMin(v int) CreateIntegerAttributeOption { + return func(o *CreateIntegerAttributeOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func WithCreateIntegerAttributeMax(v int) CreateIntegerAttributeOption { + return func(o *CreateIntegerAttributeOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func WithCreateIntegerAttributeDefault(v int) CreateIntegerAttributeOption { + return func(o *CreateIntegerAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateIntegerAttributeArray(v bool) CreateIntegerAttributeOption { + return func(o *CreateIntegerAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateIntegerAttribute create an integer attribute. Optionally, minimum and +// maximum values can be provided. +func (srv *Databases) CreateIntegerAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateIntegerAttributeOption)(*models.AttributeInteger, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/integer") + options := CreateIntegerAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeInteger + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeInteger) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateIntegerAttribute update an integer attribute. Changing the `default` +// value will not update already existing documents. +func (srv *Databases) UpdateIntegerAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Min int, Max int, Default int)(*models.AttributeInteger, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["min"] = Min + params["max"] = Max + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeInteger + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeInteger) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateIpAttributeOptions struct { + Default string + Array bool + enabledSetters map[string]bool +} +func (options CreateIpAttributeOptions) New() *CreateIpAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + } + return &options +} +type CreateIpAttributeOption func(*CreateIpAttributeOptions) +func WithCreateIpAttributeDefault(v string) CreateIpAttributeOption { + return func(o *CreateIpAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateIpAttributeArray(v bool) CreateIpAttributeOption { + return func(o *CreateIpAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateIpAttribute create IP address attribute. +func (srv *Databases) CreateIpAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateIpAttributeOption)(*models.AttributeIp, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/ip") + options := CreateIpAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeIp + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeIp) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateIpAttribute update an ip attribute. Changing the `default` value will +// not update already existing documents. +func (srv *Databases) UpdateIpAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default string)(*models.AttributeIp, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeIp + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeIp) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateRelationshipAttributeOptions struct { + TwoWay bool + Key string + TwoWayKey string + OnDelete string + enabledSetters map[string]bool +} +func (options CreateRelationshipAttributeOptions) New() *CreateRelationshipAttributeOptions { + options.enabledSetters = map[string]bool{ + "TwoWay": false, + "Key": false, + "TwoWayKey": false, + "OnDelete": false, + } + return &options +} +type CreateRelationshipAttributeOption func(*CreateRelationshipAttributeOptions) +func WithCreateRelationshipAttributeTwoWay(v bool) CreateRelationshipAttributeOption { + return func(o *CreateRelationshipAttributeOptions) { + o.TwoWay = v + o.enabledSetters["TwoWay"] = true + } +} +func WithCreateRelationshipAttributeKey(v string) CreateRelationshipAttributeOption { + return func(o *CreateRelationshipAttributeOptions) { + o.Key = v + o.enabledSetters["Key"] = true + } +} +func WithCreateRelationshipAttributeTwoWayKey(v string) CreateRelationshipAttributeOption { + return func(o *CreateRelationshipAttributeOptions) { + o.TwoWayKey = v + o.enabledSetters["TwoWayKey"] = true + } +} +func WithCreateRelationshipAttributeOnDelete(v string) CreateRelationshipAttributeOption { + return func(o *CreateRelationshipAttributeOptions) { + o.OnDelete = v + o.enabledSetters["OnDelete"] = true + } +} + +// CreateRelationshipAttribute create relationship attribute. [Learn more +// about relationship +// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). +func (srv *Databases) CreateRelationshipAttribute(DatabaseId string, CollectionId string, RelatedCollectionId string, Type string, optionalSetters ...CreateRelationshipAttributeOption)(*models.AttributeRelationship, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/relationship") + options := CreateRelationshipAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["relatedCollectionId"] = RelatedCollectionId + params["type"] = Type + if options.enabledSetters["TwoWay"] { + params["twoWay"] = options.TwoWay + } + if options.enabledSetters["Key"] { + params["key"] = options.Key + } + if options.enabledSetters["TwoWayKey"] { + params["twoWayKey"] = options.TwoWayKey + } + if options.enabledSetters["OnDelete"] { + params["onDelete"] = options.OnDelete + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeRelationship + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeRelationship) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateStringAttributeOptions struct { + Default string + Array bool + Encrypt bool + enabledSetters map[string]bool +} +func (options CreateStringAttributeOptions) New() *CreateStringAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + "Encrypt": false, + } + return &options +} +type CreateStringAttributeOption func(*CreateStringAttributeOptions) +func WithCreateStringAttributeDefault(v string) CreateStringAttributeOption { + return func(o *CreateStringAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateStringAttributeArray(v bool) CreateStringAttributeOption { + return func(o *CreateStringAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} +func WithCreateStringAttributeEncrypt(v bool) CreateStringAttributeOption { + return func(o *CreateStringAttributeOptions) { + o.Encrypt = v + o.enabledSetters["Encrypt"] = true + } +} + +// CreateStringAttribute create a string attribute. +func (srv *Databases) CreateStringAttribute(DatabaseId string, CollectionId string, Key string, Size int, Required bool, optionalSetters ...CreateStringAttributeOption)(*models.AttributeString, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/string") + options := CreateStringAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["size"] = Size + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + if options.enabledSetters["Encrypt"] { + params["encrypt"] = options.Encrypt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeString + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeString) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateStringAttribute update a string attribute. Changing the `default` +// value will not update already existing documents. +func (srv *Databases) UpdateStringAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default string)(*models.AttributeString, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeString + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeString) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateUrlAttributeOptions struct { + Default string + Array bool + enabledSetters map[string]bool +} +func (options CreateUrlAttributeOptions) New() *CreateUrlAttributeOptions { + options.enabledSetters = map[string]bool{ + "Default": false, + "Array": false, + } + return &options +} +type CreateUrlAttributeOption func(*CreateUrlAttributeOptions) +func WithCreateUrlAttributeDefault(v string) CreateUrlAttributeOption { + return func(o *CreateUrlAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func WithCreateUrlAttributeArray(v bool) CreateUrlAttributeOption { + return func(o *CreateUrlAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateUrlAttribute create a URL attribute. +func (srv *Databases) CreateUrlAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateUrlAttributeOption)(*models.AttributeUrl, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/url") + options := CreateUrlAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeUrl + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeUrl) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateUrlAttribute update an url attribute. Changing the `default` value +// will not update already existing documents. +func (srv *Databases) UpdateUrlAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default string)(*models.AttributeUrl, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeUrl + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeUrl) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetAttribute get attribute by ID. +func (srv *Databases) GetAttribute(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteAttribute deletes an attribute. +func (srv *Databases) DeleteAttribute(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateRelationshipAttributeOptions struct { + OnDelete string + enabledSetters map[string]bool +} +func (options UpdateRelationshipAttributeOptions) New() *UpdateRelationshipAttributeOptions { + options.enabledSetters = map[string]bool{ + "OnDelete": false, + } + return &options +} +type UpdateRelationshipAttributeOption func(*UpdateRelationshipAttributeOptions) +func WithUpdateRelationshipAttributeOnDelete(v string) UpdateRelationshipAttributeOption { + return func(o *UpdateRelationshipAttributeOptions) { + o.OnDelete = v + o.enabledSetters["OnDelete"] = true + } +} + +// UpdateRelationshipAttribute update relationship attribute. [Learn more +// about relationship +// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). +func (srv *Databases) UpdateRelationshipAttribute(DatabaseId string, CollectionId string, Key string, optionalSetters ...UpdateRelationshipAttributeOption)(*models.AttributeRelationship, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship") + options := UpdateRelationshipAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + if options.enabledSetters["OnDelete"] { + params["onDelete"] = options.OnDelete + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.AttributeRelationship + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.AttributeRelationship) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListDocumentsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListDocumentsOptions) New() *ListDocumentsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListDocumentsOption func(*ListDocumentsOptions) +func WithListDocumentsQueries(v []interface{}) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListDocuments get a list of all the user's documents in a given collection. +// You can use the query params to filter your results. +func (srv *Databases) ListDocuments(DatabaseId string, CollectionId string, optionalSetters ...ListDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/documents") + options := ListDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.DocumentList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateDocumentOptions struct { + Permissions []interface{} + enabledSetters map[string]bool +} +func (options CreateDocumentOptions) New() *CreateDocumentOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + } + return &options +} +type CreateDocumentOption func(*CreateDocumentOptions) +func WithCreateDocumentPermissions(v []interface{}) CreateDocumentOption { + return func(o *CreateDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} + +// CreateDocument create a new 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. +func (srv *Databases) CreateDocument(DatabaseId string, CollectionId string, DocumentId string, Data interface{}, optionalSetters ...CreateDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/documents") + options := CreateDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + params["data"] = Data + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Document + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetDocumentOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options GetDocumentOptions) New() *GetDocumentOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type GetDocumentOption func(*GetDocumentOptions) +func WithGetDocumentQueries(v []interface{}) GetDocumentOption { + return func(o *GetDocumentOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// GetDocument get a document by its unique ID. This endpoint response returns +// a JSON object with the document data. +func (srv *Databases) GetDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...GetDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := GetDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Document + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateDocumentOptions struct { + Data interface{} + Permissions []interface{} + enabledSetters map[string]bool +} +func (options UpdateDocumentOptions) New() *UpdateDocumentOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Permissions": false, + } + return &options +} +type UpdateDocumentOption func(*UpdateDocumentOptions) +func WithUpdateDocumentData(v interface{}) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func WithUpdateDocumentPermissions(v []interface{}) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} + +// UpdateDocument update a document by its unique ID. Using the patch method +// you can pass only specific fields that will get updated. +func (srv *Databases) UpdateDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpdateDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := UpdateDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Document + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteDocument delete a document by its unique ID. +func (srv *Databases) DeleteDocument(DatabaseId string, CollectionId string, DocumentId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/documents/{documentId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListIndexesOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListIndexesOptions) New() *ListIndexesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListIndexesOption func(*ListIndexesOptions) +func WithListIndexesQueries(v []interface{}) ListIndexesOption { + return func(o *ListIndexesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListIndexes list indexes in the collection. +func (srv *Databases) ListIndexes(DatabaseId string, CollectionId string, optionalSetters ...ListIndexesOption)(*models.IndexList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/indexes") + options := ListIndexesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.IndexList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.IndexList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateIndexOptions struct { + Orders []interface{} + enabledSetters map[string]bool +} +func (options CreateIndexOptions) New() *CreateIndexOptions { + options.enabledSetters = map[string]bool{ + "Orders": false, + } + return &options +} +type CreateIndexOption func(*CreateIndexOptions) +func WithCreateIndexOrders(v []interface{}) CreateIndexOption { + return func(o *CreateIndexOptions) { + o.Orders = v + o.enabledSetters["Orders"] = true + } +} + +// CreateIndex creates an index on the attributes listed. Your index should +// include all the attributes you will query in a single request. +// Attributes can be `key`, `fulltext`, and `unique`. +func (srv *Databases) CreateIndex(DatabaseId string, CollectionId string, Key string, Type string, Attributes []interface{}, optionalSetters ...CreateIndexOption)(*models.Index, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/indexes") + options := CreateIndexOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["type"] = Type + params["attributes"] = Attributes + if options.enabledSetters["Orders"] { + params["orders"] = options.Orders + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Index + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Index) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetIndex get index by ID. +func (srv *Databases) GetIndex(DatabaseId string, CollectionId string, Key string)(*models.Index, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/indexes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Index + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Index) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteIndex delete an index. +func (srv *Databases) DeleteIndex(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/indexes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md new file mode 100644 index 0000000..9086483 --- /dev/null +++ b/docs/examples/account/create-anonymous-session.md @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateAnonymousSession( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md new file mode 100644 index 0000000..9ee8218 --- /dev/null +++ b/docs/examples/account/create-email-password-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateEmailPasswordSession( + "email@example.com", + "password", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md new file mode 100644 index 0000000..b67f1c5 --- /dev/null +++ b/docs/examples/account/create-email-token.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateEmailToken( + "", + "email@example.com", + account.WithCreateEmailTokenPhrase(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-j-w-t.md new file mode 100644 index 0000000..5f4ac14 --- /dev/null +++ b/docs/examples/account/create-j-w-t.md @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateJWT( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-u-r-l-token.md new file mode 100644 index 0000000..3627b0b --- /dev/null +++ b/docs/examples/account/create-magic-u-r-l-token.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateMagicURLToken( + "", + "email@example.com", + account.WithCreateMagicURLTokenUrl("https://example.com"), + account.WithCreateMagicURLTokenPhrase(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md new file mode 100644 index 0000000..32f771b --- /dev/null +++ b/docs/examples/account/create-mfa-authenticator.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.CreateMfaAuthenticator( + "totp", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md new file mode 100644 index 0000000..35fe23d --- /dev/null +++ b/docs/examples/account/create-mfa-challenge.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateMfaChallenge( + "email", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md new file mode 100644 index 0000000..41244ce --- /dev/null +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.CreateMfaRecoveryCodes( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-o-auth2token.md b/docs/examples/account/create-o-auth2token.md new file mode 100644 index 0000000..acec403 --- /dev/null +++ b/docs/examples/account/create-o-auth2token.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateOAuth2Token( + "amazon", + account.WithCreateOAuth2TokenSuccess("https://example.com"), + account.WithCreateOAuth2TokenFailure("https://example.com"), + account.WithCreateOAuth2TokenScopes([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md new file mode 100644 index 0000000..26d6ea0 --- /dev/null +++ b/docs/examples/account/create-phone-token.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreatePhoneToken( + "", + "+12065550100", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md new file mode 100644 index 0000000..0cbc246 --- /dev/null +++ b/docs/examples/account/create-phone-verification.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.CreatePhoneVerification( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md new file mode 100644 index 0000000..0ea4d97 --- /dev/null +++ b/docs/examples/account/create-recovery.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.CreateRecovery( + "email@example.com", + "https://example.com", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md new file mode 100644 index 0000000..f15dc97 --- /dev/null +++ b/docs/examples/account/create-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.CreateSession( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md new file mode 100644 index 0000000..ae18e6e --- /dev/null +++ b/docs/examples/account/create-verification.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.CreateVerification( + "https://example.com", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md new file mode 100644 index 0000000..9444719 --- /dev/null +++ b/docs/examples/account/create.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.Create( + "", + "email@example.com", + "", + account.WithCreateName(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/delete-identity.md b/docs/examples/account/delete-identity.md new file mode 100644 index 0000000..18935d8 --- /dev/null +++ b/docs/examples/account/delete-identity.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.DeleteIdentity( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md new file mode 100644 index 0000000..98f57d3 --- /dev/null +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.DeleteMfaAuthenticator( + "totp", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md new file mode 100644 index 0000000..71c6dd2 --- /dev/null +++ b/docs/examples/account/delete-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.DeleteSession( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md new file mode 100644 index 0000000..392bc8b --- /dev/null +++ b/docs/examples/account/delete-sessions.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.DeleteSessions( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md new file mode 100644 index 0000000..f02a1b9 --- /dev/null +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.GetMfaRecoveryCodes( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md new file mode 100644 index 0000000..b56d0e3 --- /dev/null +++ b/docs/examples/account/get-prefs.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.GetPrefs( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md new file mode 100644 index 0000000..5c98f00 --- /dev/null +++ b/docs/examples/account/get-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.GetSession( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md new file mode 100644 index 0000000..6d14e3a --- /dev/null +++ b/docs/examples/account/get.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.Get( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md new file mode 100644 index 0000000..bc1b320 --- /dev/null +++ b/docs/examples/account/list-identities.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.ListIdentities( + account.WithListIdentitiesQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md new file mode 100644 index 0000000..2aec5f4 --- /dev/null +++ b/docs/examples/account/list-logs.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.ListLogs( + account.WithListLogsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md new file mode 100644 index 0000000..8b98247 --- /dev/null +++ b/docs/examples/account/list-mfa-factors.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.ListMfaFactors( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md new file mode 100644 index 0000000..d24e7ce --- /dev/null +++ b/docs/examples/account/list-sessions.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.ListSessions( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md new file mode 100644 index 0000000..45ae447 --- /dev/null +++ b/docs/examples/account/update-email.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateEmail( + "email@example.com", + "password", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-m-f-a.md new file mode 100644 index 0000000..1507088 --- /dev/null +++ b/docs/examples/account/update-m-f-a.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateMFA( + false, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-u-r-l-session.md new file mode 100644 index 0000000..5c5e391 --- /dev/null +++ b/docs/examples/account/update-magic-u-r-l-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.UpdateMagicURLSession( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md new file mode 100644 index 0000000..a94925d --- /dev/null +++ b/docs/examples/account/update-mfa-authenticator.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateMfaAuthenticator( + "totp", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md new file mode 100644 index 0000000..825c525 --- /dev/null +++ b/docs/examples/account/update-mfa-challenge.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateMfaChallenge( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md new file mode 100644 index 0000000..bac13e4 --- /dev/null +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateMfaRecoveryCodes( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md new file mode 100644 index 0000000..2e59644 --- /dev/null +++ b/docs/examples/account/update-name.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateName( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md new file mode 100644 index 0000000..4b4993f --- /dev/null +++ b/docs/examples/account/update-password.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdatePassword( + "", + account.WithUpdatePasswordOldPassword("password"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md new file mode 100644 index 0000000..dd00b55 --- /dev/null +++ b/docs/examples/account/update-phone-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + + service := account.NewAccount(client) + response, error := service.UpdatePhoneSession( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md new file mode 100644 index 0000000..fa111c0 --- /dev/null +++ b/docs/examples/account/update-phone-verification.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdatePhoneVerification( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md new file mode 100644 index 0000000..d1ea343 --- /dev/null +++ b/docs/examples/account/update-phone.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdatePhone( + "+12065550100", + "password", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md new file mode 100644 index 0000000..c5898d9 --- /dev/null +++ b/docs/examples/account/update-prefs.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdatePrefs( + map[string]interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md new file mode 100644 index 0000000..c1850c4 --- /dev/null +++ b/docs/examples/account/update-recovery.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateRecovery( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md new file mode 100644 index 0000000..e34e822 --- /dev/null +++ b/docs/examples/account/update-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateSession( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md new file mode 100644 index 0000000..396b69f --- /dev/null +++ b/docs/examples/account/update-status.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateStatus( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md new file mode 100644 index 0000000..2a07f78 --- /dev/null +++ b/docs/examples/account/update-verification.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/account" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := account.NewAccount(client) + response, error := service.UpdateVerification( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md new file mode 100644 index 0000000..7ab9261 --- /dev/null +++ b/docs/examples/avatars/get-browser.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetBrowser( + "aa", + avatars.WithGetBrowserWidth(0), + avatars.WithGetBrowserHeight(0), + avatars.WithGetBrowserQuality(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md new file mode 100644 index 0000000..a862fc6 --- /dev/null +++ b/docs/examples/avatars/get-credit-card.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetCreditCard( + "amex", + avatars.WithGetCreditCardWidth(0), + avatars.WithGetCreditCardHeight(0), + avatars.WithGetCreditCardQuality(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md new file mode 100644 index 0000000..8276cd2 --- /dev/null +++ b/docs/examples/avatars/get-favicon.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetFavicon( + "https://example.com", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md new file mode 100644 index 0000000..9d74522 --- /dev/null +++ b/docs/examples/avatars/get-flag.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetFlag( + "af", + avatars.WithGetFlagWidth(0), + avatars.WithGetFlagHeight(0), + avatars.WithGetFlagQuality(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md new file mode 100644 index 0000000..70dacb0 --- /dev/null +++ b/docs/examples/avatars/get-image.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetImage( + "https://example.com", + avatars.WithGetImageWidth(0), + avatars.WithGetImageHeight(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md new file mode 100644 index 0000000..2e4e225 --- /dev/null +++ b/docs/examples/avatars/get-initials.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetInitials( + avatars.WithGetInitialsName(""), + avatars.WithGetInitialsWidth(0), + avatars.WithGetInitialsHeight(0), + avatars.WithGetInitialsBackground(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md new file mode 100644 index 0000000..5923193 --- /dev/null +++ b/docs/examples/avatars/get-q-r.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/avatars" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := avatars.NewAvatars(client) + response, error := service.GetQR( + "", + avatars.WithGetQRSize(1), + avatars.WithGetQRMargin(0), + avatars.WithGetQRDownload(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-boolean-attribute.md b/docs/examples/databases/create-boolean-attribute.md new file mode 100644 index 0000000..5fb718c --- /dev/null +++ b/docs/examples/databases/create-boolean-attribute.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateBooleanAttribute( + "", + "", + "", + false, + databases.WithCreateBooleanAttributeDefault(false), + databases.WithCreateBooleanAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-collection.md b/docs/examples/databases/create-collection.md new file mode 100644 index 0000000..8ec44be --- /dev/null +++ b/docs/examples/databases/create-collection.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateCollection( + "", + "", + "", + databases.WithCreateCollectionPermissions(interface{}{"read("any")"}), + databases.WithCreateCollectionDocumentSecurity(false), + databases.WithCreateCollectionEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-datetime-attribute.md b/docs/examples/databases/create-datetime-attribute.md new file mode 100644 index 0000000..dc81db4 --- /dev/null +++ b/docs/examples/databases/create-datetime-attribute.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateDatetimeAttribute( + "", + "", + "", + false, + databases.WithCreateDatetimeAttributeDefault(""), + databases.WithCreateDatetimeAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md new file mode 100644 index 0000000..4028034 --- /dev/null +++ b/docs/examples/databases/create-document.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := databases.NewDatabases(client) + response, error := service.CreateDocument( + "", + "", + "", + map[string]interface{}{}, + databases.WithCreateDocumentPermissions(interface{}{"read("any")"}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-email-attribute.md b/docs/examples/databases/create-email-attribute.md new file mode 100644 index 0000000..df69c63 --- /dev/null +++ b/docs/examples/databases/create-email-attribute.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateEmailAttribute( + "", + "", + "", + false, + databases.WithCreateEmailAttributeDefault("email@example.com"), + databases.WithCreateEmailAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-enum-attribute.md b/docs/examples/databases/create-enum-attribute.md new file mode 100644 index 0000000..bb814d2 --- /dev/null +++ b/docs/examples/databases/create-enum-attribute.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateEnumAttribute( + "", + "", + "", + []interface{}{}, + false, + databases.WithCreateEnumAttributeDefault(""), + databases.WithCreateEnumAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-float-attribute.md b/docs/examples/databases/create-float-attribute.md new file mode 100644 index 0000000..1adc9b7 --- /dev/null +++ b/docs/examples/databases/create-float-attribute.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateFloatAttribute( + "", + "", + "", + false, + databases.WithCreateFloatAttributeMin(0), + databases.WithCreateFloatAttributeMax(0), + databases.WithCreateFloatAttributeDefault(0), + databases.WithCreateFloatAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-index.md b/docs/examples/databases/create-index.md new file mode 100644 index 0000000..2dc304a --- /dev/null +++ b/docs/examples/databases/create-index.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateIndex( + "", + "", + "", + "key", + []interface{}{}, + databases.WithCreateIndexOrders([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-integer-attribute.md b/docs/examples/databases/create-integer-attribute.md new file mode 100644 index 0000000..95dc4d0 --- /dev/null +++ b/docs/examples/databases/create-integer-attribute.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateIntegerAttribute( + "", + "", + "", + false, + databases.WithCreateIntegerAttributeMin(0), + databases.WithCreateIntegerAttributeMax(0), + databases.WithCreateIntegerAttributeDefault(0), + databases.WithCreateIntegerAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-ip-attribute.md b/docs/examples/databases/create-ip-attribute.md new file mode 100644 index 0000000..6a93548 --- /dev/null +++ b/docs/examples/databases/create-ip-attribute.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateIpAttribute( + "", + "", + "", + false, + databases.WithCreateIpAttributeDefault(""), + databases.WithCreateIpAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-relationship-attribute.md b/docs/examples/databases/create-relationship-attribute.md new file mode 100644 index 0000000..a895f37 --- /dev/null +++ b/docs/examples/databases/create-relationship-attribute.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateRelationshipAttribute( + "", + "", + "", + "oneToOne", + databases.WithCreateRelationshipAttributeTwoWay(false), + databases.WithCreateRelationshipAttributeKey(""), + databases.WithCreateRelationshipAttributeTwoWayKey(""), + databases.WithCreateRelationshipAttributeOnDelete("cascade"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-string-attribute.md b/docs/examples/databases/create-string-attribute.md new file mode 100644 index 0000000..b61d896 --- /dev/null +++ b/docs/examples/databases/create-string-attribute.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateStringAttribute( + "", + "", + "", + 1, + false, + databases.WithCreateStringAttributeDefault(""), + databases.WithCreateStringAttributeArray(false), + databases.WithCreateStringAttributeEncrypt(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create-url-attribute.md b/docs/examples/databases/create-url-attribute.md new file mode 100644 index 0000000..2378290 --- /dev/null +++ b/docs/examples/databases/create-url-attribute.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.CreateUrlAttribute( + "", + "", + "", + false, + databases.WithCreateUrlAttributeDefault("https://example.com"), + databases.WithCreateUrlAttributeArray(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/create.md b/docs/examples/databases/create.md new file mode 100644 index 0000000..c5ec12a --- /dev/null +++ b/docs/examples/databases/create.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.Create( + "", + "", + databases.WithCreateEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/delete-attribute.md b/docs/examples/databases/delete-attribute.md new file mode 100644 index 0000000..64418b1 --- /dev/null +++ b/docs/examples/databases/delete-attribute.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.DeleteAttribute( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/delete-collection.md b/docs/examples/databases/delete-collection.md new file mode 100644 index 0000000..eaa080b --- /dev/null +++ b/docs/examples/databases/delete-collection.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.DeleteCollection( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md new file mode 100644 index 0000000..fdedf1e --- /dev/null +++ b/docs/examples/databases/delete-document.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := databases.NewDatabases(client) + response, error := service.DeleteDocument( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/delete-index.md b/docs/examples/databases/delete-index.md new file mode 100644 index 0000000..5beadd1 --- /dev/null +++ b/docs/examples/databases/delete-index.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.DeleteIndex( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/delete.md b/docs/examples/databases/delete.md new file mode 100644 index 0000000..06ed2ba --- /dev/null +++ b/docs/examples/databases/delete.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.Delete( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/get-attribute.md b/docs/examples/databases/get-attribute.md new file mode 100644 index 0000000..df15da2 --- /dev/null +++ b/docs/examples/databases/get-attribute.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.GetAttribute( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/get-collection.md b/docs/examples/databases/get-collection.md new file mode 100644 index 0000000..0d89eed --- /dev/null +++ b/docs/examples/databases/get-collection.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.GetCollection( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md new file mode 100644 index 0000000..877cdd8 --- /dev/null +++ b/docs/examples/databases/get-document.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := databases.NewDatabases(client) + response, error := service.GetDocument( + "", + "", + "", + databases.WithGetDocumentQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/get-index.md b/docs/examples/databases/get-index.md new file mode 100644 index 0000000..1ef0c45 --- /dev/null +++ b/docs/examples/databases/get-index.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.GetIndex( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/get.md b/docs/examples/databases/get.md new file mode 100644 index 0000000..72d7fea --- /dev/null +++ b/docs/examples/databases/get.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.Get( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/list-attributes.md b/docs/examples/databases/list-attributes.md new file mode 100644 index 0000000..36e5ae4 --- /dev/null +++ b/docs/examples/databases/list-attributes.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.ListAttributes( + "", + "", + databases.WithListAttributesQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/list-collections.md b/docs/examples/databases/list-collections.md new file mode 100644 index 0000000..a21721e --- /dev/null +++ b/docs/examples/databases/list-collections.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.ListCollections( + "", + databases.WithListCollectionsQueries([]interface{}{}), + databases.WithListCollectionsSearch(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md new file mode 100644 index 0000000..07fa0ed --- /dev/null +++ b/docs/examples/databases/list-documents.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := databases.NewDatabases(client) + response, error := service.ListDocuments( + "", + "", + databases.WithListDocumentsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/list-indexes.md b/docs/examples/databases/list-indexes.md new file mode 100644 index 0000000..682405d --- /dev/null +++ b/docs/examples/databases/list-indexes.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.ListIndexes( + "", + "", + databases.WithListIndexesQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/list.md b/docs/examples/databases/list.md new file mode 100644 index 0000000..a931d2a --- /dev/null +++ b/docs/examples/databases/list.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.List( + databases.WithListQueries([]interface{}{}), + databases.WithListSearch(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-boolean-attribute.md b/docs/examples/databases/update-boolean-attribute.md new file mode 100644 index 0000000..632c22d --- /dev/null +++ b/docs/examples/databases/update-boolean-attribute.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateBooleanAttribute( + "", + "", + "", + false, + false, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-collection.md b/docs/examples/databases/update-collection.md new file mode 100644 index 0000000..03c4962 --- /dev/null +++ b/docs/examples/databases/update-collection.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateCollection( + "", + "", + "", + databases.WithUpdateCollectionPermissions(interface{}{"read("any")"}), + databases.WithUpdateCollectionDocumentSecurity(false), + databases.WithUpdateCollectionEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-datetime-attribute.md b/docs/examples/databases/update-datetime-attribute.md new file mode 100644 index 0000000..c66601b --- /dev/null +++ b/docs/examples/databases/update-datetime-attribute.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateDatetimeAttribute( + "", + "", + "", + false, + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md new file mode 100644 index 0000000..cf05b1e --- /dev/null +++ b/docs/examples/databases/update-document.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := databases.NewDatabases(client) + response, error := service.UpdateDocument( + "", + "", + "", + databases.WithUpdateDocumentData(map[string]interface{}{}), + databases.WithUpdateDocumentPermissions(interface{}{"read("any")"}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-email-attribute.md b/docs/examples/databases/update-email-attribute.md new file mode 100644 index 0000000..9326e29 --- /dev/null +++ b/docs/examples/databases/update-email-attribute.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateEmailAttribute( + "", + "", + "", + false, + "email@example.com", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-enum-attribute.md b/docs/examples/databases/update-enum-attribute.md new file mode 100644 index 0000000..7094722 --- /dev/null +++ b/docs/examples/databases/update-enum-attribute.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateEnumAttribute( + "", + "", + "", + []interface{}{}, + false, + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-float-attribute.md b/docs/examples/databases/update-float-attribute.md new file mode 100644 index 0000000..53fcd5b --- /dev/null +++ b/docs/examples/databases/update-float-attribute.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateFloatAttribute( + "", + "", + "", + false, + 0, + 0, + 0, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-integer-attribute.md b/docs/examples/databases/update-integer-attribute.md new file mode 100644 index 0000000..eb6a8cd --- /dev/null +++ b/docs/examples/databases/update-integer-attribute.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateIntegerAttribute( + "", + "", + "", + false, + 0, + 0, + 0, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-ip-attribute.md b/docs/examples/databases/update-ip-attribute.md new file mode 100644 index 0000000..b0c836c --- /dev/null +++ b/docs/examples/databases/update-ip-attribute.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateIpAttribute( + "", + "", + "", + false, + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-relationship-attribute.md b/docs/examples/databases/update-relationship-attribute.md new file mode 100644 index 0000000..bbcabcf --- /dev/null +++ b/docs/examples/databases/update-relationship-attribute.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateRelationshipAttribute( + "", + "", + "", + databases.WithUpdateRelationshipAttributeOnDelete("cascade"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-string-attribute.md b/docs/examples/databases/update-string-attribute.md new file mode 100644 index 0000000..2a51779 --- /dev/null +++ b/docs/examples/databases/update-string-attribute.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateStringAttribute( + "", + "", + "", + false, + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update-url-attribute.md b/docs/examples/databases/update-url-attribute.md new file mode 100644 index 0000000..141cb12 --- /dev/null +++ b/docs/examples/databases/update-url-attribute.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.UpdateUrlAttribute( + "", + "", + "", + false, + "https://example.com", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/databases/update.md b/docs/examples/databases/update.md new file mode 100644 index 0000000..8821f5c --- /dev/null +++ b/docs/examples/databases/update.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/databases" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := databases.NewDatabases(client) + response, error := service.Update( + "", + "", + databases.WithUpdateEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/create-build.md b/docs/examples/functions/create-build.md new file mode 100644 index 0000000..773e417 --- /dev/null +++ b/docs/examples/functions/create-build.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.CreateBuild( + "", + "", + functions.WithCreateBuildBuildId(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/create-deployment.md b/docs/examples/functions/create-deployment.md new file mode 100644 index 0000000..bd7f07d --- /dev/null +++ b/docs/examples/functions/create-deployment.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.CreateDeployment( + "", + file.NewInputFile("/path/to/file.png", "file.png"), + false, + functions.WithCreateDeploymentEntrypoint(""), + functions.WithCreateDeploymentCommands(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md new file mode 100644 index 0000000..421b914 --- /dev/null +++ b/docs/examples/functions/create-execution.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := functions.NewFunctions(client) + response, error := service.CreateExecution( + "", + functions.WithCreateExecutionBody(""), + functions.WithCreateExecutionAsync(false), + functions.WithCreateExecutionPath(""), + functions.WithCreateExecutionMethod("GET"), + functions.WithCreateExecutionHeaders(map[string]interface{}{}), + functions.WithCreateExecutionScheduledAt(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/create-variable.md b/docs/examples/functions/create-variable.md new file mode 100644 index 0000000..9766d1e --- /dev/null +++ b/docs/examples/functions/create-variable.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.CreateVariable( + "", + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md new file mode 100644 index 0000000..3e7c42f --- /dev/null +++ b/docs/examples/functions/create.md @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.Create( + "", + "", + "node-14.5", + functions.WithCreateExecute(interface{}{"any"}), + functions.WithCreateEvents([]interface{}{}), + functions.WithCreateSchedule(""), + functions.WithCreateTimeout(1), + functions.WithCreateEnabled(false), + functions.WithCreateLogging(false), + functions.WithCreateEntrypoint(""), + functions.WithCreateCommands(""), + functions.WithCreateScopes([]interface{}{}), + functions.WithCreateInstallationId(""), + functions.WithCreateProviderRepositoryId(""), + functions.WithCreateProviderBranch(""), + functions.WithCreateProviderSilentMode(false), + functions.WithCreateProviderRootDirectory(""), + functions.WithCreateTemplateRepository(""), + functions.WithCreateTemplateOwner(""), + functions.WithCreateTemplateRootDirectory(""), + functions.WithCreateTemplateBranch(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/delete-deployment.md b/docs/examples/functions/delete-deployment.md new file mode 100644 index 0000000..052a685 --- /dev/null +++ b/docs/examples/functions/delete-deployment.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.DeleteDeployment( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/delete-execution.md b/docs/examples/functions/delete-execution.md new file mode 100644 index 0000000..094a0db --- /dev/null +++ b/docs/examples/functions/delete-execution.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.DeleteExecution( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/delete-variable.md b/docs/examples/functions/delete-variable.md new file mode 100644 index 0000000..e7bf0a7 --- /dev/null +++ b/docs/examples/functions/delete-variable.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.DeleteVariable( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/delete.md b/docs/examples/functions/delete.md new file mode 100644 index 0000000..79a9c1b --- /dev/null +++ b/docs/examples/functions/delete.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.Delete( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/download-deployment.md b/docs/examples/functions/download-deployment.md new file mode 100644 index 0000000..37d2149 --- /dev/null +++ b/docs/examples/functions/download-deployment.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.DownloadDeployment( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/get-deployment.md b/docs/examples/functions/get-deployment.md new file mode 100644 index 0000000..37b26a9 --- /dev/null +++ b/docs/examples/functions/get-deployment.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.GetDeployment( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md new file mode 100644 index 0000000..0187abe --- /dev/null +++ b/docs/examples/functions/get-execution.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := functions.NewFunctions(client) + response, error := service.GetExecution( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/get-variable.md b/docs/examples/functions/get-variable.md new file mode 100644 index 0000000..03ad092 --- /dev/null +++ b/docs/examples/functions/get-variable.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.GetVariable( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/get.md b/docs/examples/functions/get.md new file mode 100644 index 0000000..3502e11 --- /dev/null +++ b/docs/examples/functions/get.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.Get( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/list-deployments.md b/docs/examples/functions/list-deployments.md new file mode 100644 index 0000000..8c444b4 --- /dev/null +++ b/docs/examples/functions/list-deployments.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.ListDeployments( + "", + functions.WithListDeploymentsQueries([]interface{}{}), + functions.WithListDeploymentsSearch(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md new file mode 100644 index 0000000..a8581fc --- /dev/null +++ b/docs/examples/functions/list-executions.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := functions.NewFunctions(client) + response, error := service.ListExecutions( + "", + functions.WithListExecutionsQueries([]interface{}{}), + functions.WithListExecutionsSearch(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/list-runtimes.md b/docs/examples/functions/list-runtimes.md new file mode 100644 index 0000000..7f1d67b --- /dev/null +++ b/docs/examples/functions/list-runtimes.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.ListRuntimes( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/list-variables.md b/docs/examples/functions/list-variables.md new file mode 100644 index 0000000..41a5f1b --- /dev/null +++ b/docs/examples/functions/list-variables.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.ListVariables( + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/list.md b/docs/examples/functions/list.md new file mode 100644 index 0000000..e81685e --- /dev/null +++ b/docs/examples/functions/list.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.List( + functions.WithListQueries([]interface{}{}), + functions.WithListSearch(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/update-deployment-build.md b/docs/examples/functions/update-deployment-build.md new file mode 100644 index 0000000..f72a94f --- /dev/null +++ b/docs/examples/functions/update-deployment-build.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.UpdateDeploymentBuild( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/update-deployment.md b/docs/examples/functions/update-deployment.md new file mode 100644 index 0000000..2ff37a0 --- /dev/null +++ b/docs/examples/functions/update-deployment.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.UpdateDeployment( + "", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/update-variable.md b/docs/examples/functions/update-variable.md new file mode 100644 index 0000000..3b51ecd --- /dev/null +++ b/docs/examples/functions/update-variable.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.UpdateVariable( + "", + "", + "", + functions.WithUpdateVariableValue(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md new file mode 100644 index 0000000..4b67391 --- /dev/null +++ b/docs/examples/functions/update.md @@ -0,0 +1,42 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/functions" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := functions.NewFunctions(client) + response, error := service.Update( + "", + "", + functions.WithUpdateRuntime("node-14.5"), + functions.WithUpdateExecute(interface{}{"any"}), + functions.WithUpdateEvents([]interface{}{}), + functions.WithUpdateSchedule(""), + functions.WithUpdateTimeout(1), + functions.WithUpdateEnabled(false), + functions.WithUpdateLogging(false), + functions.WithUpdateEntrypoint(""), + functions.WithUpdateCommands(""), + functions.WithUpdateScopes([]interface{}{}), + functions.WithUpdateInstallationId(""), + functions.WithUpdateProviderRepositoryId(""), + functions.WithUpdateProviderBranch(""), + functions.WithUpdateProviderSilentMode(false), + functions.WithUpdateProviderRootDirectory(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md new file mode 100644 index 0000000..dccdb85 --- /dev/null +++ b/docs/examples/graphql/mutation.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/graphql" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := graphql.NewGraphql(client) + response, error := service.Mutation( + map[string]interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md new file mode 100644 index 0000000..478682a --- /dev/null +++ b/docs/examples/graphql/query.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/graphql" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := graphql.NewGraphql(client) + response, error := service.Query( + map[string]interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-antivirus.md b/docs/examples/health/get-antivirus.md new file mode 100644 index 0000000..d5e15be --- /dev/null +++ b/docs/examples/health/get-antivirus.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetAntivirus( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-cache.md b/docs/examples/health/get-cache.md new file mode 100644 index 0000000..2212f09 --- /dev/null +++ b/docs/examples/health/get-cache.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetCache( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-certificate.md b/docs/examples/health/get-certificate.md new file mode 100644 index 0000000..5c9b8f9 --- /dev/null +++ b/docs/examples/health/get-certificate.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetCertificate( + health.WithGetCertificateDomain(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-d-b.md b/docs/examples/health/get-d-b.md new file mode 100644 index 0000000..d101282 --- /dev/null +++ b/docs/examples/health/get-d-b.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetDB( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-failed-jobs.md b/docs/examples/health/get-failed-jobs.md new file mode 100644 index 0000000..6006fab --- /dev/null +++ b/docs/examples/health/get-failed-jobs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetFailedJobs( + "v1-database", + health.WithGetFailedJobsThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-pub-sub.md b/docs/examples/health/get-pub-sub.md new file mode 100644 index 0000000..3340e2b --- /dev/null +++ b/docs/examples/health/get-pub-sub.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetPubSub( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-builds.md b/docs/examples/health/get-queue-builds.md new file mode 100644 index 0000000..bd395b4 --- /dev/null +++ b/docs/examples/health/get-queue-builds.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueBuilds( + health.WithGetQueueBuildsThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-certificates.md b/docs/examples/health/get-queue-certificates.md new file mode 100644 index 0000000..26a430b --- /dev/null +++ b/docs/examples/health/get-queue-certificates.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueCertificates( + health.WithGetQueueCertificatesThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-databases.md b/docs/examples/health/get-queue-databases.md new file mode 100644 index 0000000..5ff6173 --- /dev/null +++ b/docs/examples/health/get-queue-databases.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueDatabases( + health.WithGetQueueDatabasesName(""), + health.WithGetQueueDatabasesThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-deletes.md b/docs/examples/health/get-queue-deletes.md new file mode 100644 index 0000000..0ce1631 --- /dev/null +++ b/docs/examples/health/get-queue-deletes.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueDeletes( + health.WithGetQueueDeletesThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-functions.md b/docs/examples/health/get-queue-functions.md new file mode 100644 index 0000000..032f30a --- /dev/null +++ b/docs/examples/health/get-queue-functions.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueFunctions( + health.WithGetQueueFunctionsThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-logs.md b/docs/examples/health/get-queue-logs.md new file mode 100644 index 0000000..11e19e0 --- /dev/null +++ b/docs/examples/health/get-queue-logs.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueLogs( + health.WithGetQueueLogsThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-mails.md b/docs/examples/health/get-queue-mails.md new file mode 100644 index 0000000..5f8e56f --- /dev/null +++ b/docs/examples/health/get-queue-mails.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueMails( + health.WithGetQueueMailsThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-messaging.md b/docs/examples/health/get-queue-messaging.md new file mode 100644 index 0000000..7afe7ba --- /dev/null +++ b/docs/examples/health/get-queue-messaging.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueMessaging( + health.WithGetQueueMessagingThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-migrations.md b/docs/examples/health/get-queue-migrations.md new file mode 100644 index 0000000..6da744e --- /dev/null +++ b/docs/examples/health/get-queue-migrations.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueMigrations( + health.WithGetQueueMigrationsThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-usage-dump.md b/docs/examples/health/get-queue-usage-dump.md new file mode 100644 index 0000000..097cb01 --- /dev/null +++ b/docs/examples/health/get-queue-usage-dump.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueUsageDump( + health.WithGetQueueUsageDumpThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-usage.md b/docs/examples/health/get-queue-usage.md new file mode 100644 index 0000000..a70ddcf --- /dev/null +++ b/docs/examples/health/get-queue-usage.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueUsage( + health.WithGetQueueUsageThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue-webhooks.md b/docs/examples/health/get-queue-webhooks.md new file mode 100644 index 0000000..08afa66 --- /dev/null +++ b/docs/examples/health/get-queue-webhooks.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueueWebhooks( + health.WithGetQueueWebhooksThreshold(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-queue.md b/docs/examples/health/get-queue.md new file mode 100644 index 0000000..385e5f6 --- /dev/null +++ b/docs/examples/health/get-queue.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetQueue( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-storage-local.md b/docs/examples/health/get-storage-local.md new file mode 100644 index 0000000..8fa3a4c --- /dev/null +++ b/docs/examples/health/get-storage-local.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetStorageLocal( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-storage.md b/docs/examples/health/get-storage.md new file mode 100644 index 0000000..59d20f6 --- /dev/null +++ b/docs/examples/health/get-storage.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetStorage( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get-time.md b/docs/examples/health/get-time.md new file mode 100644 index 0000000..4e141bb --- /dev/null +++ b/docs/examples/health/get-time.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.GetTime( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/health/get.md b/docs/examples/health/get.md new file mode 100644 index 0000000..18cb882 --- /dev/null +++ b/docs/examples/health/get.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/health" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := health.NewHealth(client) + response, error := service.Get( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md new file mode 100644 index 0000000..864835b --- /dev/null +++ b/docs/examples/locale/get.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.Get( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-codes.md b/docs/examples/locale/list-codes.md new file mode 100644 index 0000000..536659a --- /dev/null +++ b/docs/examples/locale/list-codes.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListCodes( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md new file mode 100644 index 0000000..1175062 --- /dev/null +++ b/docs/examples/locale/list-continents.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListContinents( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-e-u.md new file mode 100644 index 0000000..26f055c --- /dev/null +++ b/docs/examples/locale/list-countries-e-u.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListCountriesEU( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md new file mode 100644 index 0000000..0655994 --- /dev/null +++ b/docs/examples/locale/list-countries-phones.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListCountriesPhones( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md new file mode 100644 index 0000000..d580c37 --- /dev/null +++ b/docs/examples/locale/list-countries.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListCountries( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md new file mode 100644 index 0000000..20f9a15 --- /dev/null +++ b/docs/examples/locale/list-currencies.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListCurrencies( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md new file mode 100644 index 0000000..b216c83 --- /dev/null +++ b/docs/examples/locale/list-languages.md @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/locale" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := locale.NewLocale(client) + response, error := service.ListLanguages( + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-apns-provider.md b/docs/examples/messaging/create-apns-provider.md new file mode 100644 index 0000000..68748aa --- /dev/null +++ b/docs/examples/messaging/create-apns-provider.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateApnsProvider( + "", + "", + messaging.WithCreateApnsProviderAuthKey(""), + messaging.WithCreateApnsProviderAuthKeyId(""), + messaging.WithCreateApnsProviderTeamId(""), + messaging.WithCreateApnsProviderBundleId(""), + messaging.WithCreateApnsProviderSandbox(false), + messaging.WithCreateApnsProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-email.md b/docs/examples/messaging/create-email.md new file mode 100644 index 0000000..334c1cc --- /dev/null +++ b/docs/examples/messaging/create-email.md @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateEmail( + "", + "", + "", + messaging.WithCreateEmailTopics([]interface{}{}), + messaging.WithCreateEmailUsers([]interface{}{}), + messaging.WithCreateEmailTargets([]interface{}{}), + messaging.WithCreateEmailCc([]interface{}{}), + messaging.WithCreateEmailBcc([]interface{}{}), + messaging.WithCreateEmailAttachments([]interface{}{}), + messaging.WithCreateEmailDraft(false), + messaging.WithCreateEmailHtml(false), + messaging.WithCreateEmailScheduledAt(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-fcm-provider.md b/docs/examples/messaging/create-fcm-provider.md new file mode 100644 index 0000000..68029a7 --- /dev/null +++ b/docs/examples/messaging/create-fcm-provider.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateFcmProvider( + "", + "", + messaging.WithCreateFcmProviderServiceAccountJSON(map[string]interface{}{}), + messaging.WithCreateFcmProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-mailgun-provider.md b/docs/examples/messaging/create-mailgun-provider.md new file mode 100644 index 0000000..401b94c --- /dev/null +++ b/docs/examples/messaging/create-mailgun-provider.md @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateMailgunProvider( + "", + "", + messaging.WithCreateMailgunProviderApiKey(""), + messaging.WithCreateMailgunProviderDomain(""), + messaging.WithCreateMailgunProviderIsEuRegion(false), + messaging.WithCreateMailgunProviderFromName(""), + messaging.WithCreateMailgunProviderFromEmail("email@example.com"), + messaging.WithCreateMailgunProviderReplyToName(""), + messaging.WithCreateMailgunProviderReplyToEmail("email@example.com"), + messaging.WithCreateMailgunProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-msg91provider.md b/docs/examples/messaging/create-msg91provider.md new file mode 100644 index 0000000..ac6a890 --- /dev/null +++ b/docs/examples/messaging/create-msg91provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateMsg91Provider( + "", + "", + messaging.WithCreateMsg91ProviderTemplateId(""), + messaging.WithCreateMsg91ProviderSenderId(""), + messaging.WithCreateMsg91ProviderAuthKey(""), + messaging.WithCreateMsg91ProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md new file mode 100644 index 0000000..14ea988 --- /dev/null +++ b/docs/examples/messaging/create-push.md @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreatePush( + "", + "", + "<BODY>", + messaging.WithCreatePushTopics([]interface{}{}), + messaging.WithCreatePushUsers([]interface{}{}), + messaging.WithCreatePushTargets([]interface{}{}), + messaging.WithCreatePushData(map[string]interface{}{}), + messaging.WithCreatePushAction("<ACTION>"), + messaging.WithCreatePushImage("[ID1:ID2]"), + messaging.WithCreatePushIcon("<ICON>"), + messaging.WithCreatePushSound("<SOUND>"), + messaging.WithCreatePushColor("<COLOR>"), + messaging.WithCreatePushTag("<TAG>"), + messaging.WithCreatePushBadge("<BADGE>"), + messaging.WithCreatePushDraft(false), + messaging.WithCreatePushScheduledAt(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-sendgrid-provider.md b/docs/examples/messaging/create-sendgrid-provider.md new file mode 100644 index 0000000..a9e9793 --- /dev/null +++ b/docs/examples/messaging/create-sendgrid-provider.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateSendgridProvider( + "<PROVIDER_ID>", + "<NAME>", + messaging.WithCreateSendgridProviderApiKey("<API_KEY>"), + messaging.WithCreateSendgridProviderFromName("<FROM_NAME>"), + messaging.WithCreateSendgridProviderFromEmail("email@example.com"), + messaging.WithCreateSendgridProviderReplyToName("<REPLY_TO_NAME>"), + messaging.WithCreateSendgridProviderReplyToEmail("email@example.com"), + messaging.WithCreateSendgridProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-sms.md b/docs/examples/messaging/create-sms.md new file mode 100644 index 0000000..1e5366d --- /dev/null +++ b/docs/examples/messaging/create-sms.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateSms( + "<MESSAGE_ID>", + "<CONTENT>", + messaging.WithCreateSmsTopics([]interface{}{}), + messaging.WithCreateSmsUsers([]interface{}{}), + messaging.WithCreateSmsTargets([]interface{}{}), + messaging.WithCreateSmsDraft(false), + messaging.WithCreateSmsScheduledAt(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-smtp-provider.md b/docs/examples/messaging/create-smtp-provider.md new file mode 100644 index 0000000..7dfbfce --- /dev/null +++ b/docs/examples/messaging/create-smtp-provider.md @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateSmtpProvider( + "<PROVIDER_ID>", + "<NAME>", + "<HOST>", + messaging.WithCreateSmtpProviderPort(1), + messaging.WithCreateSmtpProviderUsername("<USERNAME>"), + messaging.WithCreateSmtpProviderPassword("<PASSWORD>"), + messaging.WithCreateSmtpProviderEncryption("none"), + messaging.WithCreateSmtpProviderAutoTLS(false), + messaging.WithCreateSmtpProviderMailer("<MAILER>"), + messaging.WithCreateSmtpProviderFromName("<FROM_NAME>"), + messaging.WithCreateSmtpProviderFromEmail("email@example.com"), + messaging.WithCreateSmtpProviderReplyToName("<REPLY_TO_NAME>"), + messaging.WithCreateSmtpProviderReplyToEmail("email@example.com"), + messaging.WithCreateSmtpProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-subscriber.md b/docs/examples/messaging/create-subscriber.md new file mode 100644 index 0000000..699a821 --- /dev/null +++ b/docs/examples/messaging/create-subscriber.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetJWT("") // Your secret JSON Web Token + + service := messaging.NewMessaging(client) + response, error := service.CreateSubscriber( + "<TOPIC_ID>", + "<SUBSCRIBER_ID>", + "<TARGET_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-telesign-provider.md b/docs/examples/messaging/create-telesign-provider.md new file mode 100644 index 0000000..c4ba566 --- /dev/null +++ b/docs/examples/messaging/create-telesign-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateTelesignProvider( + "<PROVIDER_ID>", + "<NAME>", + messaging.WithCreateTelesignProviderFrom("+12065550100"), + messaging.WithCreateTelesignProviderCustomerId("<CUSTOMER_ID>"), + messaging.WithCreateTelesignProviderApiKey("<API_KEY>"), + messaging.WithCreateTelesignProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-textmagic-provider.md b/docs/examples/messaging/create-textmagic-provider.md new file mode 100644 index 0000000..7cb267b --- /dev/null +++ b/docs/examples/messaging/create-textmagic-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateTextmagicProvider( + "<PROVIDER_ID>", + "<NAME>", + messaging.WithCreateTextmagicProviderFrom("+12065550100"), + messaging.WithCreateTextmagicProviderUsername("<USERNAME>"), + messaging.WithCreateTextmagicProviderApiKey("<API_KEY>"), + messaging.WithCreateTextmagicProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-topic.md b/docs/examples/messaging/create-topic.md new file mode 100644 index 0000000..dcc85af --- /dev/null +++ b/docs/examples/messaging/create-topic.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateTopic( + "<TOPIC_ID>", + "<NAME>", + messaging.WithCreateTopicSubscribe(interface{}{"any"}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-twilio-provider.md b/docs/examples/messaging/create-twilio-provider.md new file mode 100644 index 0000000..a67ecf9 --- /dev/null +++ b/docs/examples/messaging/create-twilio-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateTwilioProvider( + "<PROVIDER_ID>", + "<NAME>", + messaging.WithCreateTwilioProviderFrom("+12065550100"), + messaging.WithCreateTwilioProviderAccountSid("<ACCOUNT_SID>"), + messaging.WithCreateTwilioProviderAuthToken("<AUTH_TOKEN>"), + messaging.WithCreateTwilioProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/create-vonage-provider.md b/docs/examples/messaging/create-vonage-provider.md new file mode 100644 index 0000000..e0a88f7 --- /dev/null +++ b/docs/examples/messaging/create-vonage-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.CreateVonageProvider( + "<PROVIDER_ID>", + "<NAME>", + messaging.WithCreateVonageProviderFrom("+12065550100"), + messaging.WithCreateVonageProviderApiKey("<API_KEY>"), + messaging.WithCreateVonageProviderApiSecret("<API_SECRET>"), + messaging.WithCreateVonageProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/delete-provider.md b/docs/examples/messaging/delete-provider.md new file mode 100644 index 0000000..6fffd44 --- /dev/null +++ b/docs/examples/messaging/delete-provider.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.DeleteProvider( + "<PROVIDER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/delete-subscriber.md b/docs/examples/messaging/delete-subscriber.md new file mode 100644 index 0000000..20585b1 --- /dev/null +++ b/docs/examples/messaging/delete-subscriber.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetJWT("") // Your secret JSON Web Token + + service := messaging.NewMessaging(client) + response, error := service.DeleteSubscriber( + "<TOPIC_ID>", + "<SUBSCRIBER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/delete-topic.md b/docs/examples/messaging/delete-topic.md new file mode 100644 index 0000000..4910530 --- /dev/null +++ b/docs/examples/messaging/delete-topic.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.DeleteTopic( + "<TOPIC_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/delete.md b/docs/examples/messaging/delete.md new file mode 100644 index 0000000..0fe8edf --- /dev/null +++ b/docs/examples/messaging/delete.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.Delete( + "<MESSAGE_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/get-message.md b/docs/examples/messaging/get-message.md new file mode 100644 index 0000000..fbeb6d2 --- /dev/null +++ b/docs/examples/messaging/get-message.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.GetMessage( + "<MESSAGE_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/get-provider.md b/docs/examples/messaging/get-provider.md new file mode 100644 index 0000000..691f94d --- /dev/null +++ b/docs/examples/messaging/get-provider.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.GetProvider( + "<PROVIDER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/get-subscriber.md b/docs/examples/messaging/get-subscriber.md new file mode 100644 index 0000000..88db72e --- /dev/null +++ b/docs/examples/messaging/get-subscriber.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.GetSubscriber( + "<TOPIC_ID>", + "<SUBSCRIBER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/get-topic.md b/docs/examples/messaging/get-topic.md new file mode 100644 index 0000000..753bd19 --- /dev/null +++ b/docs/examples/messaging/get-topic.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.GetTopic( + "<TOPIC_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-message-logs.md b/docs/examples/messaging/list-message-logs.md new file mode 100644 index 0000000..4a78305 --- /dev/null +++ b/docs/examples/messaging/list-message-logs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListMessageLogs( + "<MESSAGE_ID>", + messaging.WithListMessageLogsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-messages.md b/docs/examples/messaging/list-messages.md new file mode 100644 index 0000000..5203f11 --- /dev/null +++ b/docs/examples/messaging/list-messages.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListMessages( + messaging.WithListMessagesQueries([]interface{}{}), + messaging.WithListMessagesSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-provider-logs.md b/docs/examples/messaging/list-provider-logs.md new file mode 100644 index 0000000..4c11219 --- /dev/null +++ b/docs/examples/messaging/list-provider-logs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListProviderLogs( + "<PROVIDER_ID>", + messaging.WithListProviderLogsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-providers.md b/docs/examples/messaging/list-providers.md new file mode 100644 index 0000000..2c73349 --- /dev/null +++ b/docs/examples/messaging/list-providers.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListProviders( + messaging.WithListProvidersQueries([]interface{}{}), + messaging.WithListProvidersSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-subscriber-logs.md b/docs/examples/messaging/list-subscriber-logs.md new file mode 100644 index 0000000..e424e96 --- /dev/null +++ b/docs/examples/messaging/list-subscriber-logs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListSubscriberLogs( + "<SUBSCRIBER_ID>", + messaging.WithListSubscriberLogsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-subscribers.md b/docs/examples/messaging/list-subscribers.md new file mode 100644 index 0000000..beda97f --- /dev/null +++ b/docs/examples/messaging/list-subscribers.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListSubscribers( + "<TOPIC_ID>", + messaging.WithListSubscribersQueries([]interface{}{}), + messaging.WithListSubscribersSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-targets.md b/docs/examples/messaging/list-targets.md new file mode 100644 index 0000000..5058a88 --- /dev/null +++ b/docs/examples/messaging/list-targets.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListTargets( + "<MESSAGE_ID>", + messaging.WithListTargetsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-topic-logs.md b/docs/examples/messaging/list-topic-logs.md new file mode 100644 index 0000000..9b6a764 --- /dev/null +++ b/docs/examples/messaging/list-topic-logs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListTopicLogs( + "<TOPIC_ID>", + messaging.WithListTopicLogsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/list-topics.md b/docs/examples/messaging/list-topics.md new file mode 100644 index 0000000..c0c1312 --- /dev/null +++ b/docs/examples/messaging/list-topics.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.ListTopics( + messaging.WithListTopicsQueries([]interface{}{}), + messaging.WithListTopicsSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-apns-provider.md b/docs/examples/messaging/update-apns-provider.md new file mode 100644 index 0000000..a3a3368 --- /dev/null +++ b/docs/examples/messaging/update-apns-provider.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateApnsProvider( + "<PROVIDER_ID>", + messaging.WithUpdateApnsProviderName("<NAME>"), + messaging.WithUpdateApnsProviderEnabled(false), + messaging.WithUpdateApnsProviderAuthKey("<AUTH_KEY>"), + messaging.WithUpdateApnsProviderAuthKeyId("<AUTH_KEY_ID>"), + messaging.WithUpdateApnsProviderTeamId("<TEAM_ID>"), + messaging.WithUpdateApnsProviderBundleId("<BUNDLE_ID>"), + messaging.WithUpdateApnsProviderSandbox(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-email.md b/docs/examples/messaging/update-email.md new file mode 100644 index 0000000..33f397b --- /dev/null +++ b/docs/examples/messaging/update-email.md @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateEmail( + "<MESSAGE_ID>", + messaging.WithUpdateEmailTopics([]interface{}{}), + messaging.WithUpdateEmailUsers([]interface{}{}), + messaging.WithUpdateEmailTargets([]interface{}{}), + messaging.WithUpdateEmailSubject("<SUBJECT>"), + messaging.WithUpdateEmailContent("<CONTENT>"), + messaging.WithUpdateEmailDraft(false), + messaging.WithUpdateEmailHtml(false), + messaging.WithUpdateEmailCc([]interface{}{}), + messaging.WithUpdateEmailBcc([]interface{}{}), + messaging.WithUpdateEmailScheduledAt(""), + messaging.WithUpdateEmailAttachments([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-fcm-provider.md b/docs/examples/messaging/update-fcm-provider.md new file mode 100644 index 0000000..db02b89 --- /dev/null +++ b/docs/examples/messaging/update-fcm-provider.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateFcmProvider( + "<PROVIDER_ID>", + messaging.WithUpdateFcmProviderName("<NAME>"), + messaging.WithUpdateFcmProviderEnabled(false), + messaging.WithUpdateFcmProviderServiceAccountJSON(map[string]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-mailgun-provider.md b/docs/examples/messaging/update-mailgun-provider.md new file mode 100644 index 0000000..690ace8 --- /dev/null +++ b/docs/examples/messaging/update-mailgun-provider.md @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateMailgunProvider( + "<PROVIDER_ID>", + messaging.WithUpdateMailgunProviderName("<NAME>"), + messaging.WithUpdateMailgunProviderApiKey("<API_KEY>"), + messaging.WithUpdateMailgunProviderDomain("<DOMAIN>"), + messaging.WithUpdateMailgunProviderIsEuRegion(false), + messaging.WithUpdateMailgunProviderEnabled(false), + messaging.WithUpdateMailgunProviderFromName("<FROM_NAME>"), + messaging.WithUpdateMailgunProviderFromEmail("email@example.com"), + messaging.WithUpdateMailgunProviderReplyToName("<REPLY_TO_NAME>"), + messaging.WithUpdateMailgunProviderReplyToEmail("<REPLY_TO_EMAIL>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-msg91provider.md b/docs/examples/messaging/update-msg91provider.md new file mode 100644 index 0000000..c86a3b9 --- /dev/null +++ b/docs/examples/messaging/update-msg91provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateMsg91Provider( + "<PROVIDER_ID>", + messaging.WithUpdateMsg91ProviderName("<NAME>"), + messaging.WithUpdateMsg91ProviderEnabled(false), + messaging.WithUpdateMsg91ProviderTemplateId("<TEMPLATE_ID>"), + messaging.WithUpdateMsg91ProviderSenderId("<SENDER_ID>"), + messaging.WithUpdateMsg91ProviderAuthKey("<AUTH_KEY>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md new file mode 100644 index 0000000..a2b9069 --- /dev/null +++ b/docs/examples/messaging/update-push.md @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdatePush( + "<MESSAGE_ID>", + messaging.WithUpdatePushTopics([]interface{}{}), + messaging.WithUpdatePushUsers([]interface{}{}), + messaging.WithUpdatePushTargets([]interface{}{}), + messaging.WithUpdatePushTitle("<TITLE>"), + messaging.WithUpdatePushBody("<BODY>"), + messaging.WithUpdatePushData(map[string]interface{}{}), + messaging.WithUpdatePushAction("<ACTION>"), + messaging.WithUpdatePushImage("[ID1:ID2]"), + messaging.WithUpdatePushIcon("<ICON>"), + messaging.WithUpdatePushSound("<SOUND>"), + messaging.WithUpdatePushColor("<COLOR>"), + messaging.WithUpdatePushTag("<TAG>"), + messaging.WithUpdatePushBadge(0), + messaging.WithUpdatePushDraft(false), + messaging.WithUpdatePushScheduledAt(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-sendgrid-provider.md b/docs/examples/messaging/update-sendgrid-provider.md new file mode 100644 index 0000000..6d8a632 --- /dev/null +++ b/docs/examples/messaging/update-sendgrid-provider.md @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateSendgridProvider( + "<PROVIDER_ID>", + messaging.WithUpdateSendgridProviderName("<NAME>"), + messaging.WithUpdateSendgridProviderEnabled(false), + messaging.WithUpdateSendgridProviderApiKey("<API_KEY>"), + messaging.WithUpdateSendgridProviderFromName("<FROM_NAME>"), + messaging.WithUpdateSendgridProviderFromEmail("email@example.com"), + messaging.WithUpdateSendgridProviderReplyToName("<REPLY_TO_NAME>"), + messaging.WithUpdateSendgridProviderReplyToEmail("<REPLY_TO_EMAIL>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-sms.md b/docs/examples/messaging/update-sms.md new file mode 100644 index 0000000..1053922 --- /dev/null +++ b/docs/examples/messaging/update-sms.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateSms( + "<MESSAGE_ID>", + messaging.WithUpdateSmsTopics([]interface{}{}), + messaging.WithUpdateSmsUsers([]interface{}{}), + messaging.WithUpdateSmsTargets([]interface{}{}), + messaging.WithUpdateSmsContent("<CONTENT>"), + messaging.WithUpdateSmsDraft(false), + messaging.WithUpdateSmsScheduledAt(""), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-smtp-provider.md b/docs/examples/messaging/update-smtp-provider.md new file mode 100644 index 0000000..cce3582 --- /dev/null +++ b/docs/examples/messaging/update-smtp-provider.md @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateSmtpProvider( + "<PROVIDER_ID>", + messaging.WithUpdateSmtpProviderName("<NAME>"), + messaging.WithUpdateSmtpProviderHost("<HOST>"), + messaging.WithUpdateSmtpProviderPort(1), + messaging.WithUpdateSmtpProviderUsername("<USERNAME>"), + messaging.WithUpdateSmtpProviderPassword("<PASSWORD>"), + messaging.WithUpdateSmtpProviderEncryption("none"), + messaging.WithUpdateSmtpProviderAutoTLS(false), + messaging.WithUpdateSmtpProviderMailer("<MAILER>"), + messaging.WithUpdateSmtpProviderFromName("<FROM_NAME>"), + messaging.WithUpdateSmtpProviderFromEmail("email@example.com"), + messaging.WithUpdateSmtpProviderReplyToName("<REPLY_TO_NAME>"), + messaging.WithUpdateSmtpProviderReplyToEmail("<REPLY_TO_EMAIL>"), + messaging.WithUpdateSmtpProviderEnabled(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-telesign-provider.md b/docs/examples/messaging/update-telesign-provider.md new file mode 100644 index 0000000..94696d6 --- /dev/null +++ b/docs/examples/messaging/update-telesign-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateTelesignProvider( + "<PROVIDER_ID>", + messaging.WithUpdateTelesignProviderName("<NAME>"), + messaging.WithUpdateTelesignProviderEnabled(false), + messaging.WithUpdateTelesignProviderCustomerId("<CUSTOMER_ID>"), + messaging.WithUpdateTelesignProviderApiKey("<API_KEY>"), + messaging.WithUpdateTelesignProviderFrom("<FROM>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-textmagic-provider.md b/docs/examples/messaging/update-textmagic-provider.md new file mode 100644 index 0000000..dcc4027 --- /dev/null +++ b/docs/examples/messaging/update-textmagic-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateTextmagicProvider( + "<PROVIDER_ID>", + messaging.WithUpdateTextmagicProviderName("<NAME>"), + messaging.WithUpdateTextmagicProviderEnabled(false), + messaging.WithUpdateTextmagicProviderUsername("<USERNAME>"), + messaging.WithUpdateTextmagicProviderApiKey("<API_KEY>"), + messaging.WithUpdateTextmagicProviderFrom("<FROM>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-topic.md b/docs/examples/messaging/update-topic.md new file mode 100644 index 0000000..a23d84e --- /dev/null +++ b/docs/examples/messaging/update-topic.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateTopic( + "<TOPIC_ID>", + messaging.WithUpdateTopicName("<NAME>"), + messaging.WithUpdateTopicSubscribe(interface{}{"any"}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-twilio-provider.md b/docs/examples/messaging/update-twilio-provider.md new file mode 100644 index 0000000..7415443 --- /dev/null +++ b/docs/examples/messaging/update-twilio-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateTwilioProvider( + "<PROVIDER_ID>", + messaging.WithUpdateTwilioProviderName("<NAME>"), + messaging.WithUpdateTwilioProviderEnabled(false), + messaging.WithUpdateTwilioProviderAccountSid("<ACCOUNT_SID>"), + messaging.WithUpdateTwilioProviderAuthToken("<AUTH_TOKEN>"), + messaging.WithUpdateTwilioProviderFrom("<FROM>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/messaging/update-vonage-provider.md b/docs/examples/messaging/update-vonage-provider.md new file mode 100644 index 0000000..ea832c8 --- /dev/null +++ b/docs/examples/messaging/update-vonage-provider.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/messaging" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := messaging.NewMessaging(client) + response, error := service.UpdateVonageProvider( + "<PROVIDER_ID>", + messaging.WithUpdateVonageProviderName("<NAME>"), + messaging.WithUpdateVonageProviderEnabled(false), + messaging.WithUpdateVonageProviderApiKey("<API_KEY>"), + messaging.WithUpdateVonageProviderApiSecret("<API_SECRET>"), + messaging.WithUpdateVonageProviderFrom("<FROM>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/create-bucket.md b/docs/examples/storage/create-bucket.md new file mode 100644 index 0000000..f58d082 --- /dev/null +++ b/docs/examples/storage/create-bucket.md @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := storage.NewStorage(client) + response, error := service.CreateBucket( + "<BUCKET_ID>", + "<NAME>", + storage.WithCreateBucketPermissions(interface{}{"read("any")"}), + storage.WithCreateBucketFileSecurity(false), + storage.WithCreateBucketEnabled(false), + storage.WithCreateBucketMaximumFileSize(1), + storage.WithCreateBucketAllowedFileExtensions([]interface{}{}), + storage.WithCreateBucketCompression("none"), + storage.WithCreateBucketEncryption(false), + storage.WithCreateBucketAntivirus(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md new file mode 100644 index 0000000..8f4d310 --- /dev/null +++ b/docs/examples/storage/create-file.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.CreateFile( + "<BUCKET_ID>", + "<FILE_ID>", + file.NewInputFile("/path/to/file.png", "file.png"), + storage.WithCreateFilePermissions(interface{}{"read("any")"}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/delete-bucket.md b/docs/examples/storage/delete-bucket.md new file mode 100644 index 0000000..9636c17 --- /dev/null +++ b/docs/examples/storage/delete-bucket.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := storage.NewStorage(client) + response, error := service.DeleteBucket( + "<BUCKET_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md new file mode 100644 index 0000000..79c0659 --- /dev/null +++ b/docs/examples/storage/delete-file.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.DeleteFile( + "<BUCKET_ID>", + "<FILE_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/get-bucket.md b/docs/examples/storage/get-bucket.md new file mode 100644 index 0000000..b47be00 --- /dev/null +++ b/docs/examples/storage/get-bucket.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := storage.NewStorage(client) + response, error := service.GetBucket( + "<BUCKET_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md new file mode 100644 index 0000000..46bc320 --- /dev/null +++ b/docs/examples/storage/get-file-download.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.GetFileDownload( + "<BUCKET_ID>", + "<FILE_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md new file mode 100644 index 0000000..47e4bcb --- /dev/null +++ b/docs/examples/storage/get-file-preview.md @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.GetFilePreview( + "<BUCKET_ID>", + "<FILE_ID>", + storage.WithGetFilePreviewWidth(0), + storage.WithGetFilePreviewHeight(0), + storage.WithGetFilePreviewGravity("center"), + storage.WithGetFilePreviewQuality(0), + storage.WithGetFilePreviewBorderWidth(0), + storage.WithGetFilePreviewBorderColor(""), + storage.WithGetFilePreviewBorderRadius(0), + storage.WithGetFilePreviewOpacity(0), + storage.WithGetFilePreviewRotation(-360), + storage.WithGetFilePreviewBackground(""), + storage.WithGetFilePreviewOutput("jpg"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md new file mode 100644 index 0000000..1dc2eaf --- /dev/null +++ b/docs/examples/storage/get-file-view.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.GetFileView( + "<BUCKET_ID>", + "<FILE_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md new file mode 100644 index 0000000..907a5b3 --- /dev/null +++ b/docs/examples/storage/get-file.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.GetFile( + "<BUCKET_ID>", + "<FILE_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/list-buckets.md b/docs/examples/storage/list-buckets.md new file mode 100644 index 0000000..c947764 --- /dev/null +++ b/docs/examples/storage/list-buckets.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := storage.NewStorage(client) + response, error := service.ListBuckets( + storage.WithListBucketsQueries([]interface{}{}), + storage.WithListBucketsSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md new file mode 100644 index 0000000..b08644c --- /dev/null +++ b/docs/examples/storage/list-files.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.ListFiles( + "<BUCKET_ID>", + storage.WithListFilesQueries([]interface{}{}), + storage.WithListFilesSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/update-bucket.md b/docs/examples/storage/update-bucket.md new file mode 100644 index 0000000..efd7398 --- /dev/null +++ b/docs/examples/storage/update-bucket.md @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := storage.NewStorage(client) + response, error := service.UpdateBucket( + "<BUCKET_ID>", + "<NAME>", + storage.WithUpdateBucketPermissions(interface{}{"read("any")"}), + storage.WithUpdateBucketFileSecurity(false), + storage.WithUpdateBucketEnabled(false), + storage.WithUpdateBucketMaximumFileSize(1), + storage.WithUpdateBucketAllowedFileExtensions([]interface{}{}), + storage.WithUpdateBucketCompression("none"), + storage.WithUpdateBucketEncryption(false), + storage.WithUpdateBucketAntivirus(false), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md new file mode 100644 index 0000000..eba2a23 --- /dev/null +++ b/docs/examples/storage/update-file.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/storage" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := storage.NewStorage(client) + response, error := service.UpdateFile( + "<BUCKET_ID>", + "<FILE_ID>", + storage.WithUpdateFileName("<NAME>"), + storage.WithUpdateFilePermissions(interface{}{"read("any")"}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md new file mode 100644 index 0000000..29f7279 --- /dev/null +++ b/docs/examples/teams/create-membership.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.CreateMembership( + "<TEAM_ID>", + []interface{}{}, + teams.WithCreateMembershipEmail("email@example.com"), + teams.WithCreateMembershipUserId("<USER_ID>"), + teams.WithCreateMembershipPhone("+12065550100"), + teams.WithCreateMembershipUrl("https://example.com"), + teams.WithCreateMembershipName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md new file mode 100644 index 0000000..f51afa1 --- /dev/null +++ b/docs/examples/teams/create.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.Create( + "<TEAM_ID>", + "<NAME>", + teams.WithCreateRoles([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md new file mode 100644 index 0000000..69cf916 --- /dev/null +++ b/docs/examples/teams/delete-membership.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.DeleteMembership( + "<TEAM_ID>", + "<MEMBERSHIP_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md new file mode 100644 index 0000000..4d418d8 --- /dev/null +++ b/docs/examples/teams/delete.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.Delete( + "<TEAM_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md new file mode 100644 index 0000000..fa796ac --- /dev/null +++ b/docs/examples/teams/get-membership.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.GetMembership( + "<TEAM_ID>", + "<MEMBERSHIP_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md new file mode 100644 index 0000000..7e99866 --- /dev/null +++ b/docs/examples/teams/get-prefs.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.GetPrefs( + "<TEAM_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md new file mode 100644 index 0000000..aba9ea1 --- /dev/null +++ b/docs/examples/teams/get.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.Get( + "<TEAM_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md new file mode 100644 index 0000000..9912353 --- /dev/null +++ b/docs/examples/teams/list-memberships.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.ListMemberships( + "<TEAM_ID>", + teams.WithListMembershipsQueries([]interface{}{}), + teams.WithListMembershipsSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md new file mode 100644 index 0000000..b936db2 --- /dev/null +++ b/docs/examples/teams/list.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.List( + teams.WithListQueries([]interface{}{}), + teams.WithListSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md new file mode 100644 index 0000000..0276462 --- /dev/null +++ b/docs/examples/teams/update-membership-status.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.UpdateMembershipStatus( + "<TEAM_ID>", + "<MEMBERSHIP_ID>", + "<USER_ID>", + "<SECRET>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md new file mode 100644 index 0000000..b500314 --- /dev/null +++ b/docs/examples/teams/update-membership.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.UpdateMembership( + "<TEAM_ID>", + "<MEMBERSHIP_ID>", + []interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md new file mode 100644 index 0000000..fc9546e --- /dev/null +++ b/docs/examples/teams/update-name.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.UpdateName( + "<TEAM_ID>", + "<NAME>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md new file mode 100644 index 0000000..b1b6d3c --- /dev/null +++ b/docs/examples/teams/update-prefs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/teams" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetSession("") // The user session to authenticate with + + service := teams.NewTeams(client) + response, error := service.UpdatePrefs( + "<TEAM_ID>", + map[string]interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-argon2user.md b/docs/examples/users/create-argon2user.md new file mode 100644 index 0000000..956e8af --- /dev/null +++ b/docs/examples/users/create-argon2user.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateArgon2User( + "<USER_ID>", + "email@example.com", + "password", + users.WithCreateArgon2UserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-bcrypt-user.md b/docs/examples/users/create-bcrypt-user.md new file mode 100644 index 0000000..9ca9e59 --- /dev/null +++ b/docs/examples/users/create-bcrypt-user.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateBcryptUser( + "<USER_ID>", + "email@example.com", + "password", + users.WithCreateBcryptUserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-j-w-t.md b/docs/examples/users/create-j-w-t.md new file mode 100644 index 0000000..ebf592e --- /dev/null +++ b/docs/examples/users/create-j-w-t.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateJWT( + "<USER_ID>", + users.WithCreateJWTSessionId("<SESSION_ID>"), + users.WithCreateJWTDuration(0), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-m-d5user.md b/docs/examples/users/create-m-d5user.md new file mode 100644 index 0000000..f1d7fdb --- /dev/null +++ b/docs/examples/users/create-m-d5user.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateMD5User( + "<USER_ID>", + "email@example.com", + "password", + users.WithCreateMD5UserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-mfa-recovery-codes.md b/docs/examples/users/create-mfa-recovery-codes.md new file mode 100644 index 0000000..3896452 --- /dev/null +++ b/docs/examples/users/create-mfa-recovery-codes.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateMfaRecoveryCodes( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-p-h-pass-user.md b/docs/examples/users/create-p-h-pass-user.md new file mode 100644 index 0000000..b3ee544 --- /dev/null +++ b/docs/examples/users/create-p-h-pass-user.md @@ -0,0 +1,29 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreatePHPassUser( + "<USER_ID>", + "email@example.com", + "password", + users.WithCreatePHPassUserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-s-h-a-user.md b/docs/examples/users/create-s-h-a-user.md new file mode 100644 index 0000000..c09098f --- /dev/null +++ b/docs/examples/users/create-s-h-a-user.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateSHAUser( + "<USER_ID>", + "email@example.com", + "password", + users.WithCreateSHAUserPasswordVersion("sha1"), + users.WithCreateSHAUserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-scrypt-modified-user.md b/docs/examples/users/create-scrypt-modified-user.md new file mode 100644 index 0000000..e6d765c --- /dev/null +++ b/docs/examples/users/create-scrypt-modified-user.md @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateScryptModifiedUser( + "<USER_ID>", + "email@example.com", + "password", + "<PASSWORD_SALT>", + "<PASSWORD_SALT_SEPARATOR>", + "<PASSWORD_SIGNER_KEY>", + users.WithCreateScryptModifiedUserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-scrypt-user.md b/docs/examples/users/create-scrypt-user.md new file mode 100644 index 0000000..872ca43 --- /dev/null +++ b/docs/examples/users/create-scrypt-user.md @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateScryptUser( + "<USER_ID>", + "email@example.com", + "password", + "<PASSWORD_SALT>", + 0, + 0, + 0, + 0, + users.WithCreateScryptUserName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-session.md b/docs/examples/users/create-session.md new file mode 100644 index 0000000..a394e03 --- /dev/null +++ b/docs/examples/users/create-session.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateSession( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-target.md b/docs/examples/users/create-target.md new file mode 100644 index 0000000..ff06ebc --- /dev/null +++ b/docs/examples/users/create-target.md @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateTarget( + "<USER_ID>", + "<TARGET_ID>", + "email", + "<IDENTIFIER>", + users.WithCreateTargetProviderId("<PROVIDER_ID>"), + users.WithCreateTargetName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create-token.md b/docs/examples/users/create-token.md new file mode 100644 index 0000000..a0930c6 --- /dev/null +++ b/docs/examples/users/create-token.md @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.CreateToken( + "<USER_ID>", + users.WithCreateTokenLength(4), + users.WithCreateTokenExpire(60), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/create.md b/docs/examples/users/create.md new file mode 100644 index 0000000..d5e7399 --- /dev/null +++ b/docs/examples/users/create.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.Create( + "<USER_ID>", + users.WithCreateEmail("email@example.com"), + users.WithCreatePhone("+12065550100"), + users.WithCreatePassword(""), + users.WithCreateName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/delete-identity.md b/docs/examples/users/delete-identity.md new file mode 100644 index 0000000..53e556c --- /dev/null +++ b/docs/examples/users/delete-identity.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.DeleteIdentity( + "<IDENTITY_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/delete-mfa-authenticator.md b/docs/examples/users/delete-mfa-authenticator.md new file mode 100644 index 0000000..752aeed --- /dev/null +++ b/docs/examples/users/delete-mfa-authenticator.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.DeleteMfaAuthenticator( + "<USER_ID>", + "totp", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/delete-session.md b/docs/examples/users/delete-session.md new file mode 100644 index 0000000..ca398ff --- /dev/null +++ b/docs/examples/users/delete-session.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.DeleteSession( + "<USER_ID>", + "<SESSION_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/delete-sessions.md b/docs/examples/users/delete-sessions.md new file mode 100644 index 0000000..2845131 --- /dev/null +++ b/docs/examples/users/delete-sessions.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.DeleteSessions( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/delete-target.md b/docs/examples/users/delete-target.md new file mode 100644 index 0000000..e3b60ad --- /dev/null +++ b/docs/examples/users/delete-target.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.DeleteTarget( + "<USER_ID>", + "<TARGET_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/delete.md b/docs/examples/users/delete.md new file mode 100644 index 0000000..5289ac4 --- /dev/null +++ b/docs/examples/users/delete.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.Delete( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/get-mfa-recovery-codes.md b/docs/examples/users/get-mfa-recovery-codes.md new file mode 100644 index 0000000..71e083b --- /dev/null +++ b/docs/examples/users/get-mfa-recovery-codes.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.GetMfaRecoveryCodes( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/get-prefs.md b/docs/examples/users/get-prefs.md new file mode 100644 index 0000000..10f4e82 --- /dev/null +++ b/docs/examples/users/get-prefs.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.GetPrefs( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/get-target.md b/docs/examples/users/get-target.md new file mode 100644 index 0000000..08f444d --- /dev/null +++ b/docs/examples/users/get-target.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.GetTarget( + "<USER_ID>", + "<TARGET_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/get.md b/docs/examples/users/get.md new file mode 100644 index 0000000..fe90b0d --- /dev/null +++ b/docs/examples/users/get.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.Get( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list-identities.md b/docs/examples/users/list-identities.md new file mode 100644 index 0000000..a60d0df --- /dev/null +++ b/docs/examples/users/list-identities.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.ListIdentities( + users.WithListIdentitiesQueries([]interface{}{}), + users.WithListIdentitiesSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list-logs.md b/docs/examples/users/list-logs.md new file mode 100644 index 0000000..3d47e19 --- /dev/null +++ b/docs/examples/users/list-logs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.ListLogs( + "<USER_ID>", + users.WithListLogsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list-memberships.md b/docs/examples/users/list-memberships.md new file mode 100644 index 0000000..25386ee --- /dev/null +++ b/docs/examples/users/list-memberships.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.ListMemberships( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list-mfa-factors.md b/docs/examples/users/list-mfa-factors.md new file mode 100644 index 0000000..1d1961b --- /dev/null +++ b/docs/examples/users/list-mfa-factors.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.ListMfaFactors( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list-sessions.md b/docs/examples/users/list-sessions.md new file mode 100644 index 0000000..63752d8 --- /dev/null +++ b/docs/examples/users/list-sessions.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.ListSessions( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list-targets.md b/docs/examples/users/list-targets.md new file mode 100644 index 0000000..594c017 --- /dev/null +++ b/docs/examples/users/list-targets.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.ListTargets( + "<USER_ID>", + users.WithListTargetsQueries([]interface{}{}), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/list.md b/docs/examples/users/list.md new file mode 100644 index 0000000..d610211 --- /dev/null +++ b/docs/examples/users/list.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.List( + users.WithListQueries([]interface{}{}), + users.WithListSearch("<SEARCH>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-email-verification.md b/docs/examples/users/update-email-verification.md new file mode 100644 index 0000000..82c0d31 --- /dev/null +++ b/docs/examples/users/update-email-verification.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateEmailVerification( + "<USER_ID>", + false, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-email.md b/docs/examples/users/update-email.md new file mode 100644 index 0000000..f76e855 --- /dev/null +++ b/docs/examples/users/update-email.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateEmail( + "<USER_ID>", + "email@example.com", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-labels.md b/docs/examples/users/update-labels.md new file mode 100644 index 0000000..3f52c6d --- /dev/null +++ b/docs/examples/users/update-labels.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateLabels( + "<USER_ID>", + []interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-mfa-recovery-codes.md b/docs/examples/users/update-mfa-recovery-codes.md new file mode 100644 index 0000000..b55e5a9 --- /dev/null +++ b/docs/examples/users/update-mfa-recovery-codes.md @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateMfaRecoveryCodes( + "<USER_ID>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-mfa.md b/docs/examples/users/update-mfa.md new file mode 100644 index 0000000..99b06ce --- /dev/null +++ b/docs/examples/users/update-mfa.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateMfa( + "<USER_ID>", + false, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-name.md b/docs/examples/users/update-name.md new file mode 100644 index 0000000..d8a734d --- /dev/null +++ b/docs/examples/users/update-name.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateName( + "<USER_ID>", + "<NAME>", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-password.md b/docs/examples/users/update-password.md new file mode 100644 index 0000000..44a8294 --- /dev/null +++ b/docs/examples/users/update-password.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdatePassword( + "<USER_ID>", + "", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-phone-verification.md b/docs/examples/users/update-phone-verification.md new file mode 100644 index 0000000..d55ddfb --- /dev/null +++ b/docs/examples/users/update-phone-verification.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdatePhoneVerification( + "<USER_ID>", + false, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-phone.md b/docs/examples/users/update-phone.md new file mode 100644 index 0000000..8344190 --- /dev/null +++ b/docs/examples/users/update-phone.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdatePhone( + "<USER_ID>", + "+12065550100", + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-prefs.md b/docs/examples/users/update-prefs.md new file mode 100644 index 0000000..178e02d --- /dev/null +++ b/docs/examples/users/update-prefs.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdatePrefs( + "<USER_ID>", + map[string]interface{}{}, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-status.md b/docs/examples/users/update-status.md new file mode 100644 index 0000000..9572639 --- /dev/null +++ b/docs/examples/users/update-status.md @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateStatus( + "<USER_ID>", + false, + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/docs/examples/users/update-target.md b/docs/examples/users/update-target.md new file mode 100644 index 0000000..79ee462 --- /dev/null +++ b/docs/examples/users/update-target.md @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +func main() { + client := client.NewClient() + + client.SetEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint + client.SetProject("") // Your project ID + client.SetKey("") // Your secret API key + + service := users.NewUsers(client) + response, error := service.UpdateTarget( + "<USER_ID>", + "<TARGET_ID>", + users.WithUpdateTargetIdentifier("<IDENTIFIER>"), + users.WithUpdateTargetProviderId("<PROVIDER_ID>"), + users.WithUpdateTargetName("<NAME>"), + ) + + if error != nil { + panic(error) + } + + fmt.Println(response) +} diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..3b2d923 --- /dev/null +++ b/example/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "log" + "os" + "time" + + "github.com/appwrite/sdk-for-go/appwrite" +) + +const ( + EmptyParentDocument = "" + EmptyParentProperty = "" + EmptyParentPropertyType = "" +) + +func main() { + var EmptyArray = []interface{}{} + + client := appwrite.NewClient() + client.SetEndpoint(os.Getenv("YOUR_ENDPOINT")) + client.SetProject(os.Getenv("YOUR_PROJECT_ID")) + client.SetKey(os.Getenv("YOUR_KEY")) + client.SetTimeout(10 * time.Second) + + db := appwrite.NewDatabases(client) + data := map[string]string{ + "hello": "world", + } + doc, err := db.CreateDocument( + os.Getenv("DATABASE_ID"), + os.Getenv("COLLECTION_ID"), + os.Getenv("DOCUMENT_ID"), + data, + EmptyArray, + ) + if err != nil { + log.Printf("Error creating document: %v", err) + } + log.Printf("Created document: %v", doc) +} diff --git a/file/inputFile.go b/file/inputFile.go new file mode 100644 index 0000000..73d2c44 --- /dev/null +++ b/file/inputFile.go @@ -0,0 +1,15 @@ +package file + +type InputFile struct { + Name string + Path string + Data []byte +} + +func NewInputFile(path string, name string) InputFile { + return InputFile{ + Name: name, + Path: path, + Data: nil, + } +} diff --git a/functions/functions.go b/functions/functions.go new file mode 100644 index 0000000..63eb10d --- /dev/null +++ b/functions/functions.go @@ -0,0 +1,1419 @@ +package functions + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/file" + "strings" +) + +// Functions service +type Functions struct { + client client.Client +} + +func NewFunctions(clt client.Client) *Functions { + return &Functions{ + client: clt, + } +} + + +type ListOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListOption func(*ListOptions) +func WithListQueries(v []interface{}) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListSearch(v string) ListOption { + return func(o *ListOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// List get a list of all the project's functions. You can use the query +// params to filter your results. +func (srv *Functions) List(optionalSetters ...ListOption)(*models.FunctionList, error) { + path := "/functions" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.FunctionList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.FunctionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateOptions struct { + Execute []interface{} + Events []interface{} + Schedule string + Timeout int + Enabled bool + Logging bool + Entrypoint string + Commands string + Scopes []interface{} + InstallationId string + ProviderRepositoryId string + ProviderBranch string + ProviderSilentMode bool + ProviderRootDirectory string + TemplateRepository string + TemplateOwner string + TemplateRootDirectory string + TemplateBranch string + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Execute": false, + "Events": false, + "Schedule": false, + "Timeout": false, + "Enabled": false, + "Logging": false, + "Entrypoint": false, + "Commands": false, + "Scopes": false, + "InstallationId": false, + "ProviderRepositoryId": false, + "ProviderBranch": false, + "ProviderSilentMode": false, + "ProviderRootDirectory": false, + "TemplateRepository": false, + "TemplateOwner": false, + "TemplateRootDirectory": false, + "TemplateBranch": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func WithCreateExecute(v []interface{}) CreateOption { + return func(o *CreateOptions) { + o.Execute = v + o.enabledSetters["Execute"] = true + } +} +func WithCreateEvents(v []interface{}) CreateOption { + return func(o *CreateOptions) { + o.Events = v + o.enabledSetters["Events"] = true + } +} +func WithCreateSchedule(v string) CreateOption { + return func(o *CreateOptions) { + o.Schedule = v + o.enabledSetters["Schedule"] = true + } +} +func WithCreateTimeout(v int) CreateOption { + return func(o *CreateOptions) { + o.Timeout = v + o.enabledSetters["Timeout"] = true + } +} +func WithCreateEnabled(v bool) CreateOption { + return func(o *CreateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithCreateLogging(v bool) CreateOption { + return func(o *CreateOptions) { + o.Logging = v + o.enabledSetters["Logging"] = true + } +} +func WithCreateEntrypoint(v string) CreateOption { + return func(o *CreateOptions) { + o.Entrypoint = v + o.enabledSetters["Entrypoint"] = true + } +} +func WithCreateCommands(v string) CreateOption { + return func(o *CreateOptions) { + o.Commands = v + o.enabledSetters["Commands"] = true + } +} +func WithCreateScopes(v []interface{}) CreateOption { + return func(o *CreateOptions) { + o.Scopes = v + o.enabledSetters["Scopes"] = true + } +} +func WithCreateInstallationId(v string) CreateOption { + return func(o *CreateOptions) { + o.InstallationId = v + o.enabledSetters["InstallationId"] = true + } +} +func WithCreateProviderRepositoryId(v string) CreateOption { + return func(o *CreateOptions) { + o.ProviderRepositoryId = v + o.enabledSetters["ProviderRepositoryId"] = true + } +} +func WithCreateProviderBranch(v string) CreateOption { + return func(o *CreateOptions) { + o.ProviderBranch = v + o.enabledSetters["ProviderBranch"] = true + } +} +func WithCreateProviderSilentMode(v bool) CreateOption { + return func(o *CreateOptions) { + o.ProviderSilentMode = v + o.enabledSetters["ProviderSilentMode"] = true + } +} +func WithCreateProviderRootDirectory(v string) CreateOption { + return func(o *CreateOptions) { + o.ProviderRootDirectory = v + o.enabledSetters["ProviderRootDirectory"] = true + } +} +func WithCreateTemplateRepository(v string) CreateOption { + return func(o *CreateOptions) { + o.TemplateRepository = v + o.enabledSetters["TemplateRepository"] = true + } +} +func WithCreateTemplateOwner(v string) CreateOption { + return func(o *CreateOptions) { + o.TemplateOwner = v + o.enabledSetters["TemplateOwner"] = true + } +} +func WithCreateTemplateRootDirectory(v string) CreateOption { + return func(o *CreateOptions) { + o.TemplateRootDirectory = v + o.enabledSetters["TemplateRootDirectory"] = true + } +} +func WithCreateTemplateBranch(v string) CreateOption { + return func(o *CreateOptions) { + o.TemplateBranch = v + o.enabledSetters["TemplateBranch"] = true + } +} + +// Create create a new function. You can pass a list of +// [permissions](https://appwrite.io/docs/permissions) to allow different +// project users or team with access to execute the function using the client +// API. +func (srv *Functions) Create(FunctionId string, Name string, Runtime string, optionalSetters ...CreateOption)(*models.Function, error) { + path := "/functions" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["name"] = Name + params["runtime"] = Runtime + if options.enabledSetters["Execute"] { + params["execute"] = options.Execute + } + if options.enabledSetters["Events"] { + params["events"] = options.Events + } + if options.enabledSetters["Schedule"] { + params["schedule"] = options.Schedule + } + if options.enabledSetters["Timeout"] { + params["timeout"] = options.Timeout + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["Logging"] { + params["logging"] = options.Logging + } + if options.enabledSetters["Entrypoint"] { + params["entrypoint"] = options.Entrypoint + } + if options.enabledSetters["Commands"] { + params["commands"] = options.Commands + } + if options.enabledSetters["Scopes"] { + params["scopes"] = options.Scopes + } + if options.enabledSetters["InstallationId"] { + params["installationId"] = options.InstallationId + } + if options.enabledSetters["ProviderRepositoryId"] { + params["providerRepositoryId"] = options.ProviderRepositoryId + } + if options.enabledSetters["ProviderBranch"] { + params["providerBranch"] = options.ProviderBranch + } + if options.enabledSetters["ProviderSilentMode"] { + params["providerSilentMode"] = options.ProviderSilentMode + } + if options.enabledSetters["ProviderRootDirectory"] { + params["providerRootDirectory"] = options.ProviderRootDirectory + } + if options.enabledSetters["TemplateRepository"] { + params["templateRepository"] = options.TemplateRepository + } + if options.enabledSetters["TemplateOwner"] { + params["templateOwner"] = options.TemplateOwner + } + if options.enabledSetters["TemplateRootDirectory"] { + params["templateRootDirectory"] = options.TemplateRootDirectory + } + if options.enabledSetters["TemplateBranch"] { + params["templateBranch"] = options.TemplateBranch + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Function + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Function) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListRuntimes get a list of all runtimes that are currently active on your +// instance. +func (srv *Functions) ListRuntimes()(*models.RuntimeList, error) { + path := "/functions/runtimes" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.RuntimeList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.RuntimeList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a function by its unique ID. +func (srv *Functions) Get(FunctionId string)(*models.Function, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Function + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Function) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateOptions struct { + Runtime string + Execute []interface{} + Events []interface{} + Schedule string + Timeout int + Enabled bool + Logging bool + Entrypoint string + Commands string + Scopes []interface{} + InstallationId string + ProviderRepositoryId string + ProviderBranch string + ProviderSilentMode bool + ProviderRootDirectory string + enabledSetters map[string]bool +} +func (options UpdateOptions) New() *UpdateOptions { + options.enabledSetters = map[string]bool{ + "Runtime": false, + "Execute": false, + "Events": false, + "Schedule": false, + "Timeout": false, + "Enabled": false, + "Logging": false, + "Entrypoint": false, + "Commands": false, + "Scopes": false, + "InstallationId": false, + "ProviderRepositoryId": false, + "ProviderBranch": false, + "ProviderSilentMode": false, + "ProviderRootDirectory": false, + } + return &options +} +type UpdateOption func(*UpdateOptions) +func WithUpdateRuntime(v string) UpdateOption { + return func(o *UpdateOptions) { + o.Runtime = v + o.enabledSetters["Runtime"] = true + } +} +func WithUpdateExecute(v []interface{}) UpdateOption { + return func(o *UpdateOptions) { + o.Execute = v + o.enabledSetters["Execute"] = true + } +} +func WithUpdateEvents(v []interface{}) UpdateOption { + return func(o *UpdateOptions) { + o.Events = v + o.enabledSetters["Events"] = true + } +} +func WithUpdateSchedule(v string) UpdateOption { + return func(o *UpdateOptions) { + o.Schedule = v + o.enabledSetters["Schedule"] = true + } +} +func WithUpdateTimeout(v int) UpdateOption { + return func(o *UpdateOptions) { + o.Timeout = v + o.enabledSetters["Timeout"] = true + } +} +func WithUpdateEnabled(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateLogging(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Logging = v + o.enabledSetters["Logging"] = true + } +} +func WithUpdateEntrypoint(v string) UpdateOption { + return func(o *UpdateOptions) { + o.Entrypoint = v + o.enabledSetters["Entrypoint"] = true + } +} +func WithUpdateCommands(v string) UpdateOption { + return func(o *UpdateOptions) { + o.Commands = v + o.enabledSetters["Commands"] = true + } +} +func WithUpdateScopes(v []interface{}) UpdateOption { + return func(o *UpdateOptions) { + o.Scopes = v + o.enabledSetters["Scopes"] = true + } +} +func WithUpdateInstallationId(v string) UpdateOption { + return func(o *UpdateOptions) { + o.InstallationId = v + o.enabledSetters["InstallationId"] = true + } +} +func WithUpdateProviderRepositoryId(v string) UpdateOption { + return func(o *UpdateOptions) { + o.ProviderRepositoryId = v + o.enabledSetters["ProviderRepositoryId"] = true + } +} +func WithUpdateProviderBranch(v string) UpdateOption { + return func(o *UpdateOptions) { + o.ProviderBranch = v + o.enabledSetters["ProviderBranch"] = true + } +} +func WithUpdateProviderSilentMode(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.ProviderSilentMode = v + o.enabledSetters["ProviderSilentMode"] = true + } +} +func WithUpdateProviderRootDirectory(v string) UpdateOption { + return func(o *UpdateOptions) { + o.ProviderRootDirectory = v + o.enabledSetters["ProviderRootDirectory"] = true + } +} + +// Update update function by its unique ID. +func (srv *Functions) Update(FunctionId string, Name string, optionalSetters ...UpdateOption)(*models.Function, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}") + options := UpdateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["name"] = Name + if options.enabledSetters["Runtime"] { + params["runtime"] = options.Runtime + } + if options.enabledSetters["Execute"] { + params["execute"] = options.Execute + } + if options.enabledSetters["Events"] { + params["events"] = options.Events + } + if options.enabledSetters["Schedule"] { + params["schedule"] = options.Schedule + } + if options.enabledSetters["Timeout"] { + params["timeout"] = options.Timeout + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["Logging"] { + params["logging"] = options.Logging + } + if options.enabledSetters["Entrypoint"] { + params["entrypoint"] = options.Entrypoint + } + if options.enabledSetters["Commands"] { + params["commands"] = options.Commands + } + if options.enabledSetters["Scopes"] { + params["scopes"] = options.Scopes + } + if options.enabledSetters["InstallationId"] { + params["installationId"] = options.InstallationId + } + if options.enabledSetters["ProviderRepositoryId"] { + params["providerRepositoryId"] = options.ProviderRepositoryId + } + if options.enabledSetters["ProviderBranch"] { + params["providerBranch"] = options.ProviderBranch + } + if options.enabledSetters["ProviderSilentMode"] { + params["providerSilentMode"] = options.ProviderSilentMode + } + if options.enabledSetters["ProviderRootDirectory"] { + params["providerRootDirectory"] = options.ProviderRootDirectory + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Function + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Function) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a function by its unique ID. +func (srv *Functions) Delete(FunctionId string)(*interface{}, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListDeploymentsOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListDeploymentsOptions) New() *ListDeploymentsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListDeploymentsOption func(*ListDeploymentsOptions) +func WithListDeploymentsQueries(v []interface{}) ListDeploymentsOption { + return func(o *ListDeploymentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListDeploymentsSearch(v string) ListDeploymentsOption { + return func(o *ListDeploymentsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListDeployments get a list of all the project's code deployments. You can +// use the query params to filter your results. +func (srv *Functions) ListDeployments(FunctionId string, optionalSetters ...ListDeploymentsOption)(*models.DeploymentList, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}/deployments") + options := ListDeploymentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.DeploymentList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.DeploymentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateDeploymentOptions struct { + Entrypoint string + Commands string + enabledSetters map[string]bool +} +func (options CreateDeploymentOptions) New() *CreateDeploymentOptions { + options.enabledSetters = map[string]bool{ + "Entrypoint": false, + "Commands": false, + } + return &options +} +type CreateDeploymentOption func(*CreateDeploymentOptions) +func WithCreateDeploymentEntrypoint(v string) CreateDeploymentOption { + return func(o *CreateDeploymentOptions) { + o.Entrypoint = v + o.enabledSetters["Entrypoint"] = true + } +} +func WithCreateDeploymentCommands(v string) CreateDeploymentOption { + return func(o *CreateDeploymentOptions) { + o.Commands = v + o.enabledSetters["Commands"] = true + } +} + +// CreateDeployment create a new function code deployment. Use this endpoint +// to upload a new version of your code function. To execute your newly +// uploaded code, you'll need to update the function's deployment to use your +// new deployment UID. +// +// This endpoint accepts a tar.gz file compressed with your code. Make sure to +// include any dependencies your code has within the compressed file. You can +// learn more about code packaging in the [Appwrite Cloud Functions +// tutorial](https://appwrite.io/docs/functions). +// +// Use the "command" param to set the entrypoint used to execute your code. +func (srv *Functions) CreateDeployment(FunctionId string, Code file.InputFile, Activate bool, optionalSetters ...CreateDeploymentOption)(*models.Deployment, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}/deployments") + options := CreateDeploymentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["code"] = Code + params["activate"] = Activate + if options.enabledSetters["Entrypoint"] { + params["entrypoint"] = options.Entrypoint + } + if options.enabledSetters["Commands"] { + params["commands"] = options.Commands + } + headers := map[string]interface{}{ + "content-type": "multipart/form-data", + } + + paramName := "code" + + + uploadId := "" + + resp, err := srv.client.FileUpload(path, headers, params, paramName, uploadId) + if err != nil { + return nil, err + } + var parsed models.Deployment + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Deployment) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil +} + +// GetDeployment get a code deployment by its unique ID. +func (srv *Functions) GetDeployment(FunctionId string, DeploymentId string)(*models.Deployment, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["deploymentId"] = DeploymentId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Deployment + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Deployment) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateDeployment update the function code deployment ID using the unique +// function ID. Use this endpoint to switch the code deployment that should be +// executed by the execution endpoint. +func (srv *Functions) UpdateDeployment(FunctionId string, DeploymentId string)(*models.Function, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["deploymentId"] = DeploymentId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Function + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Function) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteDeployment delete a code deployment by its unique ID. +func (srv *Functions) DeleteDeployment(FunctionId string, DeploymentId string)(*interface{}, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["deploymentId"] = DeploymentId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateBuildOptions struct { + BuildId string + enabledSetters map[string]bool +} +func (options CreateBuildOptions) New() *CreateBuildOptions { + options.enabledSetters = map[string]bool{ + "BuildId": false, + } + return &options +} +type CreateBuildOption func(*CreateBuildOptions) +func WithCreateBuildBuildId(v string) CreateBuildOption { + return func(o *CreateBuildOptions) { + o.BuildId = v + o.enabledSetters["BuildId"] = true + } +} + +// CreateBuild +func (srv *Functions) CreateBuild(FunctionId string, DeploymentId string, optionalSetters ...CreateBuildOption)(*interface{}, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/build") + options := CreateBuildOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["deploymentId"] = DeploymentId + if options.enabledSetters["BuildId"] { + params["buildId"] = options.BuildId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateDeploymentBuild +func (srv *Functions) UpdateDeploymentBuild(FunctionId string, DeploymentId string)(*models.Build, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/build") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["deploymentId"] = DeploymentId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Build + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Build) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DownloadDeployment get a Deployment's contents by its unique ID. This +// endpoint supports range requests for partial or streaming file download. +func (srv *Functions) DownloadDeployment(FunctionId string, DeploymentId string)(*[]byte, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/download") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["deploymentId"] = DeploymentId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListExecutionsOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListExecutionsOptions) New() *ListExecutionsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListExecutionsOption func(*ListExecutionsOptions) +func WithListExecutionsQueries(v []interface{}) ListExecutionsOption { + return func(o *ListExecutionsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListExecutionsSearch(v string) ListExecutionsOption { + return func(o *ListExecutionsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListExecutions get a list of all the current user function execution logs. +// You can use the query params to filter your results. +func (srv *Functions) ListExecutions(FunctionId string, optionalSetters ...ListExecutionsOption)(*models.ExecutionList, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}/executions") + options := ListExecutionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.ExecutionList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.ExecutionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateExecutionOptions struct { + Body string + Async bool + Path string + Method string + Headers interface{} + ScheduledAt string + enabledSetters map[string]bool +} +func (options CreateExecutionOptions) New() *CreateExecutionOptions { + options.enabledSetters = map[string]bool{ + "Body": false, + "Async": false, + "Path": false, + "Method": false, + "Headers": false, + "ScheduledAt": false, + } + return &options +} +type CreateExecutionOption func(*CreateExecutionOptions) +func WithCreateExecutionBody(v string) CreateExecutionOption { + return func(o *CreateExecutionOptions) { + o.Body = v + o.enabledSetters["Body"] = true + } +} +func WithCreateExecutionAsync(v bool) CreateExecutionOption { + return func(o *CreateExecutionOptions) { + o.Async = v + o.enabledSetters["Async"] = true + } +} +func WithCreateExecutionPath(v string) CreateExecutionOption { + return func(o *CreateExecutionOptions) { + o.Path = v + o.enabledSetters["Path"] = true + } +} +func WithCreateExecutionMethod(v string) CreateExecutionOption { + return func(o *CreateExecutionOptions) { + o.Method = v + o.enabledSetters["Method"] = true + } +} +func WithCreateExecutionHeaders(v interface{}) CreateExecutionOption { + return func(o *CreateExecutionOptions) { + o.Headers = v + o.enabledSetters["Headers"] = true + } +} +func WithCreateExecutionScheduledAt(v string) CreateExecutionOption { + return func(o *CreateExecutionOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} + +// CreateExecution trigger a function execution. The returned object will +// return you the current execution status. You can ping the `Get Execution` +// endpoint to get updates on the current execution status. Once this endpoint +// is called, your function execution process will start asynchronously. +func (srv *Functions) CreateExecution(FunctionId string, optionalSetters ...CreateExecutionOption)(*models.Execution, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}/executions") + options := CreateExecutionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + if options.enabledSetters["Body"] { + params["body"] = options.Body + } + if options.enabledSetters["Async"] { + params["async"] = options.Async + } + if options.enabledSetters["Path"] { + params["path"] = options.Path + } + if options.enabledSetters["Method"] { + params["method"] = options.Method + } + if options.enabledSetters["Headers"] { + params["headers"] = options.Headers + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Execution + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Execution) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetExecution get a function execution log by its unique ID. +func (srv *Functions) GetExecution(FunctionId string, ExecutionId string)(*models.Execution, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{executionId}", ExecutionId) + path := r.Replace("/functions/{functionId}/executions/{executionId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["executionId"] = ExecutionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Execution + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Execution) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteExecution delete a function execution by its unique ID. +func (srv *Functions) DeleteExecution(FunctionId string, ExecutionId string)(*interface{}, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{executionId}", ExecutionId) + path := r.Replace("/functions/{functionId}/executions/{executionId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["executionId"] = ExecutionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListVariables get a list of all variables of a specific function. +func (srv *Functions) ListVariables(FunctionId string)(*models.VariableList, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}/variables") + params := map[string]interface{}{} + params["functionId"] = FunctionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.VariableList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.VariableList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateVariable create a new function environment variable. These variables +// can be accessed in the function at runtime as environment variables. +func (srv *Functions) CreateVariable(FunctionId string, Key string, Value string)(*models.Variable, error) { + r := strings.NewReplacer("{functionId}", FunctionId) + path := r.Replace("/functions/{functionId}/variables") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["key"] = Key + params["value"] = Value + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Variable + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Variable) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetVariable get a variable by its unique ID. +func (srv *Functions) GetVariable(FunctionId string, VariableId string)(*models.Variable, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId) + path := r.Replace("/functions/{functionId}/variables/{variableId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["variableId"] = VariableId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Variable + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Variable) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateVariableOptions struct { + Value string + enabledSetters map[string]bool +} +func (options UpdateVariableOptions) New() *UpdateVariableOptions { + options.enabledSetters = map[string]bool{ + "Value": false, + } + return &options +} +type UpdateVariableOption func(*UpdateVariableOptions) +func WithUpdateVariableValue(v string) UpdateVariableOption { + return func(o *UpdateVariableOptions) { + o.Value = v + o.enabledSetters["Value"] = true + } +} + +// UpdateVariable update variable by its unique ID. +func (srv *Functions) UpdateVariable(FunctionId string, VariableId string, Key string, optionalSetters ...UpdateVariableOption)(*models.Variable, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId) + path := r.Replace("/functions/{functionId}/variables/{variableId}") + options := UpdateVariableOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["variableId"] = VariableId + params["key"] = Key + if options.enabledSetters["Value"] { + params["value"] = options.Value + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Variable + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Variable) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteVariable delete a variable by its unique ID. +func (srv *Functions) DeleteVariable(FunctionId string, VariableId string)(*interface{}, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId) + path := r.Replace("/functions/{functionId}/variables/{variableId}") + params := map[string]interface{}{} + params["functionId"] = FunctionId + params["variableId"] = VariableId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cb34a03 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/appwrite/sdk-for-go + +go 1.12 diff --git a/graphql/graphql.go b/graphql/graphql.go new file mode 100644 index 0000000..c06e2d8 --- /dev/null +++ b/graphql/graphql.go @@ -0,0 +1,80 @@ +package graphql + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "strings" +) + +// Graphql service +type Graphql struct { + client client.Client +} + +func NewGraphql(clt client.Client) *Graphql { + return &Graphql{ + client: clt, + } +} + + +// Query execute a GraphQL mutation. +func (srv *Graphql) Query(Query interface{})(*interface{}, error) { + path := "/graphql" + params := map[string]interface{}{} + params["query"] = Query + headers := map[string]interface{}{ + "x-sdk-graphql": "true", + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Mutation execute a GraphQL mutation. +func (srv *Graphql) Mutation(Query interface{})(*interface{}, error) { + path := "/graphql/mutation" + params := map[string]interface{}{} + params["query"] = Query + headers := map[string]interface{}{ + "x-sdk-graphql": "true", + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/health/health.go b/health/health.go new file mode 100644 index 0000000..d63dd88 --- /dev/null +++ b/health/health.go @@ -0,0 +1,1054 @@ +package health + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Health service +type Health struct { + client client.Client +} + +func NewHealth(clt client.Client) *Health { + return &Health{ + client: clt, + } +} + + +// Get check the Appwrite HTTP server is up and responsive. +func (srv *Health) Get()(*models.HealthStatus, error) { + path := "/health" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetAntivirus check the Appwrite Antivirus server is up and connection is +// successful. +func (srv *Health) GetAntivirus()(*models.HealthAntivirus, error) { + path := "/health/anti-virus" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthAntivirus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthAntivirus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetCache check the Appwrite in-memory cache servers are up and connection +// is successful. +func (srv *Health) GetCache()(*models.HealthStatus, error) { + path := "/health/cache" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetCertificateOptions struct { + Domain string + enabledSetters map[string]bool +} +func (options GetCertificateOptions) New() *GetCertificateOptions { + options.enabledSetters = map[string]bool{ + "Domain": false, + } + return &options +} +type GetCertificateOption func(*GetCertificateOptions) +func WithGetCertificateDomain(v string) GetCertificateOption { + return func(o *GetCertificateOptions) { + o.Domain = v + o.enabledSetters["Domain"] = true + } +} + +// GetCertificate get the SSL certificate for a domain +func (srv *Health) GetCertificate(optionalSetters ...GetCertificateOption)(*models.HealthCertificate, error) { + path := "/health/certificate" + options := GetCertificateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Domain"] { + params["domain"] = options.Domain + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthCertificate + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthCertificate) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetDB check the Appwrite database servers are up and connection is +// successful. +func (srv *Health) GetDB()(*models.HealthStatus, error) { + path := "/health/db" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPubSub check the Appwrite pub-sub servers are up and connection is +// successful. +func (srv *Health) GetPubSub()(*models.HealthStatus, error) { + path := "/health/pubsub" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetQueue check the Appwrite queue messaging servers are up and connection +// is successful. +func (srv *Health) GetQueue()(*models.HealthStatus, error) { + path := "/health/queue" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueBuildsOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueBuildsOptions) New() *GetQueueBuildsOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueBuildsOption func(*GetQueueBuildsOptions) +func WithGetQueueBuildsThreshold(v int) GetQueueBuildsOption { + return func(o *GetQueueBuildsOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueBuilds get the number of builds that are waiting to be processed in +// the Appwrite internal queue server. +func (srv *Health) GetQueueBuilds(optionalSetters ...GetQueueBuildsOption)(*models.HealthQueue, error) { + path := "/health/queue/builds" + options := GetQueueBuildsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueCertificatesOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueCertificatesOptions) New() *GetQueueCertificatesOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueCertificatesOption func(*GetQueueCertificatesOptions) +func WithGetQueueCertificatesThreshold(v int) GetQueueCertificatesOption { + return func(o *GetQueueCertificatesOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueCertificates get the number of certificates that are waiting to be +// issued against [Letsencrypt](https://letsencrypt.org/) in the Appwrite +// internal queue server. +func (srv *Health) GetQueueCertificates(optionalSetters ...GetQueueCertificatesOption)(*models.HealthQueue, error) { + path := "/health/queue/certificates" + options := GetQueueCertificatesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueDatabasesOptions struct { + Name string + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueDatabasesOptions) New() *GetQueueDatabasesOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Threshold": false, + } + return &options +} +type GetQueueDatabasesOption func(*GetQueueDatabasesOptions) +func WithGetQueueDatabasesName(v string) GetQueueDatabasesOption { + return func(o *GetQueueDatabasesOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithGetQueueDatabasesThreshold(v int) GetQueueDatabasesOption { + return func(o *GetQueueDatabasesOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueDatabases get the number of database changes that are waiting to be +// processed in the Appwrite internal queue server. +func (srv *Health) GetQueueDatabases(optionalSetters ...GetQueueDatabasesOption)(*models.HealthQueue, error) { + path := "/health/queue/databases" + options := GetQueueDatabasesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueDeletesOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueDeletesOptions) New() *GetQueueDeletesOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueDeletesOption func(*GetQueueDeletesOptions) +func WithGetQueueDeletesThreshold(v int) GetQueueDeletesOption { + return func(o *GetQueueDeletesOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueDeletes get the number of background destructive changes that are +// waiting to be processed in the Appwrite internal queue server. +func (srv *Health) GetQueueDeletes(optionalSetters ...GetQueueDeletesOption)(*models.HealthQueue, error) { + path := "/health/queue/deletes" + options := GetQueueDeletesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetFailedJobsOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetFailedJobsOptions) New() *GetFailedJobsOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetFailedJobsOption func(*GetFailedJobsOptions) +func WithGetFailedJobsThreshold(v int) GetFailedJobsOption { + return func(o *GetFailedJobsOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetFailedJobs returns the amount of failed jobs in a given queue. +func (srv *Health) GetFailedJobs(Name string, optionalSetters ...GetFailedJobsOption)(*models.HealthQueue, error) { + r := strings.NewReplacer("{name}", Name) + path := r.Replace("/health/queue/failed/{name}") + options := GetFailedJobsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["name"] = Name + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueFunctionsOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueFunctionsOptions) New() *GetQueueFunctionsOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueFunctionsOption func(*GetQueueFunctionsOptions) +func WithGetQueueFunctionsThreshold(v int) GetQueueFunctionsOption { + return func(o *GetQueueFunctionsOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueFunctions get the number of function executions that are waiting to +// be processed in the Appwrite internal queue server. +func (srv *Health) GetQueueFunctions(optionalSetters ...GetQueueFunctionsOption)(*models.HealthQueue, error) { + path := "/health/queue/functions" + options := GetQueueFunctionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueLogsOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueLogsOptions) New() *GetQueueLogsOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueLogsOption func(*GetQueueLogsOptions) +func WithGetQueueLogsThreshold(v int) GetQueueLogsOption { + return func(o *GetQueueLogsOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueLogs get the number of logs that are waiting to be processed in the +// Appwrite internal queue server. +func (srv *Health) GetQueueLogs(optionalSetters ...GetQueueLogsOption)(*models.HealthQueue, error) { + path := "/health/queue/logs" + options := GetQueueLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueMailsOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueMailsOptions) New() *GetQueueMailsOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueMailsOption func(*GetQueueMailsOptions) +func WithGetQueueMailsThreshold(v int) GetQueueMailsOption { + return func(o *GetQueueMailsOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueMails get the number of mails that are waiting to be processed in +// the Appwrite internal queue server. +func (srv *Health) GetQueueMails(optionalSetters ...GetQueueMailsOption)(*models.HealthQueue, error) { + path := "/health/queue/mails" + options := GetQueueMailsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueMessagingOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueMessagingOptions) New() *GetQueueMessagingOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueMessagingOption func(*GetQueueMessagingOptions) +func WithGetQueueMessagingThreshold(v int) GetQueueMessagingOption { + return func(o *GetQueueMessagingOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueMessaging get the number of messages that are waiting to be +// processed in the Appwrite internal queue server. +func (srv *Health) GetQueueMessaging(optionalSetters ...GetQueueMessagingOption)(*models.HealthQueue, error) { + path := "/health/queue/messaging" + options := GetQueueMessagingOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueMigrationsOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueMigrationsOptions) New() *GetQueueMigrationsOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueMigrationsOption func(*GetQueueMigrationsOptions) +func WithGetQueueMigrationsThreshold(v int) GetQueueMigrationsOption { + return func(o *GetQueueMigrationsOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueMigrations get the number of migrations that are waiting to be +// processed in the Appwrite internal queue server. +func (srv *Health) GetQueueMigrations(optionalSetters ...GetQueueMigrationsOption)(*models.HealthQueue, error) { + path := "/health/queue/migrations" + options := GetQueueMigrationsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueUsageOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueUsageOptions) New() *GetQueueUsageOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueUsageOption func(*GetQueueUsageOptions) +func WithGetQueueUsageThreshold(v int) GetQueueUsageOption { + return func(o *GetQueueUsageOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueUsage get the number of metrics that are waiting to be processed in +// the Appwrite internal queue server. +func (srv *Health) GetQueueUsage(optionalSetters ...GetQueueUsageOption)(*models.HealthQueue, error) { + path := "/health/queue/usage" + options := GetQueueUsageOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueUsageDumpOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueUsageDumpOptions) New() *GetQueueUsageDumpOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueUsageDumpOption func(*GetQueueUsageDumpOptions) +func WithGetQueueUsageDumpThreshold(v int) GetQueueUsageDumpOption { + return func(o *GetQueueUsageDumpOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueUsageDump get the number of projects containing metrics that are +// waiting to be processed in the Appwrite internal queue server. +func (srv *Health) GetQueueUsageDump(optionalSetters ...GetQueueUsageDumpOption)(*models.HealthQueue, error) { + path := "/health/queue/usage-dump" + options := GetQueueUsageDumpOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetQueueWebhooksOptions struct { + Threshold int + enabledSetters map[string]bool +} +func (options GetQueueWebhooksOptions) New() *GetQueueWebhooksOptions { + options.enabledSetters = map[string]bool{ + "Threshold": false, + } + return &options +} +type GetQueueWebhooksOption func(*GetQueueWebhooksOptions) +func WithGetQueueWebhooksThreshold(v int) GetQueueWebhooksOption { + return func(o *GetQueueWebhooksOptions) { + o.Threshold = v + o.enabledSetters["Threshold"] = true + } +} + +// GetQueueWebhooks get the number of webhooks that are waiting to be +// processed in the Appwrite internal queue server. +func (srv *Health) GetQueueWebhooks(optionalSetters ...GetQueueWebhooksOption)(*models.HealthQueue, error) { + path := "/health/queue/webhooks" + options := GetQueueWebhooksOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Threshold"] { + params["threshold"] = options.Threshold + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthQueue + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthQueue) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetStorage check the Appwrite storage device is up and connection is +// successful. +func (srv *Health) GetStorage()(*models.HealthStatus, error) { + path := "/health/storage" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetStorageLocal check the Appwrite local storage device is up and +// connection is successful. +func (srv *Health) GetStorageLocal()(*models.HealthStatus, error) { + path := "/health/storage/local" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthStatus + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthStatus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetTime check the Appwrite server time is synced with Google remote NTP +// server. We use this technology to smoothly handle leap seconds with no +// disruptive events. The [Network Time +// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is +// used by hundreds of millions of computers and devices to synchronize their +// clocks over the Internet. If your computer sets its own clock, it likely +// uses NTP. +func (srv *Health) GetTime()(*models.HealthTime, error) { + path := "/health/time" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.HealthTime + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.HealthTime) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/id/id.go b/id/id.go new file mode 100644 index 0000000..1afd00a --- /dev/null +++ b/id/id.go @@ -0,0 +1,23 @@ +package id + +import ( + "time" + "strconv" + "math/rand" +) + +func Custom(id string) string { + return id +} + +func Unique() string { + timestamp := time.Now().UnixNano() / 1000 + + choices := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"} + hexString := strconv.FormatInt(timestamp, 16) + + for i := 0; i < 7; i++ { + hexString += choices[rand.Intn(len(choices))] + } + return hexString +} diff --git a/locale/locale.go b/locale/locale.go new file mode 100644 index 0000000..1ca1e25 --- /dev/null +++ b/locale/locale.go @@ -0,0 +1,258 @@ +package locale + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Locale service +type Locale struct { + client client.Client +} + +func NewLocale(clt client.Client) *Locale { + return &Locale{ + client: clt, + } +} + + +// Get get the current user location based on IP. Returns an object with user +// country code, country name, continent name, continent code, ip address and +// suggested currency. You can use the locale header to get the data in a +// supported language. +// +// ([IP Geolocation by DB-IP](https://db-ip.com)) +func (srv *Locale) Get()(*models.Locale, error) { + path := "/locale" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Locale + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Locale) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListCodes list of all locale codes in [ISO +// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). +func (srv *Locale) ListCodes()(*models.LocaleCodeList, error) { + path := "/locale/codes" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LocaleCodeList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LocaleCodeList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListContinents list of all continents. You can use the locale header to get +// the data in a supported language. +func (srv *Locale) ListContinents()(*models.ContinentList, error) { + path := "/locale/continents" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.ContinentList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.ContinentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListCountries list of all countries. You can use the locale header to get +// the data in a supported language. +func (srv *Locale) ListCountries()(*models.CountryList, error) { + path := "/locale/countries" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.CountryList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.CountryList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListCountriesEU list of all countries that are currently members of the EU. +// You can use the locale header to get the data in a supported language. +func (srv *Locale) ListCountriesEU()(*models.CountryList, error) { + path := "/locale/countries/eu" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.CountryList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.CountryList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListCountriesPhones list of all countries phone codes. You can use the +// locale header to get the data in a supported language. +func (srv *Locale) ListCountriesPhones()(*models.PhoneList, error) { + path := "/locale/countries/phones" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.PhoneList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.PhoneList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListCurrencies list of all currencies, including currency symbol, name, +// plural, and decimal digits for all major and minor currencies. You can use +// the locale header to get the data in a supported language. +func (srv *Locale) ListCurrencies()(*models.CurrencyList, error) { + path := "/locale/currencies" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.CurrencyList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.CurrencyList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListLanguages list of all languages classified by ISO 639-1 including +// 2-letter code, name in English, and name in the respective language. +func (srv *Locale) ListLanguages()(*models.LanguageList, error) { + path := "/locale/languages" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LanguageList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LanguageList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/messaging/messaging.go b/messaging/messaging.go new file mode 100644 index 0000000..cbc7358 --- /dev/null +++ b/messaging/messaging.go @@ -0,0 +1,4038 @@ +package messaging + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Messaging service +type Messaging struct { + client client.Client +} + +func NewMessaging(clt client.Client) *Messaging { + return &Messaging{ + client: clt, + } +} + + +type ListMessagesOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListMessagesOptions) New() *ListMessagesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListMessagesOption func(*ListMessagesOptions) +func WithListMessagesQueries(v []interface{}) ListMessagesOption { + return func(o *ListMessagesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListMessagesSearch(v string) ListMessagesOption { + return func(o *ListMessagesOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListMessages get a list of all messages from the current Appwrite project. +func (srv *Messaging) ListMessages(optionalSetters ...ListMessagesOption)(*models.MessageList, error) { + path := "/messaging/messages" + options := ListMessagesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MessageList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MessageList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateEmailOptions struct { + Topics []interface{} + Users []interface{} + Targets []interface{} + Cc []interface{} + Bcc []interface{} + Attachments []interface{} + Draft bool + Html bool + ScheduledAt string + enabledSetters map[string]bool +} +func (options CreateEmailOptions) New() *CreateEmailOptions { + options.enabledSetters = map[string]bool{ + "Topics": false, + "Users": false, + "Targets": false, + "Cc": false, + "Bcc": false, + "Attachments": false, + "Draft": false, + "Html": false, + "ScheduledAt": false, + } + return &options +} +type CreateEmailOption func(*CreateEmailOptions) +func WithCreateEmailTopics(v []interface{}) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Topics = v + o.enabledSetters["Topics"] = true + } +} +func WithCreateEmailUsers(v []interface{}) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Users = v + o.enabledSetters["Users"] = true + } +} +func WithCreateEmailTargets(v []interface{}) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Targets = v + o.enabledSetters["Targets"] = true + } +} +func WithCreateEmailCc(v []interface{}) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Cc = v + o.enabledSetters["Cc"] = true + } +} +func WithCreateEmailBcc(v []interface{}) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Bcc = v + o.enabledSetters["Bcc"] = true + } +} +func WithCreateEmailAttachments(v []interface{}) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Attachments = v + o.enabledSetters["Attachments"] = true + } +} +func WithCreateEmailDraft(v bool) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Draft = v + o.enabledSetters["Draft"] = true + } +} +func WithCreateEmailHtml(v bool) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.Html = v + o.enabledSetters["Html"] = true + } +} +func WithCreateEmailScheduledAt(v string) CreateEmailOption { + return func(o *CreateEmailOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} + +// CreateEmail create a new email message. +func (srv *Messaging) CreateEmail(MessageId string, Subject string, Content string, optionalSetters ...CreateEmailOption)(*models.Message, error) { + path := "/messaging/messages/email" + options := CreateEmailOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + params["subject"] = Subject + params["content"] = Content + if options.enabledSetters["Topics"] { + params["topics"] = options.Topics + } + if options.enabledSetters["Users"] { + params["users"] = options.Users + } + if options.enabledSetters["Targets"] { + params["targets"] = options.Targets + } + if options.enabledSetters["Cc"] { + params["cc"] = options.Cc + } + if options.enabledSetters["Bcc"] { + params["bcc"] = options.Bcc + } + if options.enabledSetters["Attachments"] { + params["attachments"] = options.Attachments + } + if options.enabledSetters["Draft"] { + params["draft"] = options.Draft + } + if options.enabledSetters["Html"] { + params["html"] = options.Html + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateEmailOptions struct { + Topics []interface{} + Users []interface{} + Targets []interface{} + Subject string + Content string + Draft bool + Html bool + Cc []interface{} + Bcc []interface{} + ScheduledAt string + Attachments []interface{} + enabledSetters map[string]bool +} +func (options UpdateEmailOptions) New() *UpdateEmailOptions { + options.enabledSetters = map[string]bool{ + "Topics": false, + "Users": false, + "Targets": false, + "Subject": false, + "Content": false, + "Draft": false, + "Html": false, + "Cc": false, + "Bcc": false, + "ScheduledAt": false, + "Attachments": false, + } + return &options +} +type UpdateEmailOption func(*UpdateEmailOptions) +func WithUpdateEmailTopics(v []interface{}) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Topics = v + o.enabledSetters["Topics"] = true + } +} +func WithUpdateEmailUsers(v []interface{}) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Users = v + o.enabledSetters["Users"] = true + } +} +func WithUpdateEmailTargets(v []interface{}) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Targets = v + o.enabledSetters["Targets"] = true + } +} +func WithUpdateEmailSubject(v string) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Subject = v + o.enabledSetters["Subject"] = true + } +} +func WithUpdateEmailContent(v string) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Content = v + o.enabledSetters["Content"] = true + } +} +func WithUpdateEmailDraft(v bool) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Draft = v + o.enabledSetters["Draft"] = true + } +} +func WithUpdateEmailHtml(v bool) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Html = v + o.enabledSetters["Html"] = true + } +} +func WithUpdateEmailCc(v []interface{}) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Cc = v + o.enabledSetters["Cc"] = true + } +} +func WithUpdateEmailBcc(v []interface{}) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Bcc = v + o.enabledSetters["Bcc"] = true + } +} +func WithUpdateEmailScheduledAt(v string) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} +func WithUpdateEmailAttachments(v []interface{}) UpdateEmailOption { + return func(o *UpdateEmailOptions) { + o.Attachments = v + o.enabledSetters["Attachments"] = true + } +} + +// UpdateEmail update an email message by its unique ID. +func (srv *Messaging) UpdateEmail(MessageId string, optionalSetters ...UpdateEmailOption)(*models.Message, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/email/{messageId}") + options := UpdateEmailOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + if options.enabledSetters["Topics"] { + params["topics"] = options.Topics + } + if options.enabledSetters["Users"] { + params["users"] = options.Users + } + if options.enabledSetters["Targets"] { + params["targets"] = options.Targets + } + if options.enabledSetters["Subject"] { + params["subject"] = options.Subject + } + if options.enabledSetters["Content"] { + params["content"] = options.Content + } + if options.enabledSetters["Draft"] { + params["draft"] = options.Draft + } + if options.enabledSetters["Html"] { + params["html"] = options.Html + } + if options.enabledSetters["Cc"] { + params["cc"] = options.Cc + } + if options.enabledSetters["Bcc"] { + params["bcc"] = options.Bcc + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + if options.enabledSetters["Attachments"] { + params["attachments"] = options.Attachments + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreatePushOptions struct { + Topics []interface{} + Users []interface{} + Targets []interface{} + Data interface{} + Action string + Image string + Icon string + Sound string + Color string + Tag string + Badge string + Draft bool + ScheduledAt string + enabledSetters map[string]bool +} +func (options CreatePushOptions) New() *CreatePushOptions { + options.enabledSetters = map[string]bool{ + "Topics": false, + "Users": false, + "Targets": false, + "Data": false, + "Action": false, + "Image": false, + "Icon": false, + "Sound": false, + "Color": false, + "Tag": false, + "Badge": false, + "Draft": false, + "ScheduledAt": false, + } + return &options +} +type CreatePushOption func(*CreatePushOptions) +func WithCreatePushTopics(v []interface{}) CreatePushOption { + return func(o *CreatePushOptions) { + o.Topics = v + o.enabledSetters["Topics"] = true + } +} +func WithCreatePushUsers(v []interface{}) CreatePushOption { + return func(o *CreatePushOptions) { + o.Users = v + o.enabledSetters["Users"] = true + } +} +func WithCreatePushTargets(v []interface{}) CreatePushOption { + return func(o *CreatePushOptions) { + o.Targets = v + o.enabledSetters["Targets"] = true + } +} +func WithCreatePushData(v interface{}) CreatePushOption { + return func(o *CreatePushOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func WithCreatePushAction(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Action = v + o.enabledSetters["Action"] = true + } +} +func WithCreatePushImage(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Image = v + o.enabledSetters["Image"] = true + } +} +func WithCreatePushIcon(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Icon = v + o.enabledSetters["Icon"] = true + } +} +func WithCreatePushSound(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Sound = v + o.enabledSetters["Sound"] = true + } +} +func WithCreatePushColor(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Color = v + o.enabledSetters["Color"] = true + } +} +func WithCreatePushTag(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Tag = v + o.enabledSetters["Tag"] = true + } +} +func WithCreatePushBadge(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.Badge = v + o.enabledSetters["Badge"] = true + } +} +func WithCreatePushDraft(v bool) CreatePushOption { + return func(o *CreatePushOptions) { + o.Draft = v + o.enabledSetters["Draft"] = true + } +} +func WithCreatePushScheduledAt(v string) CreatePushOption { + return func(o *CreatePushOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} + +// CreatePush create a new push notification. +func (srv *Messaging) CreatePush(MessageId string, Title string, Body string, optionalSetters ...CreatePushOption)(*models.Message, error) { + path := "/messaging/messages/push" + options := CreatePushOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + params["title"] = Title + params["body"] = Body + if options.enabledSetters["Topics"] { + params["topics"] = options.Topics + } + if options.enabledSetters["Users"] { + params["users"] = options.Users + } + if options.enabledSetters["Targets"] { + params["targets"] = options.Targets + } + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Action"] { + params["action"] = options.Action + } + if options.enabledSetters["Image"] { + params["image"] = options.Image + } + if options.enabledSetters["Icon"] { + params["icon"] = options.Icon + } + if options.enabledSetters["Sound"] { + params["sound"] = options.Sound + } + if options.enabledSetters["Color"] { + params["color"] = options.Color + } + if options.enabledSetters["Tag"] { + params["tag"] = options.Tag + } + if options.enabledSetters["Badge"] { + params["badge"] = options.Badge + } + if options.enabledSetters["Draft"] { + params["draft"] = options.Draft + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdatePushOptions struct { + Topics []interface{} + Users []interface{} + Targets []interface{} + Title string + Body string + Data interface{} + Action string + Image string + Icon string + Sound string + Color string + Tag string + Badge int + Draft bool + ScheduledAt string + enabledSetters map[string]bool +} +func (options UpdatePushOptions) New() *UpdatePushOptions { + options.enabledSetters = map[string]bool{ + "Topics": false, + "Users": false, + "Targets": false, + "Title": false, + "Body": false, + "Data": false, + "Action": false, + "Image": false, + "Icon": false, + "Sound": false, + "Color": false, + "Tag": false, + "Badge": false, + "Draft": false, + "ScheduledAt": false, + } + return &options +} +type UpdatePushOption func(*UpdatePushOptions) +func WithUpdatePushTopics(v []interface{}) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Topics = v + o.enabledSetters["Topics"] = true + } +} +func WithUpdatePushUsers(v []interface{}) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Users = v + o.enabledSetters["Users"] = true + } +} +func WithUpdatePushTargets(v []interface{}) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Targets = v + o.enabledSetters["Targets"] = true + } +} +func WithUpdatePushTitle(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Title = v + o.enabledSetters["Title"] = true + } +} +func WithUpdatePushBody(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Body = v + o.enabledSetters["Body"] = true + } +} +func WithUpdatePushData(v interface{}) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func WithUpdatePushAction(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Action = v + o.enabledSetters["Action"] = true + } +} +func WithUpdatePushImage(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Image = v + o.enabledSetters["Image"] = true + } +} +func WithUpdatePushIcon(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Icon = v + o.enabledSetters["Icon"] = true + } +} +func WithUpdatePushSound(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Sound = v + o.enabledSetters["Sound"] = true + } +} +func WithUpdatePushColor(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Color = v + o.enabledSetters["Color"] = true + } +} +func WithUpdatePushTag(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Tag = v + o.enabledSetters["Tag"] = true + } +} +func WithUpdatePushBadge(v int) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Badge = v + o.enabledSetters["Badge"] = true + } +} +func WithUpdatePushDraft(v bool) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.Draft = v + o.enabledSetters["Draft"] = true + } +} +func WithUpdatePushScheduledAt(v string) UpdatePushOption { + return func(o *UpdatePushOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} + +// UpdatePush update a push notification by its unique ID. +func (srv *Messaging) UpdatePush(MessageId string, optionalSetters ...UpdatePushOption)(*models.Message, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/push/{messageId}") + options := UpdatePushOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + if options.enabledSetters["Topics"] { + params["topics"] = options.Topics + } + if options.enabledSetters["Users"] { + params["users"] = options.Users + } + if options.enabledSetters["Targets"] { + params["targets"] = options.Targets + } + if options.enabledSetters["Title"] { + params["title"] = options.Title + } + if options.enabledSetters["Body"] { + params["body"] = options.Body + } + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Action"] { + params["action"] = options.Action + } + if options.enabledSetters["Image"] { + params["image"] = options.Image + } + if options.enabledSetters["Icon"] { + params["icon"] = options.Icon + } + if options.enabledSetters["Sound"] { + params["sound"] = options.Sound + } + if options.enabledSetters["Color"] { + params["color"] = options.Color + } + if options.enabledSetters["Tag"] { + params["tag"] = options.Tag + } + if options.enabledSetters["Badge"] { + params["badge"] = options.Badge + } + if options.enabledSetters["Draft"] { + params["draft"] = options.Draft + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateSmsOptions struct { + Topics []interface{} + Users []interface{} + Targets []interface{} + Draft bool + ScheduledAt string + enabledSetters map[string]bool +} +func (options CreateSmsOptions) New() *CreateSmsOptions { + options.enabledSetters = map[string]bool{ + "Topics": false, + "Users": false, + "Targets": false, + "Draft": false, + "ScheduledAt": false, + } + return &options +} +type CreateSmsOption func(*CreateSmsOptions) +func WithCreateSmsTopics(v []interface{}) CreateSmsOption { + return func(o *CreateSmsOptions) { + o.Topics = v + o.enabledSetters["Topics"] = true + } +} +func WithCreateSmsUsers(v []interface{}) CreateSmsOption { + return func(o *CreateSmsOptions) { + o.Users = v + o.enabledSetters["Users"] = true + } +} +func WithCreateSmsTargets(v []interface{}) CreateSmsOption { + return func(o *CreateSmsOptions) { + o.Targets = v + o.enabledSetters["Targets"] = true + } +} +func WithCreateSmsDraft(v bool) CreateSmsOption { + return func(o *CreateSmsOptions) { + o.Draft = v + o.enabledSetters["Draft"] = true + } +} +func WithCreateSmsScheduledAt(v string) CreateSmsOption { + return func(o *CreateSmsOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} + +// CreateSms create a new SMS message. +func (srv *Messaging) CreateSms(MessageId string, Content string, optionalSetters ...CreateSmsOption)(*models.Message, error) { + path := "/messaging/messages/sms" + options := CreateSmsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + params["content"] = Content + if options.enabledSetters["Topics"] { + params["topics"] = options.Topics + } + if options.enabledSetters["Users"] { + params["users"] = options.Users + } + if options.enabledSetters["Targets"] { + params["targets"] = options.Targets + } + if options.enabledSetters["Draft"] { + params["draft"] = options.Draft + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateSmsOptions struct { + Topics []interface{} + Users []interface{} + Targets []interface{} + Content string + Draft bool + ScheduledAt string + enabledSetters map[string]bool +} +func (options UpdateSmsOptions) New() *UpdateSmsOptions { + options.enabledSetters = map[string]bool{ + "Topics": false, + "Users": false, + "Targets": false, + "Content": false, + "Draft": false, + "ScheduledAt": false, + } + return &options +} +type UpdateSmsOption func(*UpdateSmsOptions) +func WithUpdateSmsTopics(v []interface{}) UpdateSmsOption { + return func(o *UpdateSmsOptions) { + o.Topics = v + o.enabledSetters["Topics"] = true + } +} +func WithUpdateSmsUsers(v []interface{}) UpdateSmsOption { + return func(o *UpdateSmsOptions) { + o.Users = v + o.enabledSetters["Users"] = true + } +} +func WithUpdateSmsTargets(v []interface{}) UpdateSmsOption { + return func(o *UpdateSmsOptions) { + o.Targets = v + o.enabledSetters["Targets"] = true + } +} +func WithUpdateSmsContent(v string) UpdateSmsOption { + return func(o *UpdateSmsOptions) { + o.Content = v + o.enabledSetters["Content"] = true + } +} +func WithUpdateSmsDraft(v bool) UpdateSmsOption { + return func(o *UpdateSmsOptions) { + o.Draft = v + o.enabledSetters["Draft"] = true + } +} +func WithUpdateSmsScheduledAt(v string) UpdateSmsOption { + return func(o *UpdateSmsOptions) { + o.ScheduledAt = v + o.enabledSetters["ScheduledAt"] = true + } +} + +// UpdateSms update an email message by its unique ID. +func (srv *Messaging) UpdateSms(MessageId string, optionalSetters ...UpdateSmsOption)(*models.Message, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/sms/{messageId}") + options := UpdateSmsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + if options.enabledSetters["Topics"] { + params["topics"] = options.Topics + } + if options.enabledSetters["Users"] { + params["users"] = options.Users + } + if options.enabledSetters["Targets"] { + params["targets"] = options.Targets + } + if options.enabledSetters["Content"] { + params["content"] = options.Content + } + if options.enabledSetters["Draft"] { + params["draft"] = options.Draft + } + if options.enabledSetters["ScheduledAt"] { + params["scheduledAt"] = options.ScheduledAt + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetMessage get a message by its unique ID. +func (srv *Messaging) GetMessage(MessageId string)(*models.Message, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/{messageId}") + params := map[string]interface{}{} + params["messageId"] = MessageId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Message + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Message) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a message. If the message is not a draft or scheduled, but +// has been sent, this will not recall the message. +func (srv *Messaging) Delete(MessageId string)(*interface{}, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/{messageId}") + params := map[string]interface{}{} + params["messageId"] = MessageId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListMessageLogsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListMessageLogsOptions) New() *ListMessageLogsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListMessageLogsOption func(*ListMessageLogsOptions) +func WithListMessageLogsQueries(v []interface{}) ListMessageLogsOption { + return func(o *ListMessageLogsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListMessageLogs get the message activity logs listed by its unique ID. +func (srv *Messaging) ListMessageLogs(MessageId string, optionalSetters ...ListMessageLogsOption)(*models.LogList, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/{messageId}/logs") + options := ListMessageLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LogList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LogList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListTargetsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListTargetsOptions) New() *ListTargetsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListTargetsOption func(*ListTargetsOptions) +func WithListTargetsQueries(v []interface{}) ListTargetsOption { + return func(o *ListTargetsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListTargets get a list of the targets associated with a message. +func (srv *Messaging) ListTargets(MessageId string, optionalSetters ...ListTargetsOption)(*models.TargetList, error) { + r := strings.NewReplacer("{messageId}", MessageId) + path := r.Replace("/messaging/messages/{messageId}/targets") + options := ListTargetsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["messageId"] = MessageId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.TargetList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.TargetList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListProvidersOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListProvidersOptions) New() *ListProvidersOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListProvidersOption func(*ListProvidersOptions) +func WithListProvidersQueries(v []interface{}) ListProvidersOption { + return func(o *ListProvidersOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListProvidersSearch(v string) ListProvidersOption { + return func(o *ListProvidersOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListProviders get a list of all providers from the current Appwrite +// project. +func (srv *Messaging) ListProviders(optionalSetters ...ListProvidersOption)(*models.ProviderList, error) { + path := "/messaging/providers" + options := ListProvidersOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.ProviderList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.ProviderList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateApnsProviderOptions struct { + AuthKey string + AuthKeyId string + TeamId string + BundleId string + Sandbox bool + Enabled bool + enabledSetters map[string]bool +} +func (options CreateApnsProviderOptions) New() *CreateApnsProviderOptions { + options.enabledSetters = map[string]bool{ + "AuthKey": false, + "AuthKeyId": false, + "TeamId": false, + "BundleId": false, + "Sandbox": false, + "Enabled": false, + } + return &options +} +type CreateApnsProviderOption func(*CreateApnsProviderOptions) +func WithCreateApnsProviderAuthKey(v string) CreateApnsProviderOption { + return func(o *CreateApnsProviderOptions) { + o.AuthKey = v + o.enabledSetters["AuthKey"] = true + } +} +func WithCreateApnsProviderAuthKeyId(v string) CreateApnsProviderOption { + return func(o *CreateApnsProviderOptions) { + o.AuthKeyId = v + o.enabledSetters["AuthKeyId"] = true + } +} +func WithCreateApnsProviderTeamId(v string) CreateApnsProviderOption { + return func(o *CreateApnsProviderOptions) { + o.TeamId = v + o.enabledSetters["TeamId"] = true + } +} +func WithCreateApnsProviderBundleId(v string) CreateApnsProviderOption { + return func(o *CreateApnsProviderOptions) { + o.BundleId = v + o.enabledSetters["BundleId"] = true + } +} +func WithCreateApnsProviderSandbox(v bool) CreateApnsProviderOption { + return func(o *CreateApnsProviderOptions) { + o.Sandbox = v + o.enabledSetters["Sandbox"] = true + } +} +func WithCreateApnsProviderEnabled(v bool) CreateApnsProviderOption { + return func(o *CreateApnsProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateApnsProvider create a new Apple Push Notification service provider. +func (srv *Messaging) CreateApnsProvider(ProviderId string, Name string, optionalSetters ...CreateApnsProviderOption)(*models.Provider, error) { + path := "/messaging/providers/apns" + options := CreateApnsProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["AuthKey"] { + params["authKey"] = options.AuthKey + } + if options.enabledSetters["AuthKeyId"] { + params["authKeyId"] = options.AuthKeyId + } + if options.enabledSetters["TeamId"] { + params["teamId"] = options.TeamId + } + if options.enabledSetters["BundleId"] { + params["bundleId"] = options.BundleId + } + if options.enabledSetters["Sandbox"] { + params["sandbox"] = options.Sandbox + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateApnsProviderOptions struct { + Name string + Enabled bool + AuthKey string + AuthKeyId string + TeamId string + BundleId string + Sandbox bool + enabledSetters map[string]bool +} +func (options UpdateApnsProviderOptions) New() *UpdateApnsProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "AuthKey": false, + "AuthKeyId": false, + "TeamId": false, + "BundleId": false, + "Sandbox": false, + } + return &options +} +type UpdateApnsProviderOption func(*UpdateApnsProviderOptions) +func WithUpdateApnsProviderName(v string) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateApnsProviderEnabled(v bool) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateApnsProviderAuthKey(v string) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.AuthKey = v + o.enabledSetters["AuthKey"] = true + } +} +func WithUpdateApnsProviderAuthKeyId(v string) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.AuthKeyId = v + o.enabledSetters["AuthKeyId"] = true + } +} +func WithUpdateApnsProviderTeamId(v string) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.TeamId = v + o.enabledSetters["TeamId"] = true + } +} +func WithUpdateApnsProviderBundleId(v string) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.BundleId = v + o.enabledSetters["BundleId"] = true + } +} +func WithUpdateApnsProviderSandbox(v bool) UpdateApnsProviderOption { + return func(o *UpdateApnsProviderOptions) { + o.Sandbox = v + o.enabledSetters["Sandbox"] = true + } +} + +// UpdateApnsProvider update a Apple Push Notification service provider by its +// unique ID. +func (srv *Messaging) UpdateApnsProvider(ProviderId string, optionalSetters ...UpdateApnsProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/apns/{providerId}") + options := UpdateApnsProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["AuthKey"] { + params["authKey"] = options.AuthKey + } + if options.enabledSetters["AuthKeyId"] { + params["authKeyId"] = options.AuthKeyId + } + if options.enabledSetters["TeamId"] { + params["teamId"] = options.TeamId + } + if options.enabledSetters["BundleId"] { + params["bundleId"] = options.BundleId + } + if options.enabledSetters["Sandbox"] { + params["sandbox"] = options.Sandbox + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateFcmProviderOptions struct { + ServiceAccountJSON interface{} + Enabled bool + enabledSetters map[string]bool +} +func (options CreateFcmProviderOptions) New() *CreateFcmProviderOptions { + options.enabledSetters = map[string]bool{ + "ServiceAccountJSON": false, + "Enabled": false, + } + return &options +} +type CreateFcmProviderOption func(*CreateFcmProviderOptions) +func WithCreateFcmProviderServiceAccountJSON(v interface{}) CreateFcmProviderOption { + return func(o *CreateFcmProviderOptions) { + o.ServiceAccountJSON = v + o.enabledSetters["ServiceAccountJSON"] = true + } +} +func WithCreateFcmProviderEnabled(v bool) CreateFcmProviderOption { + return func(o *CreateFcmProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateFcmProvider create a new Firebase Cloud Messaging provider. +func (srv *Messaging) CreateFcmProvider(ProviderId string, Name string, optionalSetters ...CreateFcmProviderOption)(*models.Provider, error) { + path := "/messaging/providers/fcm" + options := CreateFcmProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["ServiceAccountJSON"] { + params["serviceAccountJSON"] = options.ServiceAccountJSON + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateFcmProviderOptions struct { + Name string + Enabled bool + ServiceAccountJSON interface{} + enabledSetters map[string]bool +} +func (options UpdateFcmProviderOptions) New() *UpdateFcmProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "ServiceAccountJSON": false, + } + return &options +} +type UpdateFcmProviderOption func(*UpdateFcmProviderOptions) +func WithUpdateFcmProviderName(v string) UpdateFcmProviderOption { + return func(o *UpdateFcmProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateFcmProviderEnabled(v bool) UpdateFcmProviderOption { + return func(o *UpdateFcmProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateFcmProviderServiceAccountJSON(v interface{}) UpdateFcmProviderOption { + return func(o *UpdateFcmProviderOptions) { + o.ServiceAccountJSON = v + o.enabledSetters["ServiceAccountJSON"] = true + } +} + +// UpdateFcmProvider update a Firebase Cloud Messaging provider by its unique +// ID. +func (srv *Messaging) UpdateFcmProvider(ProviderId string, optionalSetters ...UpdateFcmProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/fcm/{providerId}") + options := UpdateFcmProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["ServiceAccountJSON"] { + params["serviceAccountJSON"] = options.ServiceAccountJSON + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateMailgunProviderOptions struct { + ApiKey string + Domain string + IsEuRegion bool + FromName string + FromEmail string + ReplyToName string + ReplyToEmail string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateMailgunProviderOptions) New() *CreateMailgunProviderOptions { + options.enabledSetters = map[string]bool{ + "ApiKey": false, + "Domain": false, + "IsEuRegion": false, + "FromName": false, + "FromEmail": false, + "ReplyToName": false, + "ReplyToEmail": false, + "Enabled": false, + } + return &options +} +type CreateMailgunProviderOption func(*CreateMailgunProviderOptions) +func WithCreateMailgunProviderApiKey(v string) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithCreateMailgunProviderDomain(v string) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.Domain = v + o.enabledSetters["Domain"] = true + } +} +func WithCreateMailgunProviderIsEuRegion(v bool) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.IsEuRegion = v + o.enabledSetters["IsEuRegion"] = true + } +} +func WithCreateMailgunProviderFromName(v string) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.FromName = v + o.enabledSetters["FromName"] = true + } +} +func WithCreateMailgunProviderFromEmail(v string) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.FromEmail = v + o.enabledSetters["FromEmail"] = true + } +} +func WithCreateMailgunProviderReplyToName(v string) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func WithCreateMailgunProviderReplyToEmail(v string) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} +func WithCreateMailgunProviderEnabled(v bool) CreateMailgunProviderOption { + return func(o *CreateMailgunProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateMailgunProvider create a new Mailgun provider. +func (srv *Messaging) CreateMailgunProvider(ProviderId string, Name string, optionalSetters ...CreateMailgunProviderOption)(*models.Provider, error) { + path := "/messaging/providers/mailgun" + options := CreateMailgunProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["Domain"] { + params["domain"] = options.Domain + } + if options.enabledSetters["IsEuRegion"] { + params["isEuRegion"] = options.IsEuRegion + } + if options.enabledSetters["FromName"] { + params["fromName"] = options.FromName + } + if options.enabledSetters["FromEmail"] { + params["fromEmail"] = options.FromEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateMailgunProviderOptions struct { + Name string + ApiKey string + Domain string + IsEuRegion bool + Enabled bool + FromName string + FromEmail string + ReplyToName string + ReplyToEmail string + enabledSetters map[string]bool +} +func (options UpdateMailgunProviderOptions) New() *UpdateMailgunProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "ApiKey": false, + "Domain": false, + "IsEuRegion": false, + "Enabled": false, + "FromName": false, + "FromEmail": false, + "ReplyToName": false, + "ReplyToEmail": false, + } + return &options +} +type UpdateMailgunProviderOption func(*UpdateMailgunProviderOptions) +func WithUpdateMailgunProviderName(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateMailgunProviderApiKey(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithUpdateMailgunProviderDomain(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.Domain = v + o.enabledSetters["Domain"] = true + } +} +func WithUpdateMailgunProviderIsEuRegion(v bool) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.IsEuRegion = v + o.enabledSetters["IsEuRegion"] = true + } +} +func WithUpdateMailgunProviderEnabled(v bool) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateMailgunProviderFromName(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.FromName = v + o.enabledSetters["FromName"] = true + } +} +func WithUpdateMailgunProviderFromEmail(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.FromEmail = v + o.enabledSetters["FromEmail"] = true + } +} +func WithUpdateMailgunProviderReplyToName(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func WithUpdateMailgunProviderReplyToEmail(v string) UpdateMailgunProviderOption { + return func(o *UpdateMailgunProviderOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} + +// UpdateMailgunProvider update a Mailgun provider by its unique ID. +func (srv *Messaging) UpdateMailgunProvider(ProviderId string, optionalSetters ...UpdateMailgunProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/mailgun/{providerId}") + options := UpdateMailgunProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["Domain"] { + params["domain"] = options.Domain + } + if options.enabledSetters["IsEuRegion"] { + params["isEuRegion"] = options.IsEuRegion + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["FromName"] { + params["fromName"] = options.FromName + } + if options.enabledSetters["FromEmail"] { + params["fromEmail"] = options.FromEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateMsg91ProviderOptions struct { + TemplateId string + SenderId string + AuthKey string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateMsg91ProviderOptions) New() *CreateMsg91ProviderOptions { + options.enabledSetters = map[string]bool{ + "TemplateId": false, + "SenderId": false, + "AuthKey": false, + "Enabled": false, + } + return &options +} +type CreateMsg91ProviderOption func(*CreateMsg91ProviderOptions) +func WithCreateMsg91ProviderTemplateId(v string) CreateMsg91ProviderOption { + return func(o *CreateMsg91ProviderOptions) { + o.TemplateId = v + o.enabledSetters["TemplateId"] = true + } +} +func WithCreateMsg91ProviderSenderId(v string) CreateMsg91ProviderOption { + return func(o *CreateMsg91ProviderOptions) { + o.SenderId = v + o.enabledSetters["SenderId"] = true + } +} +func WithCreateMsg91ProviderAuthKey(v string) CreateMsg91ProviderOption { + return func(o *CreateMsg91ProviderOptions) { + o.AuthKey = v + o.enabledSetters["AuthKey"] = true + } +} +func WithCreateMsg91ProviderEnabled(v bool) CreateMsg91ProviderOption { + return func(o *CreateMsg91ProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateMsg91Provider create a new MSG91 provider. +func (srv *Messaging) CreateMsg91Provider(ProviderId string, Name string, optionalSetters ...CreateMsg91ProviderOption)(*models.Provider, error) { + path := "/messaging/providers/msg91" + options := CreateMsg91ProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["TemplateId"] { + params["templateId"] = options.TemplateId + } + if options.enabledSetters["SenderId"] { + params["senderId"] = options.SenderId + } + if options.enabledSetters["AuthKey"] { + params["authKey"] = options.AuthKey + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateMsg91ProviderOptions struct { + Name string + Enabled bool + TemplateId string + SenderId string + AuthKey string + enabledSetters map[string]bool +} +func (options UpdateMsg91ProviderOptions) New() *UpdateMsg91ProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "TemplateId": false, + "SenderId": false, + "AuthKey": false, + } + return &options +} +type UpdateMsg91ProviderOption func(*UpdateMsg91ProviderOptions) +func WithUpdateMsg91ProviderName(v string) UpdateMsg91ProviderOption { + return func(o *UpdateMsg91ProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateMsg91ProviderEnabled(v bool) UpdateMsg91ProviderOption { + return func(o *UpdateMsg91ProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateMsg91ProviderTemplateId(v string) UpdateMsg91ProviderOption { + return func(o *UpdateMsg91ProviderOptions) { + o.TemplateId = v + o.enabledSetters["TemplateId"] = true + } +} +func WithUpdateMsg91ProviderSenderId(v string) UpdateMsg91ProviderOption { + return func(o *UpdateMsg91ProviderOptions) { + o.SenderId = v + o.enabledSetters["SenderId"] = true + } +} +func WithUpdateMsg91ProviderAuthKey(v string) UpdateMsg91ProviderOption { + return func(o *UpdateMsg91ProviderOptions) { + o.AuthKey = v + o.enabledSetters["AuthKey"] = true + } +} + +// UpdateMsg91Provider update a MSG91 provider by its unique ID. +func (srv *Messaging) UpdateMsg91Provider(ProviderId string, optionalSetters ...UpdateMsg91ProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/msg91/{providerId}") + options := UpdateMsg91ProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["TemplateId"] { + params["templateId"] = options.TemplateId + } + if options.enabledSetters["SenderId"] { + params["senderId"] = options.SenderId + } + if options.enabledSetters["AuthKey"] { + params["authKey"] = options.AuthKey + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateSendgridProviderOptions struct { + ApiKey string + FromName string + FromEmail string + ReplyToName string + ReplyToEmail string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateSendgridProviderOptions) New() *CreateSendgridProviderOptions { + options.enabledSetters = map[string]bool{ + "ApiKey": false, + "FromName": false, + "FromEmail": false, + "ReplyToName": false, + "ReplyToEmail": false, + "Enabled": false, + } + return &options +} +type CreateSendgridProviderOption func(*CreateSendgridProviderOptions) +func WithCreateSendgridProviderApiKey(v string) CreateSendgridProviderOption { + return func(o *CreateSendgridProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithCreateSendgridProviderFromName(v string) CreateSendgridProviderOption { + return func(o *CreateSendgridProviderOptions) { + o.FromName = v + o.enabledSetters["FromName"] = true + } +} +func WithCreateSendgridProviderFromEmail(v string) CreateSendgridProviderOption { + return func(o *CreateSendgridProviderOptions) { + o.FromEmail = v + o.enabledSetters["FromEmail"] = true + } +} +func WithCreateSendgridProviderReplyToName(v string) CreateSendgridProviderOption { + return func(o *CreateSendgridProviderOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func WithCreateSendgridProviderReplyToEmail(v string) CreateSendgridProviderOption { + return func(o *CreateSendgridProviderOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} +func WithCreateSendgridProviderEnabled(v bool) CreateSendgridProviderOption { + return func(o *CreateSendgridProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateSendgridProvider create a new Sendgrid provider. +func (srv *Messaging) CreateSendgridProvider(ProviderId string, Name string, optionalSetters ...CreateSendgridProviderOption)(*models.Provider, error) { + path := "/messaging/providers/sendgrid" + options := CreateSendgridProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["FromName"] { + params["fromName"] = options.FromName + } + if options.enabledSetters["FromEmail"] { + params["fromEmail"] = options.FromEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateSendgridProviderOptions struct { + Name string + Enabled bool + ApiKey string + FromName string + FromEmail string + ReplyToName string + ReplyToEmail string + enabledSetters map[string]bool +} +func (options UpdateSendgridProviderOptions) New() *UpdateSendgridProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "ApiKey": false, + "FromName": false, + "FromEmail": false, + "ReplyToName": false, + "ReplyToEmail": false, + } + return &options +} +type UpdateSendgridProviderOption func(*UpdateSendgridProviderOptions) +func WithUpdateSendgridProviderName(v string) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateSendgridProviderEnabled(v bool) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateSendgridProviderApiKey(v string) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithUpdateSendgridProviderFromName(v string) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.FromName = v + o.enabledSetters["FromName"] = true + } +} +func WithUpdateSendgridProviderFromEmail(v string) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.FromEmail = v + o.enabledSetters["FromEmail"] = true + } +} +func WithUpdateSendgridProviderReplyToName(v string) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func WithUpdateSendgridProviderReplyToEmail(v string) UpdateSendgridProviderOption { + return func(o *UpdateSendgridProviderOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} + +// UpdateSendgridProvider update a Sendgrid provider by its unique ID. +func (srv *Messaging) UpdateSendgridProvider(ProviderId string, optionalSetters ...UpdateSendgridProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/sendgrid/{providerId}") + options := UpdateSendgridProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["FromName"] { + params["fromName"] = options.FromName + } + if options.enabledSetters["FromEmail"] { + params["fromEmail"] = options.FromEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateSmtpProviderOptions struct { + Port int + Username string + Password string + Encryption string + AutoTLS bool + Mailer string + FromName string + FromEmail string + ReplyToName string + ReplyToEmail string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateSmtpProviderOptions) New() *CreateSmtpProviderOptions { + options.enabledSetters = map[string]bool{ + "Port": false, + "Username": false, + "Password": false, + "Encryption": false, + "AutoTLS": false, + "Mailer": false, + "FromName": false, + "FromEmail": false, + "ReplyToName": false, + "ReplyToEmail": false, + "Enabled": false, + } + return &options +} +type CreateSmtpProviderOption func(*CreateSmtpProviderOptions) +func WithCreateSmtpProviderPort(v int) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.Port = v + o.enabledSetters["Port"] = true + } +} +func WithCreateSmtpProviderUsername(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.Username = v + o.enabledSetters["Username"] = true + } +} +func WithCreateSmtpProviderPassword(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.Password = v + o.enabledSetters["Password"] = true + } +} +func WithCreateSmtpProviderEncryption(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.Encryption = v + o.enabledSetters["Encryption"] = true + } +} +func WithCreateSmtpProviderAutoTLS(v bool) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.AutoTLS = v + o.enabledSetters["AutoTLS"] = true + } +} +func WithCreateSmtpProviderMailer(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.Mailer = v + o.enabledSetters["Mailer"] = true + } +} +func WithCreateSmtpProviderFromName(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.FromName = v + o.enabledSetters["FromName"] = true + } +} +func WithCreateSmtpProviderFromEmail(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.FromEmail = v + o.enabledSetters["FromEmail"] = true + } +} +func WithCreateSmtpProviderReplyToName(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func WithCreateSmtpProviderReplyToEmail(v string) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} +func WithCreateSmtpProviderEnabled(v bool) CreateSmtpProviderOption { + return func(o *CreateSmtpProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateSmtpProvider create a new SMTP provider. +func (srv *Messaging) CreateSmtpProvider(ProviderId string, Name string, Host string, optionalSetters ...CreateSmtpProviderOption)(*models.Provider, error) { + path := "/messaging/providers/smtp" + options := CreateSmtpProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + params["host"] = Host + if options.enabledSetters["Port"] { + params["port"] = options.Port + } + if options.enabledSetters["Username"] { + params["username"] = options.Username + } + if options.enabledSetters["Password"] { + params["password"] = options.Password + } + if options.enabledSetters["Encryption"] { + params["encryption"] = options.Encryption + } + if options.enabledSetters["AutoTLS"] { + params["autoTLS"] = options.AutoTLS + } + if options.enabledSetters["Mailer"] { + params["mailer"] = options.Mailer + } + if options.enabledSetters["FromName"] { + params["fromName"] = options.FromName + } + if options.enabledSetters["FromEmail"] { + params["fromEmail"] = options.FromEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateSmtpProviderOptions struct { + Name string + Host string + Port int + Username string + Password string + Encryption string + AutoTLS bool + Mailer string + FromName string + FromEmail string + ReplyToName string + ReplyToEmail string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateSmtpProviderOptions) New() *UpdateSmtpProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Host": false, + "Port": false, + "Username": false, + "Password": false, + "Encryption": false, + "AutoTLS": false, + "Mailer": false, + "FromName": false, + "FromEmail": false, + "ReplyToName": false, + "ReplyToEmail": false, + "Enabled": false, + } + return &options +} +type UpdateSmtpProviderOption func(*UpdateSmtpProviderOptions) +func WithUpdateSmtpProviderName(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateSmtpProviderHost(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Host = v + o.enabledSetters["Host"] = true + } +} +func WithUpdateSmtpProviderPort(v int) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Port = v + o.enabledSetters["Port"] = true + } +} +func WithUpdateSmtpProviderUsername(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Username = v + o.enabledSetters["Username"] = true + } +} +func WithUpdateSmtpProviderPassword(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Password = v + o.enabledSetters["Password"] = true + } +} +func WithUpdateSmtpProviderEncryption(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Encryption = v + o.enabledSetters["Encryption"] = true + } +} +func WithUpdateSmtpProviderAutoTLS(v bool) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.AutoTLS = v + o.enabledSetters["AutoTLS"] = true + } +} +func WithUpdateSmtpProviderMailer(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Mailer = v + o.enabledSetters["Mailer"] = true + } +} +func WithUpdateSmtpProviderFromName(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.FromName = v + o.enabledSetters["FromName"] = true + } +} +func WithUpdateSmtpProviderFromEmail(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.FromEmail = v + o.enabledSetters["FromEmail"] = true + } +} +func WithUpdateSmtpProviderReplyToName(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func WithUpdateSmtpProviderReplyToEmail(v string) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} +func WithUpdateSmtpProviderEnabled(v bool) UpdateSmtpProviderOption { + return func(o *UpdateSmtpProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateSmtpProvider update a SMTP provider by its unique ID. +func (srv *Messaging) UpdateSmtpProvider(ProviderId string, optionalSetters ...UpdateSmtpProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/smtp/{providerId}") + options := UpdateSmtpProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Host"] { + params["host"] = options.Host + } + if options.enabledSetters["Port"] { + params["port"] = options.Port + } + if options.enabledSetters["Username"] { + params["username"] = options.Username + } + if options.enabledSetters["Password"] { + params["password"] = options.Password + } + if options.enabledSetters["Encryption"] { + params["encryption"] = options.Encryption + } + if options.enabledSetters["AutoTLS"] { + params["autoTLS"] = options.AutoTLS + } + if options.enabledSetters["Mailer"] { + params["mailer"] = options.Mailer + } + if options.enabledSetters["FromName"] { + params["fromName"] = options.FromName + } + if options.enabledSetters["FromEmail"] { + params["fromEmail"] = options.FromEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateTelesignProviderOptions struct { + From string + CustomerId string + ApiKey string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateTelesignProviderOptions) New() *CreateTelesignProviderOptions { + options.enabledSetters = map[string]bool{ + "From": false, + "CustomerId": false, + "ApiKey": false, + "Enabled": false, + } + return &options +} +type CreateTelesignProviderOption func(*CreateTelesignProviderOptions) +func WithCreateTelesignProviderFrom(v string) CreateTelesignProviderOption { + return func(o *CreateTelesignProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} +func WithCreateTelesignProviderCustomerId(v string) CreateTelesignProviderOption { + return func(o *CreateTelesignProviderOptions) { + o.CustomerId = v + o.enabledSetters["CustomerId"] = true + } +} +func WithCreateTelesignProviderApiKey(v string) CreateTelesignProviderOption { + return func(o *CreateTelesignProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithCreateTelesignProviderEnabled(v bool) CreateTelesignProviderOption { + return func(o *CreateTelesignProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateTelesignProvider create a new Telesign provider. +func (srv *Messaging) CreateTelesignProvider(ProviderId string, Name string, optionalSetters ...CreateTelesignProviderOption)(*models.Provider, error) { + path := "/messaging/providers/telesign" + options := CreateTelesignProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["From"] { + params["from"] = options.From + } + if options.enabledSetters["CustomerId"] { + params["customerId"] = options.CustomerId + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateTelesignProviderOptions struct { + Name string + Enabled bool + CustomerId string + ApiKey string + From string + enabledSetters map[string]bool +} +func (options UpdateTelesignProviderOptions) New() *UpdateTelesignProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "CustomerId": false, + "ApiKey": false, + "From": false, + } + return &options +} +type UpdateTelesignProviderOption func(*UpdateTelesignProviderOptions) +func WithUpdateTelesignProviderName(v string) UpdateTelesignProviderOption { + return func(o *UpdateTelesignProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateTelesignProviderEnabled(v bool) UpdateTelesignProviderOption { + return func(o *UpdateTelesignProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateTelesignProviderCustomerId(v string) UpdateTelesignProviderOption { + return func(o *UpdateTelesignProviderOptions) { + o.CustomerId = v + o.enabledSetters["CustomerId"] = true + } +} +func WithUpdateTelesignProviderApiKey(v string) UpdateTelesignProviderOption { + return func(o *UpdateTelesignProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithUpdateTelesignProviderFrom(v string) UpdateTelesignProviderOption { + return func(o *UpdateTelesignProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} + +// UpdateTelesignProvider update a Telesign provider by its unique ID. +func (srv *Messaging) UpdateTelesignProvider(ProviderId string, optionalSetters ...UpdateTelesignProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/telesign/{providerId}") + options := UpdateTelesignProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["CustomerId"] { + params["customerId"] = options.CustomerId + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["From"] { + params["from"] = options.From + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateTextmagicProviderOptions struct { + From string + Username string + ApiKey string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateTextmagicProviderOptions) New() *CreateTextmagicProviderOptions { + options.enabledSetters = map[string]bool{ + "From": false, + "Username": false, + "ApiKey": false, + "Enabled": false, + } + return &options +} +type CreateTextmagicProviderOption func(*CreateTextmagicProviderOptions) +func WithCreateTextmagicProviderFrom(v string) CreateTextmagicProviderOption { + return func(o *CreateTextmagicProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} +func WithCreateTextmagicProviderUsername(v string) CreateTextmagicProviderOption { + return func(o *CreateTextmagicProviderOptions) { + o.Username = v + o.enabledSetters["Username"] = true + } +} +func WithCreateTextmagicProviderApiKey(v string) CreateTextmagicProviderOption { + return func(o *CreateTextmagicProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithCreateTextmagicProviderEnabled(v bool) CreateTextmagicProviderOption { + return func(o *CreateTextmagicProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateTextmagicProvider create a new Textmagic provider. +func (srv *Messaging) CreateTextmagicProvider(ProviderId string, Name string, optionalSetters ...CreateTextmagicProviderOption)(*models.Provider, error) { + path := "/messaging/providers/textmagic" + options := CreateTextmagicProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["From"] { + params["from"] = options.From + } + if options.enabledSetters["Username"] { + params["username"] = options.Username + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateTextmagicProviderOptions struct { + Name string + Enabled bool + Username string + ApiKey string + From string + enabledSetters map[string]bool +} +func (options UpdateTextmagicProviderOptions) New() *UpdateTextmagicProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "Username": false, + "ApiKey": false, + "From": false, + } + return &options +} +type UpdateTextmagicProviderOption func(*UpdateTextmagicProviderOptions) +func WithUpdateTextmagicProviderName(v string) UpdateTextmagicProviderOption { + return func(o *UpdateTextmagicProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateTextmagicProviderEnabled(v bool) UpdateTextmagicProviderOption { + return func(o *UpdateTextmagicProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateTextmagicProviderUsername(v string) UpdateTextmagicProviderOption { + return func(o *UpdateTextmagicProviderOptions) { + o.Username = v + o.enabledSetters["Username"] = true + } +} +func WithUpdateTextmagicProviderApiKey(v string) UpdateTextmagicProviderOption { + return func(o *UpdateTextmagicProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithUpdateTextmagicProviderFrom(v string) UpdateTextmagicProviderOption { + return func(o *UpdateTextmagicProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} + +// UpdateTextmagicProvider update a Textmagic provider by its unique ID. +func (srv *Messaging) UpdateTextmagicProvider(ProviderId string, optionalSetters ...UpdateTextmagicProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/textmagic/{providerId}") + options := UpdateTextmagicProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["Username"] { + params["username"] = options.Username + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["From"] { + params["from"] = options.From + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateTwilioProviderOptions struct { + From string + AccountSid string + AuthToken string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateTwilioProviderOptions) New() *CreateTwilioProviderOptions { + options.enabledSetters = map[string]bool{ + "From": false, + "AccountSid": false, + "AuthToken": false, + "Enabled": false, + } + return &options +} +type CreateTwilioProviderOption func(*CreateTwilioProviderOptions) +func WithCreateTwilioProviderFrom(v string) CreateTwilioProviderOption { + return func(o *CreateTwilioProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} +func WithCreateTwilioProviderAccountSid(v string) CreateTwilioProviderOption { + return func(o *CreateTwilioProviderOptions) { + o.AccountSid = v + o.enabledSetters["AccountSid"] = true + } +} +func WithCreateTwilioProviderAuthToken(v string) CreateTwilioProviderOption { + return func(o *CreateTwilioProviderOptions) { + o.AuthToken = v + o.enabledSetters["AuthToken"] = true + } +} +func WithCreateTwilioProviderEnabled(v bool) CreateTwilioProviderOption { + return func(o *CreateTwilioProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateTwilioProvider create a new Twilio provider. +func (srv *Messaging) CreateTwilioProvider(ProviderId string, Name string, optionalSetters ...CreateTwilioProviderOption)(*models.Provider, error) { + path := "/messaging/providers/twilio" + options := CreateTwilioProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["From"] { + params["from"] = options.From + } + if options.enabledSetters["AccountSid"] { + params["accountSid"] = options.AccountSid + } + if options.enabledSetters["AuthToken"] { + params["authToken"] = options.AuthToken + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateTwilioProviderOptions struct { + Name string + Enabled bool + AccountSid string + AuthToken string + From string + enabledSetters map[string]bool +} +func (options UpdateTwilioProviderOptions) New() *UpdateTwilioProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "AccountSid": false, + "AuthToken": false, + "From": false, + } + return &options +} +type UpdateTwilioProviderOption func(*UpdateTwilioProviderOptions) +func WithUpdateTwilioProviderName(v string) UpdateTwilioProviderOption { + return func(o *UpdateTwilioProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateTwilioProviderEnabled(v bool) UpdateTwilioProviderOption { + return func(o *UpdateTwilioProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateTwilioProviderAccountSid(v string) UpdateTwilioProviderOption { + return func(o *UpdateTwilioProviderOptions) { + o.AccountSid = v + o.enabledSetters["AccountSid"] = true + } +} +func WithUpdateTwilioProviderAuthToken(v string) UpdateTwilioProviderOption { + return func(o *UpdateTwilioProviderOptions) { + o.AuthToken = v + o.enabledSetters["AuthToken"] = true + } +} +func WithUpdateTwilioProviderFrom(v string) UpdateTwilioProviderOption { + return func(o *UpdateTwilioProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} + +// UpdateTwilioProvider update a Twilio provider by its unique ID. +func (srv *Messaging) UpdateTwilioProvider(ProviderId string, optionalSetters ...UpdateTwilioProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/twilio/{providerId}") + options := UpdateTwilioProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["AccountSid"] { + params["accountSid"] = options.AccountSid + } + if options.enabledSetters["AuthToken"] { + params["authToken"] = options.AuthToken + } + if options.enabledSetters["From"] { + params["from"] = options.From + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateVonageProviderOptions struct { + From string + ApiKey string + ApiSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options CreateVonageProviderOptions) New() *CreateVonageProviderOptions { + options.enabledSetters = map[string]bool{ + "From": false, + "ApiKey": false, + "ApiSecret": false, + "Enabled": false, + } + return &options +} +type CreateVonageProviderOption func(*CreateVonageProviderOptions) +func WithCreateVonageProviderFrom(v string) CreateVonageProviderOption { + return func(o *CreateVonageProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} +func WithCreateVonageProviderApiKey(v string) CreateVonageProviderOption { + return func(o *CreateVonageProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithCreateVonageProviderApiSecret(v string) CreateVonageProviderOption { + return func(o *CreateVonageProviderOptions) { + o.ApiSecret = v + o.enabledSetters["ApiSecret"] = true + } +} +func WithCreateVonageProviderEnabled(v bool) CreateVonageProviderOption { + return func(o *CreateVonageProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateVonageProvider create a new Vonage provider. +func (srv *Messaging) CreateVonageProvider(ProviderId string, Name string, optionalSetters ...CreateVonageProviderOption)(*models.Provider, error) { + path := "/messaging/providers/vonage" + options := CreateVonageProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + params["name"] = Name + if options.enabledSetters["From"] { + params["from"] = options.From + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["ApiSecret"] { + params["apiSecret"] = options.ApiSecret + } + 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 + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateVonageProviderOptions struct { + Name string + Enabled bool + ApiKey string + ApiSecret string + From string + enabledSetters map[string]bool +} +func (options UpdateVonageProviderOptions) New() *UpdateVonageProviderOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Enabled": false, + "ApiKey": false, + "ApiSecret": false, + "From": false, + } + return &options +} +type UpdateVonageProviderOption func(*UpdateVonageProviderOptions) +func WithUpdateVonageProviderName(v string) UpdateVonageProviderOption { + return func(o *UpdateVonageProviderOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateVonageProviderEnabled(v bool) UpdateVonageProviderOption { + return func(o *UpdateVonageProviderOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateVonageProviderApiKey(v string) UpdateVonageProviderOption { + return func(o *UpdateVonageProviderOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func WithUpdateVonageProviderApiSecret(v string) UpdateVonageProviderOption { + return func(o *UpdateVonageProviderOptions) { + o.ApiSecret = v + o.enabledSetters["ApiSecret"] = true + } +} +func WithUpdateVonageProviderFrom(v string) UpdateVonageProviderOption { + return func(o *UpdateVonageProviderOptions) { + o.From = v + o.enabledSetters["From"] = true + } +} + +// UpdateVonageProvider update a Vonage provider by its unique ID. +func (srv *Messaging) UpdateVonageProvider(ProviderId string, optionalSetters ...UpdateVonageProviderOption)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/vonage/{providerId}") + options := UpdateVonageProviderOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["ApiSecret"] { + params["apiSecret"] = options.ApiSecret + } + if options.enabledSetters["From"] { + params["from"] = options.From + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetProvider get a provider by its unique ID. +func (srv *Messaging) GetProvider(ProviderId string)(*models.Provider, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/{providerId}") + params := map[string]interface{}{} + params["providerId"] = ProviderId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Provider + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Provider) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteProvider delete a provider by its unique ID. +func (srv *Messaging) DeleteProvider(ProviderId string)(*interface{}, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/{providerId}") + params := map[string]interface{}{} + params["providerId"] = ProviderId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListProviderLogsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListProviderLogsOptions) New() *ListProviderLogsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListProviderLogsOption func(*ListProviderLogsOptions) +func WithListProviderLogsQueries(v []interface{}) ListProviderLogsOption { + return func(o *ListProviderLogsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListProviderLogs get the provider activity logs listed by its unique ID. +func (srv *Messaging) ListProviderLogs(ProviderId string, optionalSetters ...ListProviderLogsOption)(*models.LogList, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/messaging/providers/{providerId}/logs") + options := ListProviderLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["providerId"] = ProviderId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LogList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LogList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListSubscriberLogsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListSubscriberLogsOptions) New() *ListSubscriberLogsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListSubscriberLogsOption func(*ListSubscriberLogsOptions) +func WithListSubscriberLogsQueries(v []interface{}) ListSubscriberLogsOption { + return func(o *ListSubscriberLogsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListSubscriberLogs get the subscriber activity logs listed by its unique +// ID. +func (srv *Messaging) ListSubscriberLogs(SubscriberId string, optionalSetters ...ListSubscriberLogsOption)(*models.LogList, error) { + r := strings.NewReplacer("{subscriberId}", SubscriberId) + path := r.Replace("/messaging/subscribers/{subscriberId}/logs") + options := ListSubscriberLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["subscriberId"] = SubscriberId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LogList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LogList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListTopicsOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListTopicsOptions) New() *ListTopicsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListTopicsOption func(*ListTopicsOptions) +func WithListTopicsQueries(v []interface{}) ListTopicsOption { + return func(o *ListTopicsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListTopicsSearch(v string) ListTopicsOption { + return func(o *ListTopicsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListTopics get a list of all topics from the current Appwrite project. +func (srv *Messaging) ListTopics(optionalSetters ...ListTopicsOption)(*models.TopicList, error) { + path := "/messaging/topics" + options := ListTopicsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.TopicList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.TopicList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateTopicOptions struct { + Subscribe []interface{} + enabledSetters map[string]bool +} +func (options CreateTopicOptions) New() *CreateTopicOptions { + options.enabledSetters = map[string]bool{ + "Subscribe": false, + } + return &options +} +type CreateTopicOption func(*CreateTopicOptions) +func WithCreateTopicSubscribe(v []interface{}) CreateTopicOption { + return func(o *CreateTopicOptions) { + o.Subscribe = v + o.enabledSetters["Subscribe"] = true + } +} + +// CreateTopic create a new topic. +func (srv *Messaging) CreateTopic(TopicId string, Name string, optionalSetters ...CreateTopicOption)(*models.Topic, error) { + path := "/messaging/topics" + options := CreateTopicOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["topicId"] = TopicId + params["name"] = Name + if options.enabledSetters["Subscribe"] { + params["subscribe"] = options.Subscribe + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Topic + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Topic) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetTopic get a topic by its unique ID. +func (srv *Messaging) GetTopic(TopicId string)(*models.Topic, error) { + r := strings.NewReplacer("{topicId}", TopicId) + path := r.Replace("/messaging/topics/{topicId}") + params := map[string]interface{}{} + params["topicId"] = TopicId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Topic + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Topic) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateTopicOptions struct { + Name string + Subscribe []interface{} + enabledSetters map[string]bool +} +func (options UpdateTopicOptions) New() *UpdateTopicOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Subscribe": false, + } + return &options +} +type UpdateTopicOption func(*UpdateTopicOptions) +func WithUpdateTopicName(v string) UpdateTopicOption { + return func(o *UpdateTopicOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateTopicSubscribe(v []interface{}) UpdateTopicOption { + return func(o *UpdateTopicOptions) { + o.Subscribe = v + o.enabledSetters["Subscribe"] = true + } +} + +// UpdateTopic update a topic by its unique ID. +func (srv *Messaging) UpdateTopic(TopicId string, optionalSetters ...UpdateTopicOption)(*models.Topic, error) { + r := strings.NewReplacer("{topicId}", TopicId) + path := r.Replace("/messaging/topics/{topicId}") + options := UpdateTopicOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["topicId"] = TopicId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Subscribe"] { + params["subscribe"] = options.Subscribe + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Topic + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Topic) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteTopic delete a topic by its unique ID. +func (srv *Messaging) DeleteTopic(TopicId string)(*interface{}, error) { + r := strings.NewReplacer("{topicId}", TopicId) + path := r.Replace("/messaging/topics/{topicId}") + params := map[string]interface{}{} + params["topicId"] = TopicId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListTopicLogsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListTopicLogsOptions) New() *ListTopicLogsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListTopicLogsOption func(*ListTopicLogsOptions) +func WithListTopicLogsQueries(v []interface{}) ListTopicLogsOption { + return func(o *ListTopicLogsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListTopicLogs get the topic activity logs listed by its unique ID. +func (srv *Messaging) ListTopicLogs(TopicId string, optionalSetters ...ListTopicLogsOption)(*models.LogList, error) { + r := strings.NewReplacer("{topicId}", TopicId) + path := r.Replace("/messaging/topics/{topicId}/logs") + options := ListTopicLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["topicId"] = TopicId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LogList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LogList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListSubscribersOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListSubscribersOptions) New() *ListSubscribersOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListSubscribersOption func(*ListSubscribersOptions) +func WithListSubscribersQueries(v []interface{}) ListSubscribersOption { + return func(o *ListSubscribersOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListSubscribersSearch(v string) ListSubscribersOption { + return func(o *ListSubscribersOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListSubscribers get a list of all subscribers from the current Appwrite +// project. +func (srv *Messaging) ListSubscribers(TopicId string, optionalSetters ...ListSubscribersOption)(*models.SubscriberList, error) { + r := strings.NewReplacer("{topicId}", TopicId) + path := r.Replace("/messaging/topics/{topicId}/subscribers") + options := ListSubscribersOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["topicId"] = TopicId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.SubscriberList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.SubscriberList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateSubscriber create a new subscriber. +func (srv *Messaging) CreateSubscriber(TopicId string, SubscriberId string, TargetId string)(*models.Subscriber, error) { + r := strings.NewReplacer("{topicId}", TopicId) + path := r.Replace("/messaging/topics/{topicId}/subscribers") + params := map[string]interface{}{} + params["topicId"] = TopicId + params["subscriberId"] = SubscriberId + params["targetId"] = TargetId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Subscriber + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Subscriber) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetSubscriber get a subscriber by its unique ID. +func (srv *Messaging) GetSubscriber(TopicId string, SubscriberId string)(*models.Subscriber, error) { + r := strings.NewReplacer("{topicId}", TopicId, "{subscriberId}", SubscriberId) + path := r.Replace("/messaging/topics/{topicId}/subscribers/{subscriberId}") + params := map[string]interface{}{} + params["topicId"] = TopicId + params["subscriberId"] = SubscriberId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Subscriber + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Subscriber) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteSubscriber delete a subscriber by its unique ID. +func (srv *Messaging) DeleteSubscriber(TopicId string, SubscriberId string)(*interface{}, error) { + r := strings.NewReplacer("{topicId}", TopicId, "{subscriberId}", SubscriberId) + path := r.Replace("/messaging/topics/{topicId}/subscribers/{subscriberId}") + params := map[string]interface{}{} + params["topicId"] = TopicId + params["subscriberId"] = SubscriberId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/models/algoargon2.go b/models/algoargon2.go new file mode 100644 index 0000000..5d9485d --- /dev/null +++ b/models/algoargon2.go @@ -0,0 +1,15 @@ +package models + + +// AlgoArgon2 Model +type AlgoArgon2 struct { + // Algo type. + Type string `json:"xtype"` + // Memory used to compute hash. + MemoryCost int `json:"memoryCost"` + // Amount of time consumed to compute hash + TimeCost int `json:"timeCost"` + // Number of threads used to compute hash. + Threads int `json:"threads"` + +} diff --git a/models/algobcrypt.go b/models/algobcrypt.go new file mode 100644 index 0000000..b36b350 --- /dev/null +++ b/models/algobcrypt.go @@ -0,0 +1,9 @@ +package models + + +// AlgoBcrypt Model +type AlgoBcrypt struct { + // Algo type. + Type string `json:"xtype"` + +} diff --git a/models/algomd5.go b/models/algomd5.go new file mode 100644 index 0000000..7401cca --- /dev/null +++ b/models/algomd5.go @@ -0,0 +1,9 @@ +package models + + +// AlgoMD5 Model +type AlgoMd5 struct { + // Algo type. + Type string `json:"xtype"` + +} diff --git a/models/algophpass.go b/models/algophpass.go new file mode 100644 index 0000000..f9a816f --- /dev/null +++ b/models/algophpass.go @@ -0,0 +1,9 @@ +package models + + +// AlgoPHPass Model +type AlgoPhpass struct { + // Algo type. + Type string `json:"xtype"` + +} diff --git a/models/algoscrypt.go b/models/algoscrypt.go new file mode 100644 index 0000000..1777280 --- /dev/null +++ b/models/algoscrypt.go @@ -0,0 +1,17 @@ +package models + + +// AlgoScrypt Model +type AlgoScrypt struct { + // Algo type. + Type string `json:"xtype"` + // CPU complexity of computed hash. + CostCpu int `json:"costCpu"` + // Memory complexity of computed hash. + CostMemory int `json:"costMemory"` + // Parallelization of computed hash. + CostParallel int `json:"costParallel"` + // Length used to compute hash. + Length int `json:"length"` + +} diff --git a/models/algoscryptmodified.go b/models/algoscryptmodified.go new file mode 100644 index 0000000..8b369dc --- /dev/null +++ b/models/algoscryptmodified.go @@ -0,0 +1,15 @@ +package models + + +// AlgoScryptModified Model +type AlgoScryptModified struct { + // Algo type. + Type string `json:"xtype"` + // Salt used to compute hash. + Salt string `json:"salt"` + // Separator used to compute hash. + SaltSeparator string `json:"saltSeparator"` + // Key used to compute hash. + SignerKey string `json:"signerKey"` + +} diff --git a/models/algosha.go b/models/algosha.go new file mode 100644 index 0000000..959f951 --- /dev/null +++ b/models/algosha.go @@ -0,0 +1,9 @@ +package models + + +// AlgoSHA Model +type AlgoSha struct { + // Algo type. + Type string `json:"xtype"` + +} diff --git a/models/attributeboolean.go b/models/attributeboolean.go new file mode 100644 index 0000000..7f7c0e9 --- /dev/null +++ b/models/attributeboolean.go @@ -0,0 +1,24 @@ +package models + + +// AttributeBoolean Model +type AttributeBoolean struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default bool `json:"xdefault"` + +} diff --git a/models/attributedatetime.go b/models/attributedatetime.go new file mode 100644 index 0000000..2d499bf --- /dev/null +++ b/models/attributedatetime.go @@ -0,0 +1,25 @@ +package models + + +// AttributeDatetime Model +type AttributeDatetime struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // ISO 8601 format. + Format string `json:"format"` + // Default value for attribute when not provided. Only null is optional + Default string `json:"xdefault"` + +} diff --git a/models/attributeemail.go b/models/attributeemail.go new file mode 100644 index 0000000..63c55f5 --- /dev/null +++ b/models/attributeemail.go @@ -0,0 +1,26 @@ +package models + + +// AttributeEmail Model +type AttributeEmail struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // String format. + Format string `json:"format"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default string `json:"xdefault"` + +} diff --git a/models/attributeenum.go b/models/attributeenum.go new file mode 100644 index 0000000..1cd2b74 --- /dev/null +++ b/models/attributeenum.go @@ -0,0 +1,28 @@ +package models + + +// AttributeEnum Model +type AttributeEnum struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Array of elements in enumerated type. + Elements []interface{} `json:"elements"` + // String format. + Format string `json:"format"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default string `json:"xdefault"` + +} diff --git a/models/attributefloat.go b/models/attributefloat.go new file mode 100644 index 0000000..4c2539c --- /dev/null +++ b/models/attributefloat.go @@ -0,0 +1,28 @@ +package models + + +// AttributeFloat Model +type AttributeFloat struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Minimum value to enforce for new documents. + Min float64 `json:"min"` + // Maximum value to enforce for new documents. + Max float64 `json:"max"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default float64 `json:"xdefault"` + +} diff --git a/models/attributeinteger.go b/models/attributeinteger.go new file mode 100644 index 0000000..2d1efe4 --- /dev/null +++ b/models/attributeinteger.go @@ -0,0 +1,28 @@ +package models + + +// AttributeInteger Model +type AttributeInteger struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Minimum value to enforce for new documents. + Min int `json:"min"` + // Maximum value to enforce for new documents. + Max int `json:"max"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default int `json:"xdefault"` + +} diff --git a/models/attributeip.go b/models/attributeip.go new file mode 100644 index 0000000..21fa48e --- /dev/null +++ b/models/attributeip.go @@ -0,0 +1,26 @@ +package models + + +// AttributeIP Model +type AttributeIp struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // String format. + Format string `json:"format"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default string `json:"xdefault"` + +} diff --git a/models/attributelist.go b/models/attributelist.go new file mode 100644 index 0000000..822501f --- /dev/null +++ b/models/attributelist.go @@ -0,0 +1,11 @@ +package models + + +// AttributesList Model +type AttributeList struct { + // Total number of attributes in the given collection. + Total int `json:"total"` + // List of attributes. + Attributes []interface{} `json:"attributes"` + +} diff --git a/models/attributerelationship.go b/models/attributerelationship.go new file mode 100644 index 0000000..56d0b0a --- /dev/null +++ b/models/attributerelationship.go @@ -0,0 +1,33 @@ +package models + + +// AttributeRelationship Model +type AttributeRelationship struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // The ID of the related collection. + RelatedCollection string `json:"relatedCollection"` + // The type of the relationship. + RelationType string `json:"relationType"` + // Is the relationship two-way? + TwoWay bool `json:"twoWay"` + // The key of the two-way relationship. + TwoWayKey string `json:"twoWayKey"` + // How deleting the parent document will propagate to child documents. + OnDelete string `json:"onDelete"` + // Whether this is the parent or child side of the relationship + Side string `json:"side"` + +} diff --git a/models/attributestring.go b/models/attributestring.go new file mode 100644 index 0000000..5301cc7 --- /dev/null +++ b/models/attributestring.go @@ -0,0 +1,26 @@ +package models + + +// AttributeString Model +type AttributeString struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Attribute size. + Size int `json:"size"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default string `json:"xdefault"` + +} diff --git a/models/attributeurl.go b/models/attributeurl.go new file mode 100644 index 0000000..44b0e3f --- /dev/null +++ b/models/attributeurl.go @@ -0,0 +1,26 @@ +package models + + +// AttributeURL Model +type AttributeUrl struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"xtype"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"xerror"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // String format. + Format string `json:"format"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default string `json:"xdefault"` + +} diff --git a/models/bucket.go b/models/bucket.go new file mode 100644 index 0000000..179ce0b --- /dev/null +++ b/models/bucket.go @@ -0,0 +1,35 @@ +package models + + +// Bucket Model +type Bucket struct { + // Bucket ID. + Id string `json:"$id"` + // Bucket creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Bucket update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Bucket permissions. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + Permissions []interface{} `json:"$permissions"` + // Whether file-level security is enabled. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + FileSecurity bool `json:"fileSecurity"` + // Bucket name. + Name string `json:"name"` + // Bucket enabled. + Enabled bool `json:"enabled"` + // Maximum file size supported. + MaximumFileSize int `json:"maximumFileSize"` + // Allowed file extensions. + AllowedFileExtensions []interface{} `json:"allowedFileExtensions"` + // Compression algorithm choosen 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"` + // Bucket is encrypted. + Encryption bool `json:"encryption"` + // Virus scanning is enabled. + Antivirus bool `json:"antivirus"` + +} diff --git a/models/bucketlist.go b/models/bucketlist.go new file mode 100644 index 0000000..6c1e504 --- /dev/null +++ b/models/bucketlist.go @@ -0,0 +1,11 @@ +package models + + +// BucketsList Model +type BucketList struct { + // Total number of buckets documents that matched your query. + Total int `json:"total"` + // List of buckets. + Buckets []interface{} `json:"buckets"` + +} diff --git a/models/build.go b/models/build.go new file mode 100644 index 0000000..80d0ff9 --- /dev/null +++ b/models/build.go @@ -0,0 +1,30 @@ +package models + + +// Build Model +type Build struct { + // Build ID. + Id string `json:"$id"` + // The deployment that created this build. + DeploymentId string `json:"deploymentId"` + // The build status. There are a few different types and each one means + // something different. \nFailed - The deployment build has failed. More + // details can usually be found in buildStderr\nReady - The deployment build + // was successful and the deployment is ready to be deployed\nProcessing - The + // deployment is currently waiting to have a build triggered\nBuilding - The + // deployment is currently being built + Status string `json:"status"` + // The stdout of the build. + Stdout string `json:"stdout"` + // The stderr of the build. + Stderr string `json:"stderr"` + // The deployment creation date in ISO 8601 format. + StartTime string `json:"startTime"` + // The time the build was finished in ISO 8601 format. + EndTime string `json:"endTime"` + // The build duration in seconds. + Duration int `json:"duration"` + // The code size in bytes. + Size int `json:"size"` + +} diff --git a/models/collection.go b/models/collection.go new file mode 100644 index 0000000..7ab99ea --- /dev/null +++ b/models/collection.go @@ -0,0 +1,31 @@ +package models + + +// Collection Model +type Collection struct { + // Collection ID. + Id string `json:"$id"` + // Collection creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Collection update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Collection permissions. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + Permissions []interface{} `json:"$permissions"` + // Database ID. + DatabaseId string `json:"databaseId"` + // Collection name. + Name string `json:"name"` + // Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the + // collection is inaccessible to users, but remains accessible to Server SDKs + // using API keys. + Enabled bool `json:"enabled"` + // Whether document-level permissions are enabled. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + DocumentSecurity bool `json:"documentSecurity"` + // Collection attributes. + Attributes []interface{} `json:"attributes"` + // Collection indexes. + Indexes []interface{} `json:"indexes"` + +} diff --git a/models/collectionlist.go b/models/collectionlist.go new file mode 100644 index 0000000..d098f1b --- /dev/null +++ b/models/collectionlist.go @@ -0,0 +1,11 @@ +package models + + +// CollectionsList Model +type CollectionList struct { + // Total number of collections documents that matched your query. + Total int `json:"total"` + // List of collections. + Collections []interface{} `json:"collections"` + +} diff --git a/models/continent.go b/models/continent.go new file mode 100644 index 0000000..4e853fc --- /dev/null +++ b/models/continent.go @@ -0,0 +1,11 @@ +package models + + +// Continent Model +type Continent struct { + // Continent name. + Name string `json:"name"` + // Continent two letter code. + Code string `json:"code"` + +} diff --git a/models/continentlist.go b/models/continentlist.go new file mode 100644 index 0000000..7b2f948 --- /dev/null +++ b/models/continentlist.go @@ -0,0 +1,11 @@ +package models + + +// ContinentsList Model +type ContinentList struct { + // Total number of continents documents that matched your query. + Total int `json:"total"` + // List of continents. + Continents []interface{} `json:"continents"` + +} diff --git a/models/country.go b/models/country.go new file mode 100644 index 0000000..d6d888a --- /dev/null +++ b/models/country.go @@ -0,0 +1,11 @@ +package models + + +// Country Model +type Country struct { + // Country name. + Name string `json:"name"` + // Country two-character ISO 3166-1 alpha code. + Code string `json:"code"` + +} diff --git a/models/countrylist.go b/models/countrylist.go new file mode 100644 index 0000000..5925432 --- /dev/null +++ b/models/countrylist.go @@ -0,0 +1,11 @@ +package models + + +// CountriesList Model +type CountryList struct { + // Total number of countries documents that matched your query. + Total int `json:"total"` + // List of countries. + Countries []interface{} `json:"countries"` + +} diff --git a/models/currency.go b/models/currency.go new file mode 100644 index 0000000..449e959 --- /dev/null +++ b/models/currency.go @@ -0,0 +1,22 @@ +package models + + +// Currency Model +type Currency struct { + // Currency symbol. + Symbol string `json:"symbol"` + // Currency name. + Name string `json:"name"` + // Currency native symbol. + SymbolNative string `json:"symbolNative"` + // Number of decimal digits. + DecimalDigits int `json:"decimalDigits"` + // Currency digit rounding. + Rounding float64 `json:"rounding"` + // Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) + // three-character format. + Code string `json:"code"` + // Currency plural name + NamePlural string `json:"namePlural"` + +} diff --git a/models/currencylist.go b/models/currencylist.go new file mode 100644 index 0000000..04b025d --- /dev/null +++ b/models/currencylist.go @@ -0,0 +1,11 @@ +package models + + +// CurrenciesList Model +type CurrencyList struct { + // Total number of currencies documents that matched your query. + Total int `json:"total"` + // List of currencies. + Currencies []interface{} `json:"currencies"` + +} diff --git a/models/database.go b/models/database.go new file mode 100644 index 0000000..6a71586 --- /dev/null +++ b/models/database.go @@ -0,0 +1,19 @@ +package models + + +// Database Model +type Database struct { + // Database ID. + Id string `json:"$id"` + // Database name. + Name string `json:"name"` + // Database creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Database update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the + // database is inaccessible to users, but remains accessible to Server SDKs + // using API keys. + Enabled bool `json:"enabled"` + +} diff --git a/models/databaselist.go b/models/databaselist.go new file mode 100644 index 0000000..99d1c3e --- /dev/null +++ b/models/databaselist.go @@ -0,0 +1,11 @@ +package models + + +// DatabasesList Model +type DatabaseList struct { + // Total number of databases documents that matched your query. + Total int `json:"total"` + // List of databases. + Databases []interface{} `json:"databases"` + +} diff --git a/models/deployment.go b/models/deployment.go new file mode 100644 index 0000000..0f2e799 --- /dev/null +++ b/models/deployment.go @@ -0,0 +1,54 @@ +package models + + +// Deployment Model +type Deployment struct { + // Deployment ID. + Id string `json:"$id"` + // Deployment creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Deployment update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Type of deployment. + Type string `json:"xtype"` + // Resource ID. + ResourceId string `json:"resourceId"` + // Resource type. + ResourceType string `json:"resourceType"` + // The entrypoint file to use to execute the deployment code. + Entrypoint string `json:"entrypoint"` + // The code size in bytes. + Size int `json:"size"` + // The current build ID. + BuildId string `json:"buildId"` + // Whether the deployment should be automatically activated. + Activate bool `json:"activate"` + // The deployment status. Possible values are "processing", "building", + // "waiting", "ready", and "failed". + Status string `json:"status"` + // The build logs. + BuildLogs string `json:"buildLogs"` + // The current build time in seconds. + BuildTime int `json:"buildTime"` + // The name of the vcs provider repository + ProviderRepositoryName string `json:"providerRepositoryName"` + // The name of the vcs provider repository owner + ProviderRepositoryOwner string `json:"providerRepositoryOwner"` + // The url of the vcs provider repository + ProviderRepositoryUrl string `json:"providerRepositoryUrl"` + // The branch of the vcs repository + ProviderBranch string `json:"providerBranch"` + // The commit hash of the vcs commit + ProviderCommitHash string `json:"providerCommitHash"` + // The url of vcs commit author + ProviderCommitAuthorUrl string `json:"providerCommitAuthorUrl"` + // The name of vcs commit author + ProviderCommitAuthor string `json:"providerCommitAuthor"` + // The commit message + ProviderCommitMessage string `json:"providerCommitMessage"` + // The url of the vcs commit + ProviderCommitUrl string `json:"providerCommitUrl"` + // The branch of the vcs repository + ProviderBranchUrl string `json:"providerBranchUrl"` + +} diff --git a/models/deploymentlist.go b/models/deploymentlist.go new file mode 100644 index 0000000..75f79c2 --- /dev/null +++ b/models/deploymentlist.go @@ -0,0 +1,11 @@ +package models + + +// DeploymentsList Model +type DeploymentList struct { + // Total number of deployments documents that matched your query. + Total int `json:"total"` + // List of deployments. + Deployments []interface{} `json:"deployments"` + +} diff --git a/models/document.go b/models/document.go new file mode 100644 index 0000000..e9a3e70 --- /dev/null +++ b/models/document.go @@ -0,0 +1,22 @@ +package models + + +// Document Model +type Document struct { + // Document ID. + Id string `json:"$id"` + // Collection ID. + CollectionId string `json:"$collectionId"` + // Database ID. + DatabaseId string `json:"$databaseId"` + // Document creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Document update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Document permissions. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + Permissions []interface{} `json:"$permissions"` + + // Additional properties + data interface{} +} diff --git a/models/documentlist.go b/models/documentlist.go new file mode 100644 index 0000000..fa03a12 --- /dev/null +++ b/models/documentlist.go @@ -0,0 +1,11 @@ +package models + + +// DocumentsList Model +type DocumentList struct { + // Total number of documents documents that matched your query. + Total int `json:"total"` + // List of documents. + Documents []interface{} `json:"documents"` + +} diff --git a/models/execution.go b/models/execution.go new file mode 100644 index 0000000..075999e --- /dev/null +++ b/models/execution.go @@ -0,0 +1,50 @@ +package models + + +// Execution Model +type Execution struct { + // Execution ID. + Id string `json:"$id"` + // Execution creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Execution upate date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Execution roles. + Permissions []interface{} `json:"$permissions"` + // Function ID. + FunctionId string `json:"functionId"` + // The trigger that caused the function to execute. Possible values can be: + // `http`, `schedule`, or `event`. + Trigger string `json:"trigger"` + // The status of the function execution. Possible values can be: `waiting`, + // `processing`, `completed`, or `failed`. + Status string `json:"status"` + // HTTP request method type. + RequestMethod string `json:"requestMethod"` + // HTTP request path and query. + RequestPath string `json:"requestPath"` + // HTTP response headers as a key-value object. This will return only + // whitelisted headers. All headers are returned if execution is created as + // synchronous. + RequestHeaders []interface{} `json:"requestHeaders"` + // HTTP response status code. + ResponseStatusCode int `json:"responseStatusCode"` + // HTTP response body. This will return empty unless execution is created as + // synchronous. + ResponseBody string `json:"responseBody"` + // HTTP response headers as a key-value object. This will return only + // whitelisted headers. All headers are returned if execution is created as + // synchronous. + ResponseHeaders []interface{} `json:"responseHeaders"` + // Function logs. Includes the last 4,000 characters. This will return an + // empty string unless the response is returned using an API key or as part of + // a webhook payload. + Logs string `json:"logs"` + // Function errors. Includes the last 4,000 characters. This will return an + // empty string unless the response is returned using an API key or as part of + // a webhook payload. + Errors string `json:"errors"` + // Function execution duration in seconds. + Duration float64 `json:"duration"` + +} diff --git a/models/executionlist.go b/models/executionlist.go new file mode 100644 index 0000000..2b19e44 --- /dev/null +++ b/models/executionlist.go @@ -0,0 +1,11 @@ +package models + + +// ExecutionsList Model +type ExecutionList struct { + // Total number of executions documents that matched your query. + Total int `json:"total"` + // List of executions. + Executions []interface{} `json:"executions"` + +} diff --git a/models/file.go b/models/file.go new file mode 100644 index 0000000..249345f --- /dev/null +++ b/models/file.go @@ -0,0 +1,30 @@ +package models + + +// File Model +type File struct { + // File ID. + Id string `json:"$id"` + // Bucket ID. + BucketId string `json:"bucketId"` + // File creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // File update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // File permissions. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + Permissions []interface{} `json:"$permissions"` + // File name. + Name string `json:"name"` + // File MD5 signature. + Signature string `json:"signature"` + // File mime type. + MimeType string `json:"mimeType"` + // File original size in bytes. + SizeOriginal int `json:"sizeOriginal"` + // Total number of chunks available + ChunksTotal int `json:"chunksTotal"` + // Total number of chunks uploaded + ChunksUploaded int `json:"chunksUploaded"` + +} diff --git a/models/filelist.go b/models/filelist.go new file mode 100644 index 0000000..ce7bc65 --- /dev/null +++ b/models/filelist.go @@ -0,0 +1,11 @@ +package models + + +// FilesList Model +type FileList struct { + // Total number of files documents that matched your query. + Total int `json:"total"` + // List of files. + Files []interface{} `json:"files"` + +} diff --git a/models/function.go b/models/function.go new file mode 100644 index 0000000..52d2060 --- /dev/null +++ b/models/function.go @@ -0,0 +1,59 @@ +package models + + +// Function Model +type Function struct { + // Function ID. + Id string `json:"$id"` + // Function creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Function update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Execution permissions. + Execute []interface{} `json:"execute"` + // Function name. + Name string `json:"name"` + // Function enabled. + Enabled bool `json:"enabled"` + // Is the function deployed with the latest configuration? This is set to + // false if you've changed an environment variables, entrypoint, commands, or + // other settings that needs redeploy to be applied. When the value is false, + // redeploy the function to update it with the latest configuration. + Live bool `json:"live"` + // Whether executions will be logged. When set to false, executions will not + // be logged, but will reduce resource used by your Appwrite project. + Logging bool `json:"logging"` + // Function execution runtime. + Runtime string `json:"runtime"` + // Function's active deployment ID. + Deployment string `json:"deployment"` + // Allowed permission scopes. + Scopes []interface{} `json:"scopes"` + // Function variables. + Vars []interface{} `json:"vars"` + // Function trigger events. + Events []interface{} `json:"events"` + // Function execution schedult in CRON format. + Schedule string `json:"schedule"` + // Function execution timeout in seconds. + Timeout int `json:"timeout"` + // The entrypoint file used to execute the deployment. + Entrypoint string `json:"entrypoint"` + // The build command used to build the deployment. + Commands string `json:"commands"` + // Version of Open Runtimes used for the function. + Version string `json:"version"` + // Function VCS (Version Control System) installation id. + InstallationId string `json:"installationId"` + // VCS (Version Control System) Repository ID + ProviderRepositoryId string `json:"providerRepositoryId"` + // VCS (Version Control System) branch name + ProviderBranch string `json:"providerBranch"` + // Path to function in VCS (Version Control System) repository + ProviderRootDirectory string `json:"providerRootDirectory"` + // Is VCS (Version Control System) connection is in silent mode? When in + // silence mode, no comments will be posted on the repository pull or merge + // requests + ProviderSilentMode bool `json:"providerSilentMode"` + +} diff --git a/models/functionlist.go b/models/functionlist.go new file mode 100644 index 0000000..8a4e08f --- /dev/null +++ b/models/functionlist.go @@ -0,0 +1,11 @@ +package models + + +// FunctionsList Model +type FunctionList struct { + // Total number of functions documents that matched your query. + Total int `json:"total"` + // List of functions. + Functions []interface{} `json:"functions"` + +} diff --git a/models/headers.go b/models/headers.go new file mode 100644 index 0000000..1ff5d80 --- /dev/null +++ b/models/headers.go @@ -0,0 +1,11 @@ +package models + + +// Headers Model +type Headers struct { + // Header name. + Name string `json:"name"` + // Header value. + Value string `json:"value"` + +} diff --git a/models/healthantivirus.go b/models/healthantivirus.go new file mode 100644 index 0000000..4b4a473 --- /dev/null +++ b/models/healthantivirus.go @@ -0,0 +1,11 @@ +package models + + +// HealthAntivirus Model +type HealthAntivirus struct { + // Antivirus version. + Version string `json:"version"` + // Antivirus status. Possible values can are: `disabled`, `offline`, `online` + Status string `json:"status"` + +} diff --git a/models/healthcertificate.go b/models/healthcertificate.go new file mode 100644 index 0000000..da87f34 --- /dev/null +++ b/models/healthcertificate.go @@ -0,0 +1,19 @@ +package models + + +// HealthCertificate Model +type HealthCertificate struct { + // Certificate name + Name string `json:"name"` + // Subject SN + SubjectSN string `json:"subjectSN"` + // Issuer organisation + IssuerOrganisation string `json:"issuerOrganisation"` + // Valid from + ValidFrom string `json:"validFrom"` + // Valid to + ValidTo string `json:"validTo"` + // Signature type SN + SignatureTypeSN string `json:"signatureTypeSN"` + +} diff --git a/models/healthqueue.go b/models/healthqueue.go new file mode 100644 index 0000000..896ba4f --- /dev/null +++ b/models/healthqueue.go @@ -0,0 +1,9 @@ +package models + + +// HealthQueue Model +type HealthQueue struct { + // Amount of actions in the queue. + Size int `json:"size"` + +} diff --git a/models/healthstatus.go b/models/healthstatus.go new file mode 100644 index 0000000..d3ae8cd --- /dev/null +++ b/models/healthstatus.go @@ -0,0 +1,13 @@ +package models + + +// HealthStatus Model +type HealthStatus struct { + // Name of the service. + Name string `json:"name"` + // Duration in milliseconds how long the health check took. + Ping int `json:"ping"` + // Service status. Possible values can are: `pass`, `fail` + Status string `json:"status"` + +} diff --git a/models/healthtime.go b/models/healthtime.go new file mode 100644 index 0000000..e9dc207 --- /dev/null +++ b/models/healthtime.go @@ -0,0 +1,13 @@ +package models + + +// HealthTime Model +type HealthTime struct { + // Current unix timestamp on trustful remote server. + RemoteTime int `json:"remoteTime"` + // Current unix timestamp of local server where Appwrite runs. + LocalTime int `json:"localTime"` + // Difference of unix remote and local timestamps in milliseconds. + Diff int `json:"diff"` + +} diff --git a/models/identity.go b/models/identity.go new file mode 100644 index 0000000..75baff6 --- /dev/null +++ b/models/identity.go @@ -0,0 +1,27 @@ +package models + + +// Identity Model +type Identity struct { + // Identity ID. + Id string `json:"$id"` + // Identity creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Identity update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // User ID. + UserId string `json:"userId"` + // Identity Provider. + Provider string `json:"provider"` + // ID of the User in the Identity Provider. + ProviderUid string `json:"providerUid"` + // Email of the User in the Identity Provider. + ProviderEmail string `json:"providerEmail"` + // Identity Provider Access Token. + ProviderAccessToken string `json:"providerAccessToken"` + // The date of when the access token expires in ISO 8601 format. + ProviderAccessTokenExpiry string `json:"providerAccessTokenExpiry"` + // Identity Provider Refresh Token. + ProviderRefreshToken string `json:"providerRefreshToken"` + +} diff --git a/models/identitylist.go b/models/identitylist.go new file mode 100644 index 0000000..2604430 --- /dev/null +++ b/models/identitylist.go @@ -0,0 +1,11 @@ +package models + + +// IdentitiesList Model +type IdentityList struct { + // Total number of identities documents that matched your query. + Total int `json:"total"` + // List of identities. + Identities []interface{} `json:"identities"` + +} diff --git a/models/index.go b/models/index.go new file mode 100644 index 0000000..3e9fe0a --- /dev/null +++ b/models/index.go @@ -0,0 +1,21 @@ +package models + + +// Index Model +type Index struct { + // Index Key. + Key string `json:"key"` + // Index type. + Type string `json:"xtype"` + // Index status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an index. + Error string `json:"xerror"` + // Index attributes. + Attributes []interface{} `json:"attributes"` + // Index orders. + Orders []interface{} `json:"orders"` + +} diff --git a/models/indexlist.go b/models/indexlist.go new file mode 100644 index 0000000..9e526ed --- /dev/null +++ b/models/indexlist.go @@ -0,0 +1,11 @@ +package models + + +// IndexesList Model +type IndexList struct { + // Total number of indexes documents that matched your query. + Total int `json:"total"` + // List of indexes. + Indexes []interface{} `json:"indexes"` + +} diff --git a/models/jwt.go b/models/jwt.go new file mode 100644 index 0000000..9962b2e --- /dev/null +++ b/models/jwt.go @@ -0,0 +1,9 @@ +package models + + +// JWT Model +type Jwt struct { + // JWT encoded string. + Jwt string `json:"jwt"` + +} diff --git a/models/language.go b/models/language.go new file mode 100644 index 0000000..042afe7 --- /dev/null +++ b/models/language.go @@ -0,0 +1,13 @@ +package models + + +// Language Model +type Language struct { + // Language name. + Name string `json:"name"` + // Language two-character ISO 639-1 codes. + Code string `json:"code"` + // Language native name. + NativeName string `json:"nativeName"` + +} diff --git a/models/languagelist.go b/models/languagelist.go new file mode 100644 index 0000000..545159f --- /dev/null +++ b/models/languagelist.go @@ -0,0 +1,11 @@ +package models + + +// LanguagesList Model +type LanguageList struct { + // Total number of languages documents that matched your query. + Total int `json:"total"` + // List of languages. + Languages []interface{} `json:"languages"` + +} diff --git a/models/locale.go b/models/locale.go new file mode 100644 index 0000000..87807ca --- /dev/null +++ b/models/locale.go @@ -0,0 +1,25 @@ +package models + + +// Locale Model +type Locale struct { + // User IP address. + Ip string `json:"ip"` + // Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) + // two-character format + CountryCode string `json:"countryCode"` + // Country name. This field support localization. + Country string `json:"country"` + // Continent code. A two character continent code "AF" for Africa, "AN" for + // Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" + // for Oceania, and "SA" for South America. + ContinentCode string `json:"continentCode"` + // Continent name. This field support localization. + Continent string `json:"continent"` + // True if country is part of the European Union. + Eu bool `json:"eu"` + // Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) + // three-character format + Currency string `json:"currency"` + +} diff --git a/models/localecode.go b/models/localecode.go new file mode 100644 index 0000000..02701b5 --- /dev/null +++ b/models/localecode.go @@ -0,0 +1,12 @@ +package models + + +// LocaleCode Model +type LocaleCode struct { + // Locale codes in [ISO + // 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) + Code string `json:"code"` + // Locale name + Name string `json:"name"` + +} diff --git a/models/localecodelist.go b/models/localecodelist.go new file mode 100644 index 0000000..b44c1b6 --- /dev/null +++ b/models/localecodelist.go @@ -0,0 +1,11 @@ +package models + + +// LocaleCodesList Model +type LocaleCodeList struct { + // Total number of localeCodes documents that matched your query. + Total int `json:"total"` + // List of localeCodes. + LocaleCodes []interface{} `json:"localeCodes"` + +} diff --git a/models/log.go b/models/log.go new file mode 100644 index 0000000..d3ea6c4 --- /dev/null +++ b/models/log.go @@ -0,0 +1,51 @@ +package models + + +// Log Model +type Log struct { + // Event name. + Event string `json:"event"` + // User ID. + UserId string `json:"userId"` + // User Email. + UserEmail string `json:"userEmail"` + // User Name. + UserName string `json:"userName"` + // API mode when event triggered. + Mode string `json:"mode"` + // IP session in use when the session was created. + Ip string `json:"ip"` + // Log creation date in ISO 8601 format. + Time string `json:"time"` + // Operating system code name. View list of [available + // options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + OsCode string `json:"osCode"` + // Operating system name. + OsName string `json:"osName"` + // Operating system version. + OsVersion string `json:"osVersion"` + // Client type. + ClientType string `json:"clientType"` + // Client code name. View list of [available + // options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + ClientCode string `json:"clientCode"` + // Client name. + ClientName string `json:"clientName"` + // Client version. + ClientVersion string `json:"clientVersion"` + // Client engine name. + ClientEngine string `json:"clientEngine"` + // Client engine name. + ClientEngineVersion string `json:"clientEngineVersion"` + // Device name. + DeviceName string `json:"deviceName"` + // Device brand name. + DeviceBrand string `json:"deviceBrand"` + // Device model name. + DeviceModel string `json:"deviceModel"` + // Country two-character ISO 3166-1 alpha code. + CountryCode string `json:"countryCode"` + // Country name. + CountryName string `json:"countryName"` + +} diff --git a/models/loglist.go b/models/loglist.go new file mode 100644 index 0000000..3b60f95 --- /dev/null +++ b/models/loglist.go @@ -0,0 +1,11 @@ +package models + + +// LogsList Model +type LogList struct { + // Total number of logs documents that matched your query. + Total int `json:"total"` + // List of logs. + Logs []interface{} `json:"logs"` + +} diff --git a/models/membership.go b/models/membership.go new file mode 100644 index 0000000..51112fa --- /dev/null +++ b/models/membership.go @@ -0,0 +1,36 @@ +package models + + +// Membership Model +type Membership struct { + // Membership ID. + Id string `json:"$id"` + // Membership creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Membership update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // User ID. + UserId string `json:"userId"` + // User name. + UserName string `json:"userName"` + // User email address. + UserEmail string `json:"userEmail"` + // Team ID. + TeamId string `json:"teamId"` + // Team name. + TeamName string `json:"teamName"` + // Date, the user has been invited to join the team in ISO 8601 format. + Invited string `json:"invited"` + // Date, the user has accepted the invitation to join the team in ISO 8601 + // format. + Joined string `json:"joined"` + // User confirmation status, true if the user has joined the team or false + // otherwise. + Confirm bool `json:"confirm"` + // Multi factor authentication status, true if the user has MFA enabled or + // false otherwise. + Mfa bool `json:"mfa"` + // User list of roles + Roles []interface{} `json:"roles"` + +} diff --git a/models/membershiplist.go b/models/membershiplist.go new file mode 100644 index 0000000..fa8554c --- /dev/null +++ b/models/membershiplist.go @@ -0,0 +1,11 @@ +package models + + +// MembershipsList Model +type MembershipList struct { + // Total number of memberships documents that matched your query. + Total int `json:"total"` + // List of memberships. + Memberships []interface{} `json:"memberships"` + +} diff --git a/models/message.go b/models/message.go new file mode 100644 index 0000000..3880d09 --- /dev/null +++ b/models/message.go @@ -0,0 +1,33 @@ +package models + + +// Message Model +type Message struct { + // Message ID. + Id string `json:"$id"` + // Message creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Message update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Message provider type. + ProviderType string `json:"providerType"` + // Topic IDs set as recipients. + Topics []interface{} `json:"topics"` + // User IDs set as recipients. + Users []interface{} `json:"users"` + // Target IDs set as recipients. + Targets []interface{} `json:"targets"` + // The scheduled time for message. + ScheduledAt string `json:"scheduledAt"` + // The time when the message was delivered. + DeliveredAt string `json:"deliveredAt"` + // Delivery errors if any. + DeliveryErrors []interface{} `json:"deliveryErrors"` + // Number of recipients the message was delivered to. + DeliveredTotal int `json:"deliveredTotal"` + // Data of the message. + Data interface{} `json:"data"` + // Status of delivery. + Status string `json:"status"` + +} diff --git a/models/messagelist.go b/models/messagelist.go new file mode 100644 index 0000000..007e763 --- /dev/null +++ b/models/messagelist.go @@ -0,0 +1,11 @@ +package models + + +// MessageList Model +type MessageList struct { + // Total number of messages documents that matched your query. + Total int `json:"total"` + // List of messages. + Messages []interface{} `json:"messages"` + +} diff --git a/models/mfachallenge.go b/models/mfachallenge.go new file mode 100644 index 0000000..8023893 --- /dev/null +++ b/models/mfachallenge.go @@ -0,0 +1,15 @@ +package models + + +// MFAChallenge Model +type MfaChallenge struct { + // Token ID. + Id string `json:"$id"` + // Token creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // User ID. + UserId string `json:"userId"` + // Token expiration date in ISO 8601 format. + Expire string `json:"expire"` + +} diff --git a/models/mfafactors.go b/models/mfafactors.go new file mode 100644 index 0000000..2417ecc --- /dev/null +++ b/models/mfafactors.go @@ -0,0 +1,15 @@ +package models + + +// MFAFactors Model +type MfaFactors struct { + // Can TOTP be used for MFA challenge for this account. + Totp bool `json:"totp"` + // Can phone (SMS) be used for MFA challenge for this account. + Phone bool `json:"phone"` + // Can email be used for MFA challenge for this account. + Email bool `json:"email"` + // Can recovery code be used for MFA challenge for this account. + RecoveryCode bool `json:"recoveryCode"` + +} diff --git a/models/mfarecoverycodes.go b/models/mfarecoverycodes.go new file mode 100644 index 0000000..0f02f63 --- /dev/null +++ b/models/mfarecoverycodes.go @@ -0,0 +1,9 @@ +package models + + +// MFARecoveryCodes Model +type MfaRecoveryCodes struct { + // Recovery codes. + RecoveryCodes []interface{} `json:"recoveryCodes"` + +} diff --git a/models/mfatype.go b/models/mfatype.go new file mode 100644 index 0000000..aefd404 --- /dev/null +++ b/models/mfatype.go @@ -0,0 +1,11 @@ +package models + + +// MFAType Model +type MfaType struct { + // Secret token used for TOTP factor. + Secret string `json:"secret"` + // URI for authenticator apps. + Uri string `json:"uri"` + +} diff --git a/models/phone.go b/models/phone.go new file mode 100644 index 0000000..040cca7 --- /dev/null +++ b/models/phone.go @@ -0,0 +1,13 @@ +package models + + +// Phone Model +type Phone struct { + // Phone code. + Code string `json:"code"` + // Country two-character ISO 3166-1 alpha code. + CountryCode string `json:"countryCode"` + // Country name. + CountryName string `json:"countryName"` + +} diff --git a/models/phonelist.go b/models/phonelist.go new file mode 100644 index 0000000..125f1a4 --- /dev/null +++ b/models/phonelist.go @@ -0,0 +1,11 @@ +package models + + +// PhonesList Model +type PhoneList struct { + // Total number of phones documents that matched your query. + Total int `json:"total"` + // List of phones. + Phones []interface{} `json:"phones"` + +} diff --git a/models/preferences.go b/models/preferences.go new file mode 100644 index 0000000..1bdd286 --- /dev/null +++ b/models/preferences.go @@ -0,0 +1,9 @@ +package models + + +// Preferences Model +type Preferences struct { + + // Additional properties + data interface{} +} diff --git a/models/provider.go b/models/provider.go new file mode 100644 index 0000000..95eea4a --- /dev/null +++ b/models/provider.go @@ -0,0 +1,25 @@ +package models + + +// Provider Model +type Provider struct { + // Provider ID. + Id string `json:"$id"` + // Provider creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Provider update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // The name for the provider instance. + Name string `json:"name"` + // The name of the provider service. + Provider string `json:"provider"` + // Is provider enabled? + Enabled bool `json:"enabled"` + // Type of provider. + Type string `json:"xtype"` + // Provider credentials. + Credentials interface{} `json:"credentials"` + // Provider options. + Options interface{} `json:"options"` + +} diff --git a/models/providerlist.go b/models/providerlist.go new file mode 100644 index 0000000..a578262 --- /dev/null +++ b/models/providerlist.go @@ -0,0 +1,11 @@ +package models + + +// ProviderList Model +type ProviderList struct { + // Total number of providers documents that matched your query. + Total int `json:"total"` + // List of providers. + Providers []interface{} `json:"providers"` + +} diff --git a/models/runtime.go b/models/runtime.go new file mode 100644 index 0000000..4fbf8ca --- /dev/null +++ b/models/runtime.go @@ -0,0 +1,21 @@ +package models + + +// Runtime Model +type Runtime struct { + // Runtime ID. + Id string `json:"$id"` + // Runtime Name. + Name string `json:"name"` + // Runtime version. + Version string `json:"version"` + // Base Docker image used to build the runtime. + Base string `json:"base"` + // Image name of Docker Hub. + Image string `json:"image"` + // Name of the logo image. + Logo string `json:"logo"` + // List of supported architectures. + Supports []interface{} `json:"supports"` + +} diff --git a/models/runtimelist.go b/models/runtimelist.go new file mode 100644 index 0000000..b6be732 --- /dev/null +++ b/models/runtimelist.go @@ -0,0 +1,11 @@ +package models + + +// RuntimesList Model +type RuntimeList struct { + // Total number of runtimes documents that matched your query. + Total int `json:"total"` + // List of runtimes. + Runtimes []interface{} `json:"runtimes"` + +} diff --git a/models/session.go b/models/session.go new file mode 100644 index 0000000..dbdedfc --- /dev/null +++ b/models/session.go @@ -0,0 +1,69 @@ +package models + + +// Session Model +type Session struct { + // Session ID. + Id string `json:"$id"` + // Session creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Session update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // User ID. + UserId string `json:"userId"` + // Session expiration date in ISO 8601 format. + Expire string `json:"expire"` + // Session Provider. + Provider string `json:"provider"` + // Session Provider User ID. + ProviderUid string `json:"providerUid"` + // Session Provider Access Token. + ProviderAccessToken string `json:"providerAccessToken"` + // The date of when the access token expires in ISO 8601 format. + ProviderAccessTokenExpiry string `json:"providerAccessTokenExpiry"` + // Session Provider Refresh Token. + ProviderRefreshToken string `json:"providerRefreshToken"` + // IP in use when the session was created. + Ip string `json:"ip"` + // Operating system code name. View list of [available + // options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + OsCode string `json:"osCode"` + // Operating system name. + OsName string `json:"osName"` + // Operating system version. + OsVersion string `json:"osVersion"` + // Client type. + ClientType string `json:"clientType"` + // Client code name. View list of [available + // options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + ClientCode string `json:"clientCode"` + // Client name. + ClientName string `json:"clientName"` + // Client version. + ClientVersion string `json:"clientVersion"` + // Client engine name. + ClientEngine string `json:"clientEngine"` + // Client engine name. + ClientEngineVersion string `json:"clientEngineVersion"` + // Device name. + DeviceName string `json:"deviceName"` + // Device brand name. + DeviceBrand string `json:"deviceBrand"` + // Device model name. + DeviceModel string `json:"deviceModel"` + // Country two-character ISO 3166-1 alpha code. + CountryCode string `json:"countryCode"` + // Country name. + CountryName string `json:"countryName"` + // Returns true if this the current user session. + Current bool `json:"current"` + // Returns a list of active session factors. + Factors []interface{} `json:"factors"` + // Secret used to authenticate the user. Only included if the request was made + // with an API key + Secret string `json:"secret"` + // Most recent date in ISO 8601 format when the session successfully passed + // MFA challenge. + MfaUpdatedAt string `json:"mfaUpdatedAt"` + +} diff --git a/models/sessionlist.go b/models/sessionlist.go new file mode 100644 index 0000000..ccae49a --- /dev/null +++ b/models/sessionlist.go @@ -0,0 +1,11 @@ +package models + + +// SessionsList Model +type SessionList struct { + // Total number of sessions documents that matched your query. + Total int `json:"total"` + // List of sessions. + Sessions []interface{} `json:"sessions"` + +} diff --git a/models/subscriber.go b/models/subscriber.go new file mode 100644 index 0000000..735d5c6 --- /dev/null +++ b/models/subscriber.go @@ -0,0 +1,26 @@ +package models + + +// Subscriber Model +type Subscriber struct { + // Subscriber ID. + Id string `json:"$id"` + // Subscriber creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Subscriber update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Target ID. + TargetId string `json:"targetId"` + // Target. + Target interface{} `json:"target"` + // Topic ID. + UserId string `json:"userId"` + // User Name. + UserName string `json:"userName"` + // Topic ID. + TopicId string `json:"topicId"` + // The target provider type. Can be one of the following: `email`, `sms` or + // `push`. + ProviderType string `json:"providerType"` + +} diff --git a/models/subscriberlist.go b/models/subscriberlist.go new file mode 100644 index 0000000..7085113 --- /dev/null +++ b/models/subscriberlist.go @@ -0,0 +1,11 @@ +package models + + +// SubscriberList Model +type SubscriberList struct { + // Total number of subscribers documents that matched your query. + Total int `json:"total"` + // List of subscribers. + Subscribers []interface{} `json:"subscribers"` + +} diff --git a/models/target.go b/models/target.go new file mode 100644 index 0000000..7cbd095 --- /dev/null +++ b/models/target.go @@ -0,0 +1,24 @@ +package models + + +// Target Model +type Target struct { + // Target ID. + Id string `json:"$id"` + // Target creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Target update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Target Name. + Name string `json:"name"` + // User ID. + UserId string `json:"userId"` + // Provider ID. + ProviderId string `json:"providerId"` + // The target provider type. Can be one of the following: `email`, `sms` or + // `push`. + ProviderType string `json:"providerType"` + // The target identifier. + Identifier string `json:"identifier"` + +} diff --git a/models/targetlist.go b/models/targetlist.go new file mode 100644 index 0000000..9e2451b --- /dev/null +++ b/models/targetlist.go @@ -0,0 +1,11 @@ +package models + + +// TargetList Model +type TargetList struct { + // Total number of targets documents that matched your query. + Total int `json:"total"` + // List of targets. + Targets []interface{} `json:"targets"` + +} diff --git a/models/team.go b/models/team.go new file mode 100644 index 0000000..e9f8b7e --- /dev/null +++ b/models/team.go @@ -0,0 +1,19 @@ +package models + + +// Team Model +type Team struct { + // Team ID. + Id string `json:"$id"` + // Team creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Team update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Team name. + Name string `json:"name"` + // Total number of team members. + Total int `json:"total"` + // Team preferences as a key-value object + Prefs interface{} `json:"prefs"` + +} diff --git a/models/teamlist.go b/models/teamlist.go new file mode 100644 index 0000000..58af881 --- /dev/null +++ b/models/teamlist.go @@ -0,0 +1,11 @@ +package models + + +// TeamsList Model +type TeamList struct { + // Total number of teams documents that matched your query. + Total int `json:"total"` + // List of teams. + Teams []interface{} `json:"teams"` + +} diff --git a/models/token.go b/models/token.go new file mode 100644 index 0000000..f89ef02 --- /dev/null +++ b/models/token.go @@ -0,0 +1,22 @@ +package models + + +// Token Model +type Token struct { + // Token ID. + Id string `json:"$id"` + // Token creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // User ID. + UserId string `json:"userId"` + // Token secret key. This will return an empty string unless the response is + // returned using an API key or as part of a webhook payload. + Secret string `json:"secret"` + // Token expiration date in ISO 8601 format. + Expire string `json:"expire"` + // Security phrase of a token. Empty if security phrase was not requested when + // creating a token. It includes randomly generated phrase which is also sent + // in the external resource such as email. + Phrase string `json:"phrase"` + +} diff --git a/models/topic.go b/models/topic.go new file mode 100644 index 0000000..d459cea --- /dev/null +++ b/models/topic.go @@ -0,0 +1,23 @@ +package models + + +// Topic Model +type Topic struct { + // Topic ID. + Id string `json:"$id"` + // Topic creation time in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Topic update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // The name of the topic. + Name string `json:"name"` + // Total count of email subscribers subscribed to the topic. + EmailTotal int `json:"emailTotal"` + // Total count of SMS subscribers subscribed to the topic. + SmsTotal int `json:"smsTotal"` + // Total count of push subscribers subscribed to the topic. + PushTotal int `json:"pushTotal"` + // Subscribe permissions. + Subscribe []interface{} `json:"subscribe"` + +} diff --git a/models/topiclist.go b/models/topiclist.go new file mode 100644 index 0000000..cbd4619 --- /dev/null +++ b/models/topiclist.go @@ -0,0 +1,11 @@ +package models + + +// TopicList Model +type TopicList struct { + // Total number of topics documents that matched your query. + Total int `json:"total"` + // List of topics. + Topics []interface{} `json:"topics"` + +} diff --git a/models/user.go b/models/user.go new file mode 100644 index 0000000..bfb1df4 --- /dev/null +++ b/models/user.go @@ -0,0 +1,47 @@ +package models + + +// User Model +type User struct { + // User ID. + Id string `json:"$id"` + // User creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // User update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // User name. + Name string `json:"name"` + // Hashed user password. + Password string `json:"password"` + // Password hashing algorithm. + Hash string `json:"hash"` + // Password hashing algorithm configuration. + HashOptions interface{} `json:"hashOptions"` + // User registration date in ISO 8601 format. + Registration string `json:"registration"` + // User status. Pass `true` for enabled and `false` for disabled. + Status bool `json:"status"` + // Labels for the user. + Labels []interface{} `json:"labels"` + // Password update time in ISO 8601 format. + PasswordUpdate string `json:"passwordUpdate"` + // User email address. + Email string `json:"email"` + // User phone number in E.164 format. + Phone string `json:"phone"` + // Email verification status. + EmailVerification bool `json:"emailVerification"` + // Phone verification status. + PhoneVerification bool `json:"phoneVerification"` + // Multi factor authentication status. + Mfa bool `json:"mfa"` + // User preferences as a key-value object + Prefs interface{} `json:"prefs"` + // A user-owned message receiver. A single user may have multiple e.g. emails, + // phones, and a browser. Each target is registered with a single provider. + Targets []interface{} `json:"targets"` + // Most recent access date in ISO 8601 format. This attribute is only updated + // again after 24 hours. + AccessedAt string `json:"accessedAt"` + +} diff --git a/models/userlist.go b/models/userlist.go new file mode 100644 index 0000000..c69e580 --- /dev/null +++ b/models/userlist.go @@ -0,0 +1,11 @@ +package models + + +// UsersList Model +type UserList struct { + // Total number of users documents that matched your query. + Total int `json:"total"` + // List of users. + Users []interface{} `json:"users"` + +} diff --git a/models/variable.go b/models/variable.go new file mode 100644 index 0000000..418fbc2 --- /dev/null +++ b/models/variable.go @@ -0,0 +1,23 @@ +package models + + +// Variable Model +type Variable struct { + // Variable ID. + Id string `json:"$id"` + // Variable creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Variable creation date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Variable key. + Key string `json:"key"` + // Variable value. + Value string `json:"value"` + // Service to which the variable belongs. Possible values are "project", + // "function" + ResourceType string `json:"resourceType"` + // ID of resource to which the variable belongs. If resourceType is "project", + // it is empty. If resourceType is "function", it is ID of the function. + ResourceId string `json:"resourceId"` + +} diff --git a/models/variablelist.go b/models/variablelist.go new file mode 100644 index 0000000..21d0c8b --- /dev/null +++ b/models/variablelist.go @@ -0,0 +1,11 @@ +package models + + +// VariablesList Model +type VariableList struct { + // Total number of variables documents that matched your query. + Total int `json:"total"` + // List of variables. + Variables []interface{} `json:"variables"` + +} diff --git a/permission/permission.go b/permission/permission.go new file mode 100644 index 0000000..8563e3f --- /dev/null +++ b/permission/permission.go @@ -0,0 +1,23 @@ +package permission + +import "fmt" + +func Read(role string) string { + return fmt.Sprintf("read(\"%s\")", role) +} + +func Write(role string) string { + return fmt.Sprintf("write(\"%s\")", role) +} + +func Create(role string) string { + return fmt.Sprintf("create(\"%s\")", role) +} + +func Update(role string) string { + return fmt.Sprintf("update(\"%s\")", role) +} + +func Delete(role string) string { + return fmt.Sprintf("delete(\"%s\")", role) +} diff --git a/query/query.go b/query/query.go new file mode 100644 index 0000000..079aa3c --- /dev/null +++ b/query/query.go @@ -0,0 +1,242 @@ +package query + +import ( + "encoding/json" +) + +func toArray(val interface{}) []interface{} { + switch v := val.(type) { + case nil: + return nil + case []interface{}: + return v + default: + return []interface{}{val} + } +} + +type queryOptions struct { + Method string + Attribute *string + Values *[]interface{} +} + +func parseQuery(options queryOptions) string { + data := struct { + Method string `json:"method"` + Attribute string `json:"attribute,omitempty"` + Values []interface{} `json:"values,omitempty"` + }{ + Method: options.Method, + } + + if options.Attribute != nil { + data.Attribute = *options.Attribute + } + + if options.Values != nil { + data.Values = *options.Values + } + + jsonData, _ := json.Marshal(data) + + return string(jsonData) +} + +func Equal(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "equal", + Attribute: &attribute, + Values: &values, + }) +} + +func NotEqual(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "notEqual", + Attribute: &attribute, + Values: &values, + }) +} + +func LessThan(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "lessThan", + Attribute: &attribute, + Values: &values, + }) +} + +func LessThanEqual(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "lessThanEqual", + Attribute: &attribute, + Values: &values, + }) +} + +func GreaterThan(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "greaterThan", + Attribute: &attribute, + Values: &values, + }) +} + +func GreaterThanEqual(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "greaterThanEqual", + Attribute: &attribute, + Values: &values, + }) +} + +func Search(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "search", + Attribute: &attribute, + Values: &values, + }) +} + +func IsNull(attribute string) string { + return parseQuery(queryOptions{ + Method: "isNull", + Attribute: &attribute, + }) +} + +func IsNotNull(attribute string) string { + return parseQuery(queryOptions{ + Method: "isNotNull", + Attribute: &attribute, + }) +} + +func Between(attribute string, start, end interface{}) string { + values := []interface{}{start, end} + return parseQuery(queryOptions{ + Method: "between", + Attribute: &attribute, + Values: &values, + }) +} + +func StartsWith(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "startsWith", + Attribute: &attribute, + Values: &values, + }) +} + +func EndsWith(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "endsWith", + Attribute: &attribute, + Values: &values, + }) +} + +func Contains(attribute string, value interface{}) string { + values := toArray(value) + return parseQuery(queryOptions{ + Method: "contains", + Attribute: &attribute, + Values: &values, + }) +} + +func Select(attributes interface{}) string { + values := toArray(attributes) + return parseQuery(queryOptions{ + Method: "select", + Values: &values, + }) +} + +func OrderAsc(attribute string) string { + return parseQuery(queryOptions{ + Method: "orderAsc", + Attribute: &attribute, + }) +} + +func OrderDesc(attribute string) string { + return parseQuery(queryOptions{ + Method: "orderDesc", + Attribute: &attribute, + })} + +func CursorBefore(documentId interface{}) string { + values := toArray(documentId) + return parseQuery(queryOptions{ + Method: "cursorBefore", + Values: &values, + }) +} + +func CursorAfter(documentId string) string { + values := toArray(documentId) + return parseQuery(queryOptions{ + Method: "cursorAfter", + Values: &values, + }) +} + +func Limit(limit int) string { + values := toArray(limit) + return parseQuery(queryOptions{ + Method: "limit", + Values: &values, + }) +} + +func Offset(offset int) string { + values := toArray(offset) + return parseQuery(queryOptions{ + Method: "offset", + Values: &values, + }) +} + +func Or(queries []string) string { + var parsedQueries []interface{} + for _, query := range queries { + var q interface{} + if err := json.Unmarshal([]byte(query), &q); err != nil { + // Handle error, possibly log it or return an empty result + continue + } + parsedQueries = append(parsedQueries, q) + } + return parseQuery(queryOptions{ + Method: "or", + Values: &parsedQueries, + }) +} + +func And(queries []string) string { + var parsedQueries []interface{} + for _, query := range queries { + var q interface{} + if err := json.Unmarshal([]byte(query), &q); err != nil { + // Handle error, possibly log it or return an empty result + continue + } + parsedQueries = append(parsedQueries, q) + } + return parseQuery(queryOptions{ + Method: "and", + Values: &parsedQueries, + }) +} \ No newline at end of file diff --git a/role/role.go b/role/role.go new file mode 100644 index 0000000..3ef4f91 --- /dev/null +++ b/role/role.go @@ -0,0 +1,42 @@ +package role + +import ( + "fmt" +) + +func Any() string { + return "any" +} + +func User(id, status string) string { + if status != "" { + return fmt.Sprintf("user:%s/%s", id, status) + } + return fmt.Sprintf("user:%s", id) +} + +func Users(status string) string{ + if status != "" { + return fmt.Sprintf("users/%s", status) + } + return "users" +} + +func Guests() string { + return "guests" +} + +func Team(id, role string) string { + if role != "" { + return fmt.Sprintf("team:%s/%s", id, role) + } + return fmt.Sprintf("team:%s", id) +} + +func Member(id string) string { + return fmt.Sprintf("member:%s", id) +} + +func Label(id string) string { + return fmt.Sprintf("label:%s", id) +} diff --git a/storage/storage.go b/storage/storage.go new file mode 100644 index 0000000..1accd13 --- /dev/null +++ b/storage/storage.go @@ -0,0 +1,926 @@ +package storage + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "github.com/appwrite/sdk-for-go/file" + "strings" +) + +// Storage service +type Storage struct { + client client.Client +} + +func NewStorage(clt client.Client) *Storage { + return &Storage{ + client: clt, + } +} + + +type ListBucketsOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListBucketsOptions) New() *ListBucketsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListBucketsOption func(*ListBucketsOptions) +func WithListBucketsQueries(v []interface{}) ListBucketsOption { + return func(o *ListBucketsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListBucketsSearch(v string) ListBucketsOption { + return func(o *ListBucketsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListBuckets get a list of all the storage buckets. You can use the query +// params to filter your results. +func (srv *Storage) ListBuckets(optionalSetters ...ListBucketsOption)(*models.BucketList, error) { + path := "/storage/buckets" + options := ListBucketsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.BucketList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.BucketList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateBucketOptions struct { + Permissions []interface{} + FileSecurity bool + Enabled bool + MaximumFileSize int + AllowedFileExtensions []interface{} + Compression string + Encryption bool + Antivirus bool + enabledSetters map[string]bool +} +func (options CreateBucketOptions) New() *CreateBucketOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "FileSecurity": false, + "Enabled": false, + "MaximumFileSize": false, + "AllowedFileExtensions": false, + "Compression": false, + "Encryption": false, + "Antivirus": false, + } + return &options +} +type CreateBucketOption func(*CreateBucketOptions) +func WithCreateBucketPermissions(v []interface{}) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func WithCreateBucketFileSecurity(v bool) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.FileSecurity = v + o.enabledSetters["FileSecurity"] = true + } +} +func WithCreateBucketEnabled(v bool) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithCreateBucketMaximumFileSize(v int) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.MaximumFileSize = v + o.enabledSetters["MaximumFileSize"] = true + } +} +func WithCreateBucketAllowedFileExtensions(v []interface{}) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.AllowedFileExtensions = v + o.enabledSetters["AllowedFileExtensions"] = true + } +} +func WithCreateBucketCompression(v string) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.Compression = v + o.enabledSetters["Compression"] = true + } +} +func WithCreateBucketEncryption(v bool) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.Encryption = v + o.enabledSetters["Encryption"] = true + } +} +func WithCreateBucketAntivirus(v bool) CreateBucketOption { + return func(o *CreateBucketOptions) { + o.Antivirus = v + o.enabledSetters["Antivirus"] = true + } +} + +// CreateBucket create a new storage bucket. +func (srv *Storage) CreateBucket(BucketId string, Name string, optionalSetters ...CreateBucketOption)(*models.Bucket, error) { + path := "/storage/buckets" + options := CreateBucketOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["name"] = Name + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["FileSecurity"] { + params["fileSecurity"] = options.FileSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["MaximumFileSize"] { + params["maximumFileSize"] = options.MaximumFileSize + } + if options.enabledSetters["AllowedFileExtensions"] { + params["allowedFileExtensions"] = options.AllowedFileExtensions + } + if options.enabledSetters["Compression"] { + params["compression"] = options.Compression + } + if options.enabledSetters["Encryption"] { + params["encryption"] = options.Encryption + } + if options.enabledSetters["Antivirus"] { + params["antivirus"] = options.Antivirus + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Bucket + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Bucket) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetBucket get a storage bucket by its unique ID. This endpoint response +// returns a JSON object with the storage bucket metadata. +func (srv *Storage) GetBucket(BucketId string)(*models.Bucket, error) { + r := strings.NewReplacer("{bucketId}", BucketId) + path := r.Replace("/storage/buckets/{bucketId}") + params := map[string]interface{}{} + params["bucketId"] = BucketId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Bucket + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Bucket) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateBucketOptions struct { + Permissions []interface{} + FileSecurity bool + Enabled bool + MaximumFileSize int + AllowedFileExtensions []interface{} + Compression string + Encryption bool + Antivirus bool + enabledSetters map[string]bool +} +func (options UpdateBucketOptions) New() *UpdateBucketOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "FileSecurity": false, + "Enabled": false, + "MaximumFileSize": false, + "AllowedFileExtensions": false, + "Compression": false, + "Encryption": false, + "Antivirus": false, + } + return &options +} +type UpdateBucketOption func(*UpdateBucketOptions) +func WithUpdateBucketPermissions(v []interface{}) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func WithUpdateBucketFileSecurity(v bool) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.FileSecurity = v + o.enabledSetters["FileSecurity"] = true + } +} +func WithUpdateBucketEnabled(v bool) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func WithUpdateBucketMaximumFileSize(v int) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.MaximumFileSize = v + o.enabledSetters["MaximumFileSize"] = true + } +} +func WithUpdateBucketAllowedFileExtensions(v []interface{}) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.AllowedFileExtensions = v + o.enabledSetters["AllowedFileExtensions"] = true + } +} +func WithUpdateBucketCompression(v string) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.Compression = v + o.enabledSetters["Compression"] = true + } +} +func WithUpdateBucketEncryption(v bool) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.Encryption = v + o.enabledSetters["Encryption"] = true + } +} +func WithUpdateBucketAntivirus(v bool) UpdateBucketOption { + return func(o *UpdateBucketOptions) { + o.Antivirus = v + o.enabledSetters["Antivirus"] = true + } +} + +// UpdateBucket update a storage bucket by its unique ID. +func (srv *Storage) UpdateBucket(BucketId string, Name string, optionalSetters ...UpdateBucketOption)(*models.Bucket, error) { + r := strings.NewReplacer("{bucketId}", BucketId) + path := r.Replace("/storage/buckets/{bucketId}") + options := UpdateBucketOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["name"] = Name + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["FileSecurity"] { + params["fileSecurity"] = options.FileSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["MaximumFileSize"] { + params["maximumFileSize"] = options.MaximumFileSize + } + if options.enabledSetters["AllowedFileExtensions"] { + params["allowedFileExtensions"] = options.AllowedFileExtensions + } + if options.enabledSetters["Compression"] { + params["compression"] = options.Compression + } + if options.enabledSetters["Encryption"] { + params["encryption"] = options.Encryption + } + if options.enabledSetters["Antivirus"] { + params["antivirus"] = options.Antivirus + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Bucket + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Bucket) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteBucket delete a storage bucket by its unique ID. +func (srv *Storage) DeleteBucket(BucketId string)(*interface{}, error) { + r := strings.NewReplacer("{bucketId}", BucketId) + path := r.Replace("/storage/buckets/{bucketId}") + params := map[string]interface{}{} + params["bucketId"] = BucketId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListFilesOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListFilesOptions) New() *ListFilesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListFilesOption func(*ListFilesOptions) +func WithListFilesQueries(v []interface{}) ListFilesOption { + return func(o *ListFilesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListFilesSearch(v string) ListFilesOption { + return func(o *ListFilesOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListFiles get a list of all the user files. You can use the query params to +// filter your results. +func (srv *Storage) ListFiles(BucketId string, optionalSetters ...ListFilesOption)(*models.FileList, error) { + r := strings.NewReplacer("{bucketId}", BucketId) + path := r.Replace("/storage/buckets/{bucketId}/files") + options := ListFilesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["bucketId"] = BucketId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.FileList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.FileList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateFileOptions struct { + Permissions []interface{} + enabledSetters map[string]bool +} +func (options CreateFileOptions) New() *CreateFileOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + } + return &options +} +type CreateFileOption func(*CreateFileOptions) +func WithCreateFilePermissions(v []interface{}) CreateFileOption { + return func(o *CreateFileOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} + +// CreateFile create a new file. Before using this route, you should create a +// new bucket resource using either a [server +// integration](https://appwrite.io/docs/server/storage#storageCreateBucket) +// API or directly from your Appwrite console. +// +// Larger files should be uploaded using multiple requests with the +// [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) +// header to send a partial request with a maximum supported chunk of `5MB`. +// The `content-range` header values should always be in bytes. +// +// When the first request is sent, the server will return the **File** object, +// and the subsequent part request must include the file's **id** in +// `x-appwrite-id` header to allow the server to know that the partial upload +// is for the existing file and not for a new one. +// +// If you're creating a new file using one of the Appwrite SDKs, all the +// chunking logic will be managed by the SDK internally. +func (srv *Storage) CreateFile(BucketId string, FileId string, File file.InputFile, optionalSetters ...CreateFileOption)(*models.File, error) { + r := strings.NewReplacer("{bucketId}", BucketId) + path := r.Replace("/storage/buckets/{bucketId}/files") + options := CreateFileOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + params["file"] = File + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + headers := map[string]interface{}{ + "content-type": "multipart/form-data", + } + + paramName := "file" + + + uploadId := "" + uploadId = FileId + + resp, err := srv.client.FileUpload(path, headers, params, paramName, uploadId) + if err != nil { + return nil, err + } + var parsed models.File + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.File) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil +} + +// GetFile get a file by its unique ID. This endpoint response returns a JSON +// object with the file metadata. +func (srv *Storage) GetFile(BucketId string, FileId string)(*models.File, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}") + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.File + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.File) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateFileOptions struct { + Name string + Permissions []interface{} + enabledSetters map[string]bool +} +func (options UpdateFileOptions) New() *UpdateFileOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + "Permissions": false, + } + return &options +} +type UpdateFileOption func(*UpdateFileOptions) +func WithUpdateFileName(v string) UpdateFileOption { + return func(o *UpdateFileOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} +func WithUpdateFilePermissions(v []interface{}) UpdateFileOption { + return func(o *UpdateFileOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} + +// UpdateFile update a file by its unique ID. Only users with write +// permissions have access to update this resource. +func (srv *Storage) UpdateFile(BucketId string, FileId string, optionalSetters ...UpdateFileOption)(*models.File, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}") + options := UpdateFileOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.File + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.File) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteFile delete a file by its unique ID. Only users with write +// permissions have access to delete this resource. +func (srv *Storage) DeleteFile(BucketId string, FileId string)(*interface{}, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}") + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetFileDownload get a file content by its unique ID. The endpoint response +// return with a 'Content-Disposition: attachment' header that tells the +// browser to start downloading the file to user downloads directory. +func (srv *Storage) GetFileDownload(BucketId string, FileId string)(*[]byte, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}/download") + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type GetFilePreviewOptions struct { + Width int + Height int + Gravity string + Quality int + BorderWidth int + BorderColor string + BorderRadius int + Opacity float64 + Rotation int + Background string + Output string + enabledSetters map[string]bool +} +func (options GetFilePreviewOptions) New() *GetFilePreviewOptions { + options.enabledSetters = map[string]bool{ + "Width": false, + "Height": false, + "Gravity": false, + "Quality": false, + "BorderWidth": false, + "BorderColor": false, + "BorderRadius": false, + "Opacity": false, + "Rotation": false, + "Background": false, + "Output": false, + } + return &options +} +type GetFilePreviewOption func(*GetFilePreviewOptions) +func WithGetFilePreviewWidth(v int) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Width = v + o.enabledSetters["Width"] = true + } +} +func WithGetFilePreviewHeight(v int) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Height = v + o.enabledSetters["Height"] = true + } +} +func WithGetFilePreviewGravity(v string) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Gravity = v + o.enabledSetters["Gravity"] = true + } +} +func WithGetFilePreviewQuality(v int) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Quality = v + o.enabledSetters["Quality"] = true + } +} +func WithGetFilePreviewBorderWidth(v int) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.BorderWidth = v + o.enabledSetters["BorderWidth"] = true + } +} +func WithGetFilePreviewBorderColor(v string) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.BorderColor = v + o.enabledSetters["BorderColor"] = true + } +} +func WithGetFilePreviewBorderRadius(v int) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.BorderRadius = v + o.enabledSetters["BorderRadius"] = true + } +} +func WithGetFilePreviewOpacity(v float64) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Opacity = v + o.enabledSetters["Opacity"] = true + } +} +func WithGetFilePreviewRotation(v int) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Rotation = v + o.enabledSetters["Rotation"] = true + } +} +func WithGetFilePreviewBackground(v string) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Background = v + o.enabledSetters["Background"] = true + } +} +func WithGetFilePreviewOutput(v string) GetFilePreviewOption { + return func(o *GetFilePreviewOptions) { + o.Output = v + o.enabledSetters["Output"] = true + } +} + +// GetFilePreview get a file preview image. Currently, this method supports +// preview for image files (jpg, png, and gif), other supported formats, like +// pdf, docs, slides, and spreadsheets, will return the file icon image. You +// can also pass query string arguments for cutting and resizing your preview +// image. Preview is supported only for image files smaller than 10MB. +func (srv *Storage) GetFilePreview(BucketId string, FileId string, optionalSetters ...GetFilePreviewOption)(*[]byte, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}/preview") + options := GetFilePreviewOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + if options.enabledSetters["Width"] { + params["width"] = options.Width + } + if options.enabledSetters["Height"] { + params["height"] = options.Height + } + if options.enabledSetters["Gravity"] { + params["gravity"] = options.Gravity + } + if options.enabledSetters["Quality"] { + params["quality"] = options.Quality + } + if options.enabledSetters["BorderWidth"] { + params["borderWidth"] = options.BorderWidth + } + if options.enabledSetters["BorderColor"] { + params["borderColor"] = options.BorderColor + } + if options.enabledSetters["BorderRadius"] { + params["borderRadius"] = options.BorderRadius + } + if options.enabledSetters["Opacity"] { + params["opacity"] = options.Opacity + } + if options.enabledSetters["Rotation"] { + params["rotation"] = options.Rotation + } + if options.enabledSetters["Background"] { + params["background"] = options.Background + } + if options.enabledSetters["Output"] { + params["output"] = options.Output + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetFileView get a file content by its unique ID. This endpoint is similar +// to the download method but returns with no 'Content-Disposition: +// attachment' header. +func (srv *Storage) GetFileView(BucketId string, FileId string)(*[]byte, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}/view") + params := map[string]interface{}{} + params["bucketId"] = BucketId + params["fileId"] = FileId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed []byte + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.([]byte) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/teams/teams.go b/teams/teams.go new file mode 100644 index 0000000..6201a61 --- /dev/null +++ b/teams/teams.go @@ -0,0 +1,625 @@ +package teams + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Teams service +type Teams struct { + client client.Client +} + +func NewTeams(clt client.Client) *Teams { + return &Teams{ + client: clt, + } +} + + +type ListOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListOption func(*ListOptions) +func WithListQueries(v []interface{}) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListSearch(v string) ListOption { + return func(o *ListOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// List get a list of all the teams in which the current user is a member. You +// can use the parameters to filter your results. +func (srv *Teams) List(optionalSetters ...ListOption)(*models.TeamList, error) { + path := "/teams" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.TeamList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.TeamList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateOptions struct { + Roles []interface{} + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Roles": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func WithCreateRoles(v []interface{}) CreateOption { + return func(o *CreateOptions) { + o.Roles = v + o.enabledSetters["Roles"] = true + } +} + +// Create create a new team. The user who creates the team will automatically +// be assigned as the owner of the team. Only the users with the owner role +// can invite new members, add new owners and delete or update the team. +func (srv *Teams) Create(TeamId string, Name string, optionalSetters ...CreateOption)(*models.Team, error) { + path := "/teams" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["teamId"] = TeamId + params["name"] = Name + if options.enabledSetters["Roles"] { + params["roles"] = options.Roles + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Team + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Team) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a team by its ID. All team members have read access for this +// resource. +func (srv *Teams) Get(TeamId string)(*models.Team, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}") + params := map[string]interface{}{} + params["teamId"] = TeamId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Team + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Team) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateName update the team's name by its unique ID. +func (srv *Teams) UpdateName(TeamId string, Name string)(*models.Team, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}") + params := map[string]interface{}{} + params["teamId"] = TeamId + params["name"] = Name + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Team + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Team) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a team using its ID. Only team members with the owner role +// can delete the team. +func (srv *Teams) Delete(TeamId string)(*interface{}, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}") + params := map[string]interface{}{} + params["teamId"] = TeamId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListMembershipsOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListMembershipsOptions) New() *ListMembershipsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListMembershipsOption func(*ListMembershipsOptions) +func WithListMembershipsQueries(v []interface{}) ListMembershipsOption { + return func(o *ListMembershipsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListMembershipsSearch(v string) ListMembershipsOption { + return func(o *ListMembershipsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListMemberships use this endpoint to list a team's members using the team's +// ID. All team members have read access to this endpoint. +func (srv *Teams) ListMemberships(TeamId string, optionalSetters ...ListMembershipsOption)(*models.MembershipList, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}/memberships") + options := ListMembershipsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["teamId"] = TeamId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MembershipList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MembershipList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateMembershipOptions struct { + Email string + UserId string + Phone string + Url string + Name string + enabledSetters map[string]bool +} +func (options CreateMembershipOptions) New() *CreateMembershipOptions { + options.enabledSetters = map[string]bool{ + "Email": false, + "UserId": false, + "Phone": false, + "Url": false, + "Name": false, + } + return &options +} +type CreateMembershipOption func(*CreateMembershipOptions) +func WithCreateMembershipEmail(v string) CreateMembershipOption { + return func(o *CreateMembershipOptions) { + o.Email = v + o.enabledSetters["Email"] = true + } +} +func WithCreateMembershipUserId(v string) CreateMembershipOption { + return func(o *CreateMembershipOptions) { + o.UserId = v + o.enabledSetters["UserId"] = true + } +} +func WithCreateMembershipPhone(v string) CreateMembershipOption { + return func(o *CreateMembershipOptions) { + o.Phone = v + o.enabledSetters["Phone"] = true + } +} +func WithCreateMembershipUrl(v string) CreateMembershipOption { + return func(o *CreateMembershipOptions) { + o.Url = v + o.enabledSetters["Url"] = true + } +} +func WithCreateMembershipName(v string) CreateMembershipOption { + return func(o *CreateMembershipOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateMembership invite a new member to join your team. Provide an ID for +// existing users, or invite unregistered users using an email or phone +// number. If initiated from a Client SDK, Appwrite will send an email or sms +// with a link to join the team to the invited user, and an account will be +// created for them if one doesn't exist. If initiated from a Server SDK, the +// new member will be added automatically to the team. +// +// You only need to provide one of a user ID, email, or phone number. Appwrite +// will prioritize accepting the user ID > email > phone number if you provide +// more than one of these parameters. +// +// Use the `url` parameter to redirect the user from the invitation email to +// your app. After the user is redirected, use the [Update Team Membership +// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) +// endpoint to allow the user to accept the invitation to the team. +// +// Please note that to avoid a [Redirect +// Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) +// Appwrite will accept the only redirect URLs under the domains you have +// added as a platform on the Appwrite Console. +func (srv *Teams) CreateMembership(TeamId string, Roles []interface{}, optionalSetters ...CreateMembershipOption)(*models.Membership, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}/memberships") + options := CreateMembershipOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["teamId"] = TeamId + params["roles"] = Roles + if options.enabledSetters["Email"] { + params["email"] = options.Email + } + if options.enabledSetters["UserId"] { + params["userId"] = options.UserId + } + if options.enabledSetters["Phone"] { + params["phone"] = options.Phone + } + if options.enabledSetters["Url"] { + params["url"] = options.Url + } + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Membership + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Membership) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetMembership get a team member by the membership unique id. All team +// members have read access for this resource. +func (srv *Teams) GetMembership(TeamId string, MembershipId string)(*models.Membership, error) { + r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId) + path := r.Replace("/teams/{teamId}/memberships/{membershipId}") + params := map[string]interface{}{} + params["teamId"] = TeamId + params["membershipId"] = MembershipId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Membership + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Membership) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMembership modify the roles of a team member. Only team members with +// the owner role have access to this endpoint. Learn more about [roles and +// permissions](https://appwrite.io/docs/permissions). +func (srv *Teams) UpdateMembership(TeamId string, MembershipId string, Roles []interface{})(*models.Membership, error) { + r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId) + path := r.Replace("/teams/{teamId}/memberships/{membershipId}") + params := map[string]interface{}{} + params["teamId"] = TeamId + params["membershipId"] = MembershipId + params["roles"] = Roles + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Membership + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Membership) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteMembership this endpoint allows a user to leave a team or for a team +// owner to delete the membership of any other team member. You can also use +// this endpoint to delete a user membership even if it is not accepted. +func (srv *Teams) DeleteMembership(TeamId string, MembershipId string)(*interface{}, error) { + r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId) + path := r.Replace("/teams/{teamId}/memberships/{membershipId}") + params := map[string]interface{}{} + params["teamId"] = TeamId + params["membershipId"] = MembershipId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMembershipStatus use this endpoint to allow a user to accept an +// invitation to join a team after being redirected back to your app from the +// invitation email received by the user. +// +// If the request is successful, a session for the user is automatically +// created. +func (srv *Teams) UpdateMembershipStatus(TeamId string, MembershipId string, UserId string, Secret string)(*models.Membership, error) { + r := strings.NewReplacer("{teamId}", TeamId, "{membershipId}", MembershipId) + path := r.Replace("/teams/{teamId}/memberships/{membershipId}/status") + params := map[string]interface{}{} + params["teamId"] = TeamId + params["membershipId"] = MembershipId + params["userId"] = UserId + params["secret"] = Secret + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Membership + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Membership) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPrefs get the team's shared preferences by its unique ID. If a +// preference doesn't need to be shared by all team members, prefer storing +// them in [user +// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). +func (srv *Teams) GetPrefs(TeamId string)(*models.Preferences, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}/prefs") + params := map[string]interface{}{} + params["teamId"] = TeamId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Preferences + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Preferences) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePrefs update the team's preferences by its unique ID. The object you +// pass is stored as is and replaces any previous value. The maximum allowed +// prefs size is 64kB and throws an error if exceeded. +func (srv *Teams) UpdatePrefs(TeamId string, Prefs interface{})(*models.Preferences, error) { + r := strings.NewReplacer("{teamId}", TeamId) + path := r.Replace("/teams/{teamId}/prefs") + params := map[string]interface{}{} + params["teamId"] = TeamId + params["prefs"] = Prefs + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Preferences + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Preferences) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/users/users.go b/users/users.go new file mode 100644 index 0000000..ef79a6b --- /dev/null +++ b/users/users.go @@ -0,0 +1,1892 @@ +package users + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Users service +type Users struct { + client client.Client +} + +func NewUsers(clt client.Client) *Users { + return &Users{ + client: clt, + } +} + + +type ListOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListOption func(*ListOptions) +func WithListQueries(v []interface{}) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListSearch(v string) ListOption { + return func(o *ListOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// List get a list of all the project's users. You can use the query params to +// filter your results. +func (srv *Users) List(optionalSetters ...ListOption)(*models.UserList, error) { + path := "/users" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.UserList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.UserList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateOptions struct { + Email string + Phone string + Password string + Name string + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Email": false, + "Phone": false, + "Password": false, + "Name": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func WithCreateEmail(v string) CreateOption { + return func(o *CreateOptions) { + o.Email = v + o.enabledSetters["Email"] = true + } +} +func WithCreatePhone(v string) CreateOption { + return func(o *CreateOptions) { + o.Phone = v + o.enabledSetters["Phone"] = true + } +} +func WithCreatePassword(v string) CreateOption { + return func(o *CreateOptions) { + o.Password = v + o.enabledSetters["Password"] = true + } +} +func WithCreateName(v string) CreateOption { + return func(o *CreateOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// Create create a new user. +func (srv *Users) Create(UserId string, optionalSetters ...CreateOption)(*models.User, error) { + path := "/users" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + if options.enabledSetters["Email"] { + params["email"] = options.Email + } + if options.enabledSetters["Phone"] { + params["phone"] = options.Phone + } + if options.enabledSetters["Password"] { + params["password"] = options.Password + } + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateArgon2UserOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreateArgon2UserOptions) New() *CreateArgon2UserOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreateArgon2UserOption func(*CreateArgon2UserOptions) +func WithCreateArgon2UserName(v string) CreateArgon2UserOption { + return func(o *CreateArgon2UserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateArgon2User create a new user. Password provided must be hashed with +// the [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST +// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to +// create users with a plain text password. +func (srv *Users) CreateArgon2User(UserId string, Email string, Password string, optionalSetters ...CreateArgon2UserOption)(*models.User, error) { + path := "/users/argon2" + options := CreateArgon2UserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateBcryptUserOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreateBcryptUserOptions) New() *CreateBcryptUserOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreateBcryptUserOption func(*CreateBcryptUserOptions) +func WithCreateBcryptUserName(v string) CreateBcryptUserOption { + return func(o *CreateBcryptUserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateBcryptUser create a new user. Password provided must be hashed with +// the [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST +// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to +// create users with a plain text password. +func (srv *Users) CreateBcryptUser(UserId string, Email string, Password string, optionalSetters ...CreateBcryptUserOption)(*models.User, error) { + path := "/users/bcrypt" + options := CreateBcryptUserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListIdentitiesOptions struct { + Queries []interface{} + Search string + enabledSetters map[string]bool +} +func (options ListIdentitiesOptions) New() *ListIdentitiesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + } + return &options +} +type ListIdentitiesOption func(*ListIdentitiesOptions) +func WithListIdentitiesQueries(v []interface{}) ListIdentitiesOption { + return func(o *ListIdentitiesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func WithListIdentitiesSearch(v string) ListIdentitiesOption { + return func(o *ListIdentitiesOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} + +// ListIdentities get identities for all users. +func (srv *Users) ListIdentities(optionalSetters ...ListIdentitiesOption)(*models.IdentityList, error) { + path := "/users/identities" + options := ListIdentitiesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.IdentityList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.IdentityList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteIdentity delete an identity by its unique ID. +func (srv *Users) DeleteIdentity(IdentityId string)(*interface{}, error) { + r := strings.NewReplacer("{identityId}", IdentityId) + path := r.Replace("/users/identities/{identityId}") + params := map[string]interface{}{} + params["identityId"] = IdentityId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateMD5UserOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreateMD5UserOptions) New() *CreateMD5UserOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreateMD5UserOption func(*CreateMD5UserOptions) +func WithCreateMD5UserName(v string) CreateMD5UserOption { + return func(o *CreateMD5UserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateMD5User create a new user. Password provided must be hashed with the +// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST +// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to +// create users with a plain text password. +func (srv *Users) CreateMD5User(UserId string, Email string, Password string, optionalSetters ...CreateMD5UserOption)(*models.User, error) { + path := "/users/md5" + options := CreateMD5UserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreatePHPassUserOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreatePHPassUserOptions) New() *CreatePHPassUserOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreatePHPassUserOption func(*CreatePHPassUserOptions) +func WithCreatePHPassUserName(v string) CreatePHPassUserOption { + return func(o *CreatePHPassUserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreatePHPassUser create a new user. Password provided must be hashed with +// the [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST +// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to +// create users with a plain text password. +func (srv *Users) CreatePHPassUser(UserId string, Email string, Password string, optionalSetters ...CreatePHPassUserOption)(*models.User, error) { + path := "/users/phpass" + options := CreatePHPassUserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateScryptUserOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreateScryptUserOptions) New() *CreateScryptUserOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreateScryptUserOption func(*CreateScryptUserOptions) +func WithCreateScryptUserName(v string) CreateScryptUserOption { + return func(o *CreateScryptUserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateScryptUser create a new user. Password provided must be hashed with +// the [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST +// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to +// create users with a plain text password. +func (srv *Users) CreateScryptUser(UserId string, Email string, Password string, PasswordSalt string, PasswordCpu int, PasswordMemory int, PasswordParallel int, PasswordLength int, optionalSetters ...CreateScryptUserOption)(*models.User, error) { + path := "/users/scrypt" + options := CreateScryptUserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + params["passwordSalt"] = PasswordSalt + params["passwordCpu"] = PasswordCpu + params["passwordMemory"] = PasswordMemory + params["passwordParallel"] = PasswordParallel + params["passwordLength"] = PasswordLength + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateScryptModifiedUserOptions struct { + Name string + enabledSetters map[string]bool +} +func (options CreateScryptModifiedUserOptions) New() *CreateScryptModifiedUserOptions { + options.enabledSetters = map[string]bool{ + "Name": false, + } + return &options +} +type CreateScryptModifiedUserOption func(*CreateScryptModifiedUserOptions) +func WithCreateScryptModifiedUserName(v string) CreateScryptModifiedUserOption { + return func(o *CreateScryptModifiedUserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateScryptModifiedUser create a new user. Password provided must be +// hashed with the [Scrypt +// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) +// algorithm. Use the [POST +// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to +// create users with a plain text password. +func (srv *Users) CreateScryptModifiedUser(UserId string, Email string, Password string, PasswordSalt string, PasswordSaltSeparator string, PasswordSignerKey string, optionalSetters ...CreateScryptModifiedUserOption)(*models.User, error) { + path := "/users/scrypt-modified" + options := CreateScryptModifiedUserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + params["passwordSalt"] = PasswordSalt + params["passwordSaltSeparator"] = PasswordSaltSeparator + params["passwordSignerKey"] = PasswordSignerKey + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateSHAUserOptions struct { + PasswordVersion string + Name string + enabledSetters map[string]bool +} +func (options CreateSHAUserOptions) New() *CreateSHAUserOptions { + options.enabledSetters = map[string]bool{ + "PasswordVersion": false, + "Name": false, + } + return &options +} +type CreateSHAUserOption func(*CreateSHAUserOptions) +func WithCreateSHAUserPasswordVersion(v string) CreateSHAUserOption { + return func(o *CreateSHAUserOptions) { + o.PasswordVersion = v + o.enabledSetters["PasswordVersion"] = true + } +} +func WithCreateSHAUserName(v string) CreateSHAUserOption { + return func(o *CreateSHAUserOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateSHAUser create a new user. Password provided must be hashed with the +// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use +// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) +// endpoint to create users with a plain text password. +func (srv *Users) CreateSHAUser(UserId string, Email string, Password string, optionalSetters ...CreateSHAUserOption)(*models.User, error) { + path := "/users/sha" + options := CreateSHAUserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + params["password"] = Password + if options.enabledSetters["PasswordVersion"] { + params["passwordVersion"] = options.PasswordVersion + } + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a user by its unique ID. +func (srv *Users) Get(UserId string)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a user by its unique ID, thereby releasing it's ID. Since ID +// is released and can be reused, all user-related resources like documents or +// storage files should be deleted before user deletion. If you want to keep +// ID reserved, use the +// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) +// endpoint instead. +func (srv *Users) Delete(UserId string)(*interface{}, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateEmail update the user email by its unique ID. +func (srv *Users) UpdateEmail(UserId string, Email string)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/email") + params := map[string]interface{}{} + params["userId"] = UserId + params["email"] = Email + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateJWTOptions struct { + SessionId string + Duration int + enabledSetters map[string]bool +} +func (options CreateJWTOptions) New() *CreateJWTOptions { + options.enabledSetters = map[string]bool{ + "SessionId": false, + "Duration": false, + } + return &options +} +type CreateJWTOption func(*CreateJWTOptions) +func WithCreateJWTSessionId(v string) CreateJWTOption { + return func(o *CreateJWTOptions) { + o.SessionId = v + o.enabledSetters["SessionId"] = true + } +} +func 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 for user by its +// unique ID. You can use the resulting JWT to authenticate on behalf of the +// user. The JWT secret will become invalid if the session it uses gets +// deleted. +func (srv *Users) CreateJWT(UserId string, optionalSetters ...CreateJWTOption)(*models.Jwt, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/jwts") + options := CreateJWTOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + if options.enabledSetters["SessionId"] { + params["sessionId"] = options.SessionId + } + if options.enabledSetters["Duration"] { + params["duration"] = options.Duration + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Jwt + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Jwt) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateLabels update the user labels by its unique ID. +// +// Labels can be used to grant access to resources. While teams are a way for +// user's to share access to a resource, labels can be defined by the +// developer to grant access without an invitation. See the [Permissions +// docs](https://appwrite.io/docs/permissions) for more info. +func (srv *Users) UpdateLabels(UserId string, Labels []interface{})(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/labels") + params := map[string]interface{}{} + params["userId"] = UserId + params["labels"] = Labels + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListLogsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListLogsOptions) New() *ListLogsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListLogsOption func(*ListLogsOptions) +func WithListLogsQueries(v []interface{}) ListLogsOption { + return func(o *ListLogsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListLogs get the user activity logs list by its unique ID. +func (srv *Users) ListLogs(UserId string, optionalSetters ...ListLogsOption)(*models.LogList, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/logs") + options := ListLogsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.LogList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.LogList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListMemberships get the user membership list by its unique ID. +func (srv *Users) ListMemberships(UserId string)(*models.MembershipList, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/memberships") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MembershipList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MembershipList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMfa enable or disable MFA on a user account. +func (srv *Users) UpdateMfa(UserId string, Mfa bool)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/mfa") + params := map[string]interface{}{} + params["userId"] = UserId + params["mfa"] = Mfa + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteMfaAuthenticator delete an authenticator app. +func (srv *Users) DeleteMfaAuthenticator(UserId string, Type string)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId, "{type}", Type) + path := r.Replace("/users/{userId}/mfa/authenticators/{type}") + params := map[string]interface{}{} + params["userId"] = UserId + params["type"] = Type + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListMfaFactors list the factors available on the account to be used as a +// MFA challange. +func (srv *Users) ListMfaFactors(UserId string)(*models.MfaFactors, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/mfa/factors") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaFactors + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaFactors) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetMfaRecoveryCodes get recovery codes that can be used as backup for MFA +// flow by User ID. Before getting codes, they must be generated using +// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) +// method. +func (srv *Users) GetMfaRecoveryCodes(UserId string)(*models.MfaRecoveryCodes, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/mfa/recovery-codes") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaRecoveryCodes + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaRecoveryCodes) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateMfaRecoveryCodes regenerate recovery codes that can be used as backup +// for MFA flow by User ID. Before regenerating codes, they must be first +// generated using +// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) +// method. +func (srv *Users) UpdateMfaRecoveryCodes(UserId string)(*models.MfaRecoveryCodes, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/mfa/recovery-codes") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaRecoveryCodes + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaRecoveryCodes) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateMfaRecoveryCodes generate recovery codes used as backup for MFA flow +// for User ID. Recovery codes can be used as a MFA verification type in +// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) +// method by client SDK. +func (srv *Users) CreateMfaRecoveryCodes(UserId string)(*models.MfaRecoveryCodes, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/mfa/recovery-codes") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.MfaRecoveryCodes + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.MfaRecoveryCodes) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateName update the user name by its unique ID. +func (srv *Users) UpdateName(UserId string, Name string)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/name") + params := map[string]interface{}{} + params["userId"] = UserId + params["name"] = Name + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePassword update the user password by its unique ID. +func (srv *Users) UpdatePassword(UserId string, Password string)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/password") + params := map[string]interface{}{} + params["userId"] = UserId + params["password"] = Password + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePhone update the user phone by its unique ID. +func (srv *Users) UpdatePhone(UserId string, Number string)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/phone") + params := map[string]interface{}{} + params["userId"] = UserId + params["number"] = Number + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPrefs get the user preferences by its unique ID. +func (srv *Users) GetPrefs(UserId string)(*models.Preferences, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/prefs") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Preferences + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Preferences) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePrefs update the user preferences by its unique ID. The object you +// pass is stored as is, and replaces any previous value. The maximum allowed +// prefs size is 64kB and throws error if exceeded. +func (srv *Users) UpdatePrefs(UserId string, Prefs interface{})(*models.Preferences, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/prefs") + params := map[string]interface{}{} + params["userId"] = UserId + params["prefs"] = Prefs + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Preferences + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Preferences) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// ListSessions get the user sessions list by its unique ID. +func (srv *Users) ListSessions(UserId string)(*models.SessionList, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/sessions") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.SessionList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.SessionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateSession creates a session for a user. Returns an immediately usable +// session object. +// +// If you want to generate a token for a custom authentication flow, use the +// [POST +// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) +// endpoint. +func (srv *Users) CreateSession(UserId string)(*models.Session, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/sessions") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Session + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Session) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteSessions delete all user's sessions by using the user's unique ID. +func (srv *Users) DeleteSessions(UserId string)(*interface{}, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/sessions") + params := map[string]interface{}{} + params["userId"] = UserId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteSession delete a user sessions by its unique ID. +func (srv *Users) DeleteSession(UserId string, SessionId string)(*interface{}, error) { + r := strings.NewReplacer("{userId}", UserId, "{sessionId}", SessionId) + path := r.Replace("/users/{userId}/sessions/{sessionId}") + params := map[string]interface{}{} + params["userId"] = UserId + params["sessionId"] = SessionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateStatus update the user status by its unique ID. Use this endpoint as +// an alternative to deleting a user if you want to keep user's ID reserved. +func (srv *Users) UpdateStatus(UserId string, Status bool)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/status") + params := map[string]interface{}{} + params["userId"] = UserId + params["status"] = Status + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type ListTargetsOptions struct { + Queries []interface{} + enabledSetters map[string]bool +} +func (options ListTargetsOptions) New() *ListTargetsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListTargetsOption func(*ListTargetsOptions) +func WithListTargetsQueries(v []interface{}) ListTargetsOption { + return func(o *ListTargetsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListTargets list the messaging targets that are associated with a user. +func (srv *Users) ListTargets(UserId string, optionalSetters ...ListTargetsOption)(*models.TargetList, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/targets") + options := ListTargetsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.TargetList + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.TargetList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateTargetOptions struct { + ProviderId string + Name string + enabledSetters map[string]bool +} +func (options CreateTargetOptions) New() *CreateTargetOptions { + options.enabledSetters = map[string]bool{ + "ProviderId": false, + "Name": false, + } + return &options +} +type CreateTargetOption func(*CreateTargetOptions) +func WithCreateTargetProviderId(v string) CreateTargetOption { + return func(o *CreateTargetOptions) { + o.ProviderId = v + o.enabledSetters["ProviderId"] = true + } +} +func WithCreateTargetName(v string) CreateTargetOption { + return func(o *CreateTargetOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// CreateTarget create a messaging target. +func (srv *Users) CreateTarget(UserId string, TargetId string, ProviderType string, Identifier string, optionalSetters ...CreateTargetOption)(*models.Target, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/targets") + options := CreateTargetOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["targetId"] = TargetId + params["providerType"] = ProviderType + params["identifier"] = Identifier + if options.enabledSetters["ProviderId"] { + params["providerId"] = options.ProviderId + } + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Target + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Target) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetTarget get a user's push notification target by ID. +func (srv *Users) GetTarget(UserId string, TargetId string)(*models.Target, error) { + r := strings.NewReplacer("{userId}", UserId, "{targetId}", TargetId) + path := r.Replace("/users/{userId}/targets/{targetId}") + params := map[string]interface{}{} + params["userId"] = UserId + params["targetId"] = TargetId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Target + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Target) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type UpdateTargetOptions struct { + Identifier string + ProviderId string + Name string + enabledSetters map[string]bool +} +func (options UpdateTargetOptions) New() *UpdateTargetOptions { + options.enabledSetters = map[string]bool{ + "Identifier": false, + "ProviderId": false, + "Name": false, + } + return &options +} +type UpdateTargetOption func(*UpdateTargetOptions) +func WithUpdateTargetIdentifier(v string) UpdateTargetOption { + return func(o *UpdateTargetOptions) { + o.Identifier = v + o.enabledSetters["Identifier"] = true + } +} +func WithUpdateTargetProviderId(v string) UpdateTargetOption { + return func(o *UpdateTargetOptions) { + o.ProviderId = v + o.enabledSetters["ProviderId"] = true + } +} +func WithUpdateTargetName(v string) UpdateTargetOption { + return func(o *UpdateTargetOptions) { + o.Name = v + o.enabledSetters["Name"] = true + } +} + +// UpdateTarget update a messaging target. +func (srv *Users) UpdateTarget(UserId string, TargetId string, optionalSetters ...UpdateTargetOption)(*models.Target, error) { + r := strings.NewReplacer("{userId}", UserId, "{targetId}", TargetId) + path := r.Replace("/users/{userId}/targets/{targetId}") + options := UpdateTargetOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + params["targetId"] = TargetId + if options.enabledSetters["Identifier"] { + params["identifier"] = options.Identifier + } + if options.enabledSetters["ProviderId"] { + params["providerId"] = options.ProviderId + } + if options.enabledSetters["Name"] { + params["name"] = options.Name + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.Target + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Target) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteTarget delete a messaging target. +func (srv *Users) DeleteTarget(UserId string, TargetId string)(*interface{}, error) { + r := strings.NewReplacer("{userId}", UserId, "{targetId}", TargetId) + path := r.Replace("/users/{userId}/targets/{targetId}") + params := map[string]interface{}{} + params["userId"] = UserId + params["targetId"] = TargetId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + var parsed interface{} + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +type CreateTokenOptions struct { + Length int + Expire int + enabledSetters map[string]bool +} +func (options CreateTokenOptions) New() *CreateTokenOptions { + options.enabledSetters = map[string]bool{ + "Length": false, + "Expire": false, + } + return &options +} +type CreateTokenOption func(*CreateTokenOptions) +func WithCreateTokenLength(v int) CreateTokenOption { + return func(o *CreateTokenOptions) { + o.Length = v + o.enabledSetters["Length"] = true + } +} +func WithCreateTokenExpire(v int) CreateTokenOption { + return func(o *CreateTokenOptions) { + o.Expire = v + o.enabledSetters["Expire"] = true + } +} + +// CreateToken returns a token with a secret key for creating a session. Use +// the user ID and secret and submit a request to the [PUT +// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) +// endpoint to complete the login process. +func (srv *Users) CreateToken(UserId string, optionalSetters ...CreateTokenOption)(*models.Token, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/tokens") + options := CreateTokenOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["userId"] = UserId + if options.enabledSetters["Length"] { + params["length"] = options.Length + } + 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 + } + var parsed models.Token + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.Token) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateEmailVerification update the user email verification status by its +// unique ID. +func (srv *Users) UpdateEmailVerification(UserId string, EmailVerification bool)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/verification") + params := map[string]interface{}{} + params["userId"] = UserId + params["emailVerification"] = EmailVerification + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePhoneVerification update the user phone verification status by its +// unique ID. +func (srv *Users) UpdatePhoneVerification(UserId string, PhoneVerification bool)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/verification/phone") + params := map[string]interface{}{} + params["userId"] = UserId + params["phoneVerification"] = PhoneVerification + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + var parsed models.User + if strings.HasPrefix(resp.Type, "application/json") { + err = json.Unmarshal([]byte(resp.Result.(string)), &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +}