├── .github └── ISSUE_TEMPLATE │ ├── bug.yaml │ ├── documentation.yaml │ └── feature.yaml ├── .gitignore ├── Dockerfile ├── README.md ├── build.gradle ├── docker-compose.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── nature.jpg ├── settings.gradle └── src └── main └── kotlin └── io └── appwrite └── playgroundforkotlin └── Main.kt /.github/ISSUE_TEMPLATE/bug.yaml: -------------------------------------------------------------------------------- 1 | name: "🐛 Bug Report" 2 | description: "Submit a bug report to help us improve" 3 | title: "🐛 Bug Report: " 4 | labels: [bug] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out our bug report form 🙏 10 | - type: textarea 11 | id: steps-to-reproduce 12 | validations: 13 | required: true 14 | attributes: 15 | label: "👟 Reproduction steps" 16 | description: "How do you trigger this bug? Please walk us through it step by step." 17 | placeholder: "When I ..." 18 | - type: textarea 19 | id: expected-behavior 20 | validations: 21 | required: true 22 | attributes: 23 | label: "👍 Expected behavior" 24 | description: "What did you think would happen?" 25 | placeholder: "It should ..." 26 | - type: textarea 27 | id: actual-behavior 28 | validations: 29 | required: true 30 | attributes: 31 | label: "👎 Actual Behavior" 32 | description: "What did actually happen? Add screenshots, if applicable." 33 | placeholder: "It actually ..." 34 | - type: dropdown 35 | id: appwrite-version 36 | attributes: 37 | label: "🎲 Appwrite version" 38 | description: "What version of Appwrite are you running?" 39 | options: 40 | - Version 0.10.x 41 | - Version 0.9.x 42 | - Version 0.8.x 43 | - Version 0.7.x 44 | - Version 0.6.x 45 | - Different version (specify in environment) 46 | validations: 47 | required: true 48 | - type: dropdown 49 | id: operating-system 50 | attributes: 51 | label: "💻 Operating system" 52 | description: "What OS is your server / device running on?" 53 | options: 54 | - Linux 55 | - MacOS 56 | - Windows 57 | - Something else 58 | validations: 59 | required: true 60 | - type: textarea 61 | id: enviromnemt 62 | validations: 63 | required: false 64 | attributes: 65 | label: "🧱 Your Environment" 66 | description: "Is your environment customized in any way?" 67 | placeholder: "I use Cloudflare for ..." 68 | - type: checkboxes 69 | id: no-duplicate-issues 70 | attributes: 71 | label: "👀 Have you spent some time to check if this issue has been raised before?" 72 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 73 | options: 74 | - label: "I checked and didn't find similar issue" 75 | required: true 76 | - type: checkboxes 77 | id: read-code-of-conduct 78 | attributes: 79 | label: "🏢 Have you read the Code of Conduct?" 80 | options: 81 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 82 | required: true 83 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yaml: -------------------------------------------------------------------------------- 1 | name: "📚 Documentation" 2 | description: "Report an issue related to documentation" 3 | title: "📚 Documentation: " 4 | labels: [documentation] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to make our documentation better 🙏 10 | - type: textarea 11 | id: issue-description 12 | validations: 13 | required: true 14 | attributes: 15 | label: "💭 Description" 16 | description: "A clear and concise description of what the issue is." 17 | placeholder: "Documentation should not ..." 18 | - type: checkboxes 19 | id: no-duplicate-issues 20 | attributes: 21 | label: "👀 Have you spent some time to check if this issue has been raised before?" 22 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 23 | options: 24 | - label: "I checked and didn't find similar issue" 25 | required: true 26 | - type: checkboxes 27 | id: read-code-of-conduct 28 | attributes: 29 | label: "🏢 Have you read the Code of Conduct?" 30 | options: 31 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 32 | required: true 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yaml: -------------------------------------------------------------------------------- 1 | name: 🚀 Feature 2 | description: "Submit a proposal for a new feature" 3 | title: "🚀 Feature: " 4 | labels: [feature] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out our feature request form 🙏 10 | - type: textarea 11 | id: feature-description 12 | validations: 13 | required: true 14 | attributes: 15 | label: "🔖 Feature description" 16 | description: "A clear and concise description of what the feature is." 17 | placeholder: "You should add ..." 18 | - type: textarea 19 | id: pitch 20 | validations: 21 | required: true 22 | attributes: 23 | label: "🎤 Pitch" 24 | description: "Please explain why this feature should be implemented and how it would be used. Add examples, if applicable." 25 | placeholder: "In my use-case, ..." 26 | - type: checkboxes 27 | id: no-duplicate-issues 28 | attributes: 29 | label: "👀 Have you spent some time to check if this issue has been raised before?" 30 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 31 | options: 32 | - label: "I checked and didn't find similar issue" 33 | required: true 34 | - type: checkboxes 35 | id: read-code-of-conduct 36 | attributes: 37 | label: "🏢 Have you read the Code of Conduct?" 38 | options: 39 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 40 | required: true 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:18-jdk-slim 2 | WORKDIR /app 3 | COPY . . 4 | RUN chmod +x gradlew 5 | CMD sh gradlew run -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Playground for Kotlin 2 | 3 | Simple examples that help you get started with Appwrite + Kotlin (=❤️) 4 | 5 | This is Appwrite server side integration with Kotlin. For Android integration please look at our [Android playground](https://github.com/appwrite/playground-for-android) and [Android SDK](https://github.com/appwrite/sdk-for-android) 6 | 7 | ### Work in progress 8 | 9 | Appwrite playground is a simple way to explore the Appwrite API and Appwrite Kotlin SDK. Use the source code of this page to learn how to use different Appwrite Kotlin SDK features. 10 | 11 | ## Get Started 12 | This playground doesn't include any Kotlin best practices, but rather intended to show some of the most simple examples and use cases of using the Appwrite API in your Kotlin application. 13 | 14 | ## System Requirements 15 | * A system with Kotlin 1.4+ or Docker installed. 16 | * An Appwrite instance. 17 | * An Appwrite project created in the console. 18 | * An Appwrite API key created in the console. 19 | 20 | ### Installation 21 | 1. Clone this repository. 22 | 2. `cd` into to repository. 23 | 3. Open the `src/main/kotlin/io/appwrite/playgroundforkotlin/Main.kt` file found in the cloned repository. 24 | 4. Copy your Project ID, endpoint and API key from Appwrite console into `Main.kt` 25 | 5. Run the playground: 26 | Kotlin: 27 | - Execute the command `sh gradlew run` 28 | Docker: 29 | - Execute the command `docker compose up` 30 | 6. You will see the JSON response in the console. 31 | 32 | > When connecting to Appwrite from within Docker, localhost is the hostname for the container and not your local Appwrite instance. You should replace localhost with your private IP as the Appwrite endpoint's hostname. You can also use a service like ngrok to proxy the Appwrite API. 33 | 34 | ### API Covered in Playground: 35 | 36 | - Database 37 | * Create Collection 38 | * List Collections 39 | * Add Document 40 | * List Documents 41 | * Delete Document 42 | * Delete Collection 43 | 44 | - Storage 45 | * Create Bucket 46 | * List Buckets 47 | * Upload File 48 | * List Files 49 | * Delete File 50 | * Delete Bucket 51 | 52 | - Users 53 | * Create User 54 | * List Users 55 | * Delete User 56 | 57 | - Functions 58 | * Create Function 59 | * List Functions 60 | * Delete Function 61 | 62 | ## Contributing 63 | 64 | All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code. 65 | 66 | We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the [contribution guide](https://github.com/appwrite/appwrite/blob/master/CONTRIBUTING.md). 67 | 68 | ## Security 69 | 70 | For security issues, kindly email us [security@appwrite.io](mailto:security@appwrite.io) instead of posting a public issue in GitHub. 71 | 72 | ## Follow Us 73 | 74 | Join our growing community around the world! Follow us on [Twitter](https://twitter.com/appwrite), [Facebook Page](https://www.facebook.com/appwrite.io), [Facebook Group](https://www.facebook.com/groups/appwrite.developers/) or join our [Discord Server](https://appwrite.io/discord) for more help, ideas and discussions. 75 | 76 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.jetbrains.kotlin.jvm' version '1.9.0' 3 | id 'application' 4 | } 5 | 6 | group = 'io.appwrite' 7 | version = '1.0.0' 8 | 9 | repositories { 10 | mavenCentral() 11 | maven { 12 | url "https://s01.oss.sonatype.org/content/repositories/snapshots/" 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation("io.appwrite:sdk-for-kotlin:5.0.2") 18 | implementation("com.google.code.gson:gson:2.9.0") 19 | } 20 | 21 | application { 22 | mainClassName = "io.appwrite.playgroundforkotlin.MainKt" 23 | } 24 | 25 | compileKotlin { 26 | kotlinOptions.jvmTarget = '11' 27 | } 28 | 29 | compileTestKotlin { 30 | kotlinOptions.jvmTarget = '11' 31 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | playground-for-kotlin: 5 | build: . 6 | volumes: 7 | - "./:/app" 8 | working_dir: /app 9 | command: "sh gradlew run" -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | org.gradle.daemon=false -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appwrite/playground-for-kotlin/fd2947657296c635da49dcef0dcd4326371cd2a5/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Tue Feb 15 15:38:23 NZDT 2022 8 | sdk.dir=/Users/jakebarnby/Library/Android/sdk 9 | -------------------------------------------------------------------------------- /nature.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appwrite/playground-for-kotlin/fd2947657296c635da49dcef0dcd4326371cd2a5/nature.jpg -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'playground-for-kotlin' 2 | 3 | -------------------------------------------------------------------------------- /src/main/kotlin/io/appwrite/playgroundforkotlin/Main.kt: -------------------------------------------------------------------------------- 1 | package io.appwrite.playgroundforkotlin 2 | 3 | import io.appwrite.Client 4 | import io.appwrite.ID 5 | import io.appwrite.Permission 6 | import io.appwrite.Role 7 | import io.appwrite.enums.IndexType 8 | import io.appwrite.enums.Runtime 9 | import io.appwrite.extensions.toJson 10 | import io.appwrite.models.InputFile 11 | import io.appwrite.services.Databases 12 | import io.appwrite.services.Functions 13 | import io.appwrite.services.Storage 14 | import io.appwrite.services.Users 15 | import kotlinx.coroutines.delay 16 | import kotlin.system.exitProcess 17 | 18 | val client = Client() 19 | .setEndpoint("YOUR_ENDPOINT") // Replace with your endpoint 20 | .setProject("YOUR_PROJECT_ID") // Replace with your project ID 21 | .setKey("YOUR_API_KEY") // Replace with your API Key 22 | 23 | val databases = Databases(client) 24 | val storage = Storage(client) 25 | val functions = Functions(client) 26 | val users = Users(client) 27 | 28 | lateinit var databaseId: String 29 | lateinit var collectionId: String 30 | lateinit var documentId: String 31 | lateinit var fileId: String 32 | lateinit var bucketId: String 33 | lateinit var userId: String 34 | lateinit var functionId: String 35 | 36 | 37 | suspend fun main() { 38 | createUser("${Math.random()}@appwrite.io", "user@123", "Kotlin Player") 39 | listUsers() 40 | deleteUser() 41 | 42 | createDatabase() 43 | createCollection() 44 | listCollections() 45 | createDocument() 46 | listDocuments() 47 | deleteDocument() 48 | deleteCollection() 49 | deleteDatabase() 50 | 51 | createFunction() 52 | listFunctions() 53 | deleteFunction() 54 | 55 | createBucket() 56 | listBuckets() 57 | uploadFile() 58 | listFiles() 59 | deleteFile() 60 | 61 | println("Ran playground successfully!") 62 | exitProcess(0) 63 | } 64 | 65 | suspend fun createUser(email: String, password: String, name: String) { 66 | println("Running create user API") 67 | val user = users.create( 68 | userId = ID.unique(), 69 | email, 70 | null, 71 | password, 72 | name 73 | ) 74 | userId = user.id 75 | println(user.toJson()) 76 | } 77 | 78 | suspend fun listUsers() { 79 | println("Running list users API") 80 | val users = users.list() 81 | println(users.toJson()) 82 | } 83 | 84 | suspend fun deleteUser() { 85 | println("Running delete user API") 86 | users.delete(userId) 87 | println("User deleted") 88 | } 89 | 90 | suspend fun createDatabase() { 91 | println("Running create database API") 92 | val database = databases.create(ID.unique(), "Movies") 93 | databaseId = database.id 94 | println(database.toJson()) 95 | } 96 | 97 | suspend fun deleteDatabase() { 98 | println("Running delete database API") 99 | databases.delete(databaseId) 100 | println("Database deleted") 101 | } 102 | 103 | suspend fun createCollection() { 104 | println("Running create collection API") 105 | 106 | val collection = databases.createCollection( 107 | databaseId, 108 | collectionId = "movies", 109 | name = "Movies", 110 | permissions = listOf( 111 | Permission.create(Role.users()), 112 | Permission.read(Role.users()), 113 | Permission.update(Role.users()), 114 | Permission.delete(Role.users()), 115 | ), 116 | documentSecurity = true, 117 | ) 118 | collectionId = collection.id 119 | println(collection.toJson()) 120 | 121 | println("Running create string attribute") 122 | val str = databases.createStringAttribute( 123 | databaseId, 124 | collectionId, 125 | key = "name", 126 | size = 255, 127 | required = true, 128 | array = false 129 | ) 130 | println(str.toJson()) 131 | 132 | println("Running create integer attribute") 133 | val int = databases.createIntegerAttribute( 134 | databaseId, 135 | collectionId, 136 | key = "release_year", 137 | required = true, 138 | min = 0, 139 | max = 9999 140 | ) 141 | println(int.toJson()) 142 | 143 | println("Running create float attribute") 144 | val float = databases.createFloatAttribute( 145 | databaseId, 146 | collectionId, 147 | key = "rating", 148 | required = true, 149 | min = 0.0, 150 | max = 99.99 151 | ) 152 | println(float.toJson()) 153 | 154 | println("Running create boolean attribute") 155 | val bool = databases.createBooleanAttribute( 156 | databaseId, 157 | collectionId, 158 | key = "kids", 159 | required = true 160 | ) 161 | println(bool.toJson()) 162 | 163 | println("Running create email attribute") 164 | val email = databases.createEmailAttribute( 165 | databaseId, 166 | collectionId, 167 | key = "email", 168 | required = false, 169 | ) 170 | println(email.toJson()) 171 | 172 | delay(3000) 173 | 174 | println("Running create index") 175 | val index = databases.createIndex( 176 | databaseId, 177 | collectionId, 178 | key = "name_email_idx", 179 | type = IndexType.FULLTEXT, 180 | attributes = listOf("name", "email") 181 | ) 182 | println(index.toJson()) 183 | } 184 | 185 | suspend fun listCollections() { 186 | println("Running list collection API") 187 | val collections = databases.listCollections(databaseId) 188 | println(collections.toJson()) 189 | } 190 | 191 | suspend fun deleteCollection() { 192 | println("Running delete collection API") 193 | databases.deleteCollection(databaseId, collectionId) 194 | println("Collection Deleted") 195 | } 196 | 197 | suspend fun createDocument() { 198 | println("Running Add Document API") 199 | 200 | val document = databases.createDocument( 201 | databaseId, 202 | collectionId, 203 | documentId = ID.unique(), 204 | data = mapOf( 205 | "name" to "Spider Man", 206 | "release_year" to 1920, 207 | "rating" to 98.5, 208 | "kids" to false 209 | ), 210 | permissions = listOf( 211 | Permission.read(Role.users()), 212 | Permission.update(Role.users()), 213 | Permission.delete(Role.users()), 214 | ) 215 | ) 216 | documentId = document.id 217 | println(document.toJson()) 218 | } 219 | 220 | suspend fun listDocuments() { 221 | println("Running List Document API") 222 | val documents = databases.listDocuments( 223 | databaseId, 224 | collectionId 225 | ) 226 | println(documents.toJson()) 227 | } 228 | 229 | suspend fun deleteDocument() { 230 | println("Running Delete Document API") 231 | databases.deleteDocument( 232 | databaseId, 233 | collectionId, 234 | documentId 235 | ) 236 | println("Document Deleted") 237 | } 238 | 239 | suspend fun createFunction() { 240 | println("Running Create Function API") 241 | val function = functions.create( 242 | functionId = ID.unique(), 243 | name = "Test Function", 244 | execute = listOf(Role.any()), 245 | runtime = Runtime.PHP_8_0, 246 | ) 247 | 248 | functionId = function.id 249 | 250 | val variable = functions.createVariable( 251 | functionId, 252 | key = "ENV", 253 | value = "value" 254 | ) 255 | 256 | println(function.toJson()) 257 | println(variable.toJson()) 258 | } 259 | 260 | suspend fun listFunctions() { 261 | println("Running List Functions API") 262 | val functions = functions.list() 263 | println(functions.toJson()) 264 | } 265 | 266 | suspend fun deleteFunction() { 267 | println("Running Delete Function API") 268 | functions.delete(functionId) 269 | println("Function Deleted") 270 | } 271 | 272 | suspend fun uploadFile() { 273 | println("Running Upload File API") 274 | 275 | val file = InputFile.fromPath("./nature.jpg") 276 | val storageFile = storage.createFile( 277 | bucketId = bucketId, 278 | fileId = ID.unique(), 279 | file = file, 280 | permissions = listOf( 281 | Permission.update(Role.any()) 282 | ) 283 | ) 284 | fileId = storageFile.id 285 | println(storageFile.toJson()) 286 | } 287 | 288 | suspend fun createBucket() { 289 | println("Running Create Bucket API") 290 | val bucket = storage.createBucket( 291 | bucketId = ID.unique(), 292 | name = "Name", 293 | permissions = listOf( 294 | Permission.read(Role.any()), 295 | Permission.create(Role.users()), 296 | Permission.update(Role.users()), 297 | Permission.delete(Role.users()), 298 | ), 299 | fileSecurity = true 300 | ) 301 | bucketId = bucket.id 302 | println(bucket.toJson()) 303 | } 304 | 305 | suspend fun listBuckets() { 306 | println("Running List Buckets API") 307 | val buckets = storage.listBuckets() 308 | println(buckets.toJson()) 309 | } 310 | 311 | suspend fun listFiles() { 312 | println("Running List File API") 313 | val files = storage.listFiles(bucketId) 314 | println(files.toJson()) 315 | } 316 | 317 | suspend fun deleteFile() { 318 | println("Running Delete File API") 319 | storage.deleteFile(bucketId, fileId) 320 | println("File Deleted") 321 | } 322 | --------------------------------------------------------------------------------