Skip to content

Commit acd2eff

Browse files
authored
Merge pull request #150 from abnegate/feat-kotlin-android-support
Feat kotlin android support
2 parents 8c4d9a4 + 7214677 commit acd2eff

25 files changed

+1389
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ examples/*
1111

1212
# exception to the rule
1313
!examples/.gitkeep
14+
.DS_Store

example.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Appwrite\SDK\Language\Swift;
2020
use Appwrite\SDK\Language\DotNet;
2121
use Appwrite\SDK\Language\Flutter;
22+
use Appwrite\SDK\Language\Kotlin;
2223

2324
try {
2425

@@ -419,6 +420,110 @@ function getSSLPage($url) {
419420
;
420421
$sdk->generate(__DIR__ . '/examples/CLI');
421422

423+
// Kotlin
424+
425+
$sdk = new SDK(new Kotlin(), new Swagger2($spec));
426+
427+
$sdk
428+
->setName('Kotlin')
429+
->setNamespace('io appwrite')
430+
->setDescription('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 Flutter 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')
431+
->setShortDescription('Appwrite Kotlin SDK')
432+
->setURL('https://example.com')
433+
->setGitUserName('appwrite')
434+
->setGitRepoName('sdk-for-kotlin')
435+
->setLogo('https://appwrite.io/v1/images/console.png')
436+
->setLicenseContent('test test test')
437+
->setWarning('**This SDK is compatible with Appwrite server version 0.7.x. For older versions, please check previous releases.**')
438+
->setGettingStarted("
439+
### Add your Android Platform
440+
To init your SDK and start interacting with Appwrite services, you need to add a new Flutter platform to your project. To add a new platform, go to your Appwrite console, choose the project you created in the step before, and click the 'Add Platform' button.
441+
442+
From the options, choose to add a new **Flutter** platform and add your app credentials, ignoring iOS.
443+
444+
Add your app <u>name</u> and <u>package name</u>, Your package name is generally the applicationId in your app-level build.gradle file. By registering your new app platform, you are allowing your app to communicate with the Appwrite API.
445+
446+
### OAuth
447+
In order to capture the Appwrite OAuth callback url, the following activity needs to be added to your [AndroidManifest.xml](https://github.com/appwrite/playground-for-flutter/blob/master/android/app/src/main/AndroidManifest.xml). Be sure to relpace the **[PROJECT_ID]** string with your actual Appwrite project ID. You can find your Appwrite project ID in you project settings screen in your Appwrite console.
448+
449+
```xml
450+
<manifest>
451+
<application>
452+
<activity android:name=\"io.appwrite.views.CallbackActivity\" >
453+
<intent-filter android:label=\"android_web_auth\">
454+
<action android:name=\"android.intent.action.VIEW\" />
455+
<category android:name=\"android.intent.category.DEFAULT\" />
456+
<category android:name=\"android.intent.category.BROWSABLE\" />
457+
<data android:scheme=\"appwrite-callback-[PROJECT_ID]\" />
458+
</intent-filter>
459+
</activity>
460+
</application>
461+
</manifest>
462+
```
463+
464+
### Init your SDK
465+
466+
<p>Initialize your SDK code with your project ID, which can be found in your project settings page.
467+
468+
```kotlin
469+
import io.appwrite.Client
470+
import io.appwrite.services.Account
471+
472+
val client = Client(context)
473+
.setEndpoint(\"https://[HOSTNAME_OR_IP]/v1\") // Your API Endpoint
474+
.setProject(\"5df5acd0d48c2\") // Your project ID
475+
.setSelfSigned(true) // Remove in production
476+
```
477+
478+
Before starting to send any API calls to your new Appwrite instance, make sure your Android emulators has network access to the Appwrite server hostname or IP address.
479+
480+
When trying to connect to Appwrite from an emulator or a mobile device, localhost is the hostname for the device or emulator 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](https://ngrok.com/) to proxy the Appwrite API.
481+
482+
### Make Your First Request
483+
484+
<p>Once your SDK object is set, access any of the Appwrite services and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the API References section.
485+
486+
```kotlin
487+
// Register User
488+
val accountService = Account(client)
489+
val user = accountService.create(
490+
491+
\"password\"
492+
)
493+
```
494+
495+
### Full Example
496+
497+
```kotlin
498+
import io.appwrite.Client
499+
import io.appwrite.services.Account
500+
501+
val client = Client(context)
502+
.setEndpoint(\"https://[HOSTNAME_OR_IP]/v1\") // Your API Endpoint
503+
.setProject(\"5df5acd0d48c2\") // Your project ID
504+
.setSelfSigned(true) // Remove in production
505+
506+
val accountService = Account(client)
507+
val user = accountService.create(
508+
509+
\"password\"
510+
)
511+
```
512+
513+
### Learn more
514+
You can use following resources to learn more and get help
515+
- 📜 [Appwrite Docs](https://appwrite.io/docs)
516+
- 💬 [Discord Community](https://appwrite.io/discord)
517+
")
518+
->setChangelog('**CHANGELOG**')
519+
->setVersion('0.7.0')
520+
->setTwitter('appwrite_io')
521+
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
522+
->setDefaultHeaders([
523+
'x-appwrite-response-format' => '0.7.0',
524+
])
525+
;
526+
$sdk->generate(__DIR__ . '/examples/kotlin-android');
422527
}
423528
catch (Exception $exception) {
424529
echo 'Error: ' . $exception->getMessage() . ' on ' . $exception->getFile() . ':' . $exception->getLine() . "\n";

0 commit comments

Comments
 (0)