Skip to content

Commit d5874c3

Browse files
update version number
1 parent ea06822 commit d5874c3

22 files changed

+535
-47
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ jobs:
5050
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
5151
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
5252
SIGNING_SECRET_KEY_RING_FILE: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}
53-
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
53+
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
54+
SDK_VERSION: ${{ github.event.release.tag_name }}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-0.9.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-0.10.0-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
99

10-
**This SDK is compatible with Appwrite server version 0.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).**
10+
**This SDK is compatible with Appwrite server version 0.10.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).**
1111

1212
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 Android 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)
1313

@@ -38,7 +38,7 @@ repositories {
3838
Next, add the dependency to your project's `build.gradle(.kts)` file:
3939

4040
```groovy
41-
implementation("io.appwrite:sdk-for-android:0.0.1")
41+
implementation("io.appwrite:sdk-for-android:0.2.0")
4242
```
4343

4444
### Maven
@@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file:
4949
<dependency>
5050
<groupId>io.appwrite</groupId>
5151
<artifactId>sdk-for-android</artifactId>
52-
<version>0.0.1</version>
52+
<version>0.2.0</version>
5353
</dependency>
5454
</dependencies>
5555
```
@@ -144,7 +144,7 @@ try {
144144
```
145145

146146
### Learn more
147-
You can use following resources to learn more and get help
147+
You can use the following resources to learn more and get help
148148
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-android)
149149
- 📜 [Appwrite Docs](https://appwrite.io/docs)
150150
- 💬 [Discord Community](https://appwrite.io/discord)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin'
33
// Top-level build file where you can add configuration options common to all sub-projects/modules.
44
buildscript {
55
ext.kotlin_version = "1.4.31"
6-
version '0.0.1'
6+
version '0.2.0'
77
repositories {
88
maven { url "https://plugins.gradle.org/m2/" }
99
google()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
5+
import io.appwrite.Client
6+
import io.appwrite.services.Account
7+
8+
public class MainActivity extends AppCompatActivity {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_main);
14+
15+
Client client = new Client(getApplicationContext())
16+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
17+
.setProject("5df5acd0d48c2"); // Your project ID
18+
19+
Account account = new Account(client);
20+
21+
account.createMagicURLSession(
22+
23+
new Continuation<Object>() {
24+
@NotNull
25+
@Override
26+
public CoroutineContext getContext() {
27+
return EmptyCoroutineContext.INSTANCE;
28+
}
29+
30+
@Override
31+
public void resumeWith(@NotNull Object o) {
32+
String json = "";
33+
try {
34+
if (o instanceof Result.Failure) {
35+
Result.Failure failure = (Result.Failure) o;
36+
throw failure.exception;
37+
} else {
38+
Response response = (Response) o;
39+
json = response.body().string();
40+
}
41+
} catch (Throwable th) {
42+
Log.e("ERROR", th.toString());
43+
}
44+
}
45+
}
46+
);
47+
}
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
5+
import io.appwrite.Client
6+
import io.appwrite.services.Account
7+
8+
public class MainActivity extends AppCompatActivity {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
setContentView(R.layout.activity_main);
14+
15+
Client client = new Client(getApplicationContext())
16+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
17+
.setProject("5df5acd0d48c2"); // Your project ID
18+
19+
Account account = new Account(client);
20+
21+
account.updateMagicURLSession(
22+
"[USER_ID]",
23+
"[SECRET]"
24+
new Continuation<Object>() {
25+
@NotNull
26+
@Override
27+
public CoroutineContext getContext() {
28+
return EmptyCoroutineContext.INSTANCE;
29+
}
30+
31+
@Override
32+
public void resumeWith(@NotNull Object o) {
33+
String json = "";
34+
try {
35+
if (o instanceof Result.Failure) {
36+
Result.Failure failure = (Result.Failure) o;
37+
throw failure.exception;
38+
} else {
39+
Response response = (Response) o;
40+
json = response.body().string();
41+
}
42+
} catch (Throwable th) {
43+
Log.e("ERROR", th.toString());
44+
}
45+
}
46+
}
47+
);
48+
}
49+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
5+
import io.appwrite.Client
6+
import io.appwrite.services.Account
7+
8+
class MainActivity : AppCompatActivity() {
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
setContentView(R.layout.activity_main)
12+
13+
val client = Client(applicationContext)
14+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
15+
.setProject("5df5acd0d48c2") // Your project ID
16+
17+
val account = Account(client)
18+
19+
GlobalScope.launch {
20+
val response = account.createMagicURLSession(
21+
email = "[email protected]",
22+
)
23+
val json = response.body?.string()
24+
}
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
5+
import io.appwrite.Client
6+
import io.appwrite.services.Account
7+
8+
class MainActivity : AppCompatActivity() {
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
setContentView(R.layout.activity_main)
12+
13+
val client = Client(applicationContext)
14+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
15+
.setProject("5df5acd0d48c2") // Your project ID
16+
17+
val account = Account(client)
18+
19+
GlobalScope.launch {
20+
val response = account.updateMagicURLSession(
21+
userId = "[USER_ID]",
22+
secret = "[SECRET]"
23+
)
24+
val json = response.body?.string()
25+
}
26+
}
27+
}

library/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
ext {
88
PUBLISH_GROUP_ID = 'io.appwrite'
99
PUBLISH_ARTIFACT_ID = 'sdk-for-android'
10-
PUBLISH_VERSION = '0.0.1'
10+
PUBLISH_VERSION = System.getenv('SDK_VERSION')
1111
POM_URL = 'https://github.com/appwrite/sdk-for-android'
1212
POM_SCM_URL = 'https://github.com/appwrite/sdk-for-android'
1313
POM_ISSUE_URL = 'https://github.com/appwrite/sdk-for-android/issues'
@@ -53,8 +53,8 @@ android {
5353

5454
dependencies {
5555
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${KotlinCompilerVersion.VERSION}")
56-
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
57-
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3")
56+
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
57+
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0")
5858

5959
api(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
6060
api("com.squareup.okhttp3:okhttp")
@@ -65,15 +65,16 @@ dependencies {
6565
implementation("net.gotev:cookie-store:1.3.5")
6666
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
6767
implementation("androidx.lifecycle:lifecycle-common-java8:2.3.1")
68-
implementation("androidx.appcompat:appcompat:1.2.0")
69-
implementation("androidx.fragment:fragment-ktx:1.3.2")
70-
implementation("androidx.activity:activity-ktx:1.2.2")
68+
implementation("androidx.appcompat:appcompat:1.3.1")
69+
implementation("androidx.fragment:fragment-ktx:1.3.6")
70+
implementation("androidx.activity:activity-ktx:1.3.1")
7171
implementation("androidx.browser:browser:1.3.0")
7272

7373
testImplementation 'junit:junit:4.+'
74-
testImplementation "androidx.test.ext:junit-ktx:1.1.2"
75-
testImplementation "androidx.test:core-ktx:1.3.0"
74+
testImplementation "androidx.test.ext:junit-ktx:1.1.3"
75+
testImplementation "androidx.test:core-ktx:1.4.0"
7676
testImplementation "org.robolectric:robolectric:4.5.1"
77+
testApi("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.1")
7778
}
7879

7980
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

library/src/main/java/io/appwrite/Client.kt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import android.content.pm.PackageManager
55
import com.google.gson.Gson
66
import io.appwrite.appwrite.BuildConfig
77
import io.appwrite.exceptions.AppwriteException
8-
import io.appwrite.extensions.JsonExtensions.fromJson
9-
import io.appwrite.models.Error
8+
import io.appwrite.extensions.fromJson
109
import kotlinx.coroutines.CoroutineScope
1110
import kotlinx.coroutines.Dispatchers
1211
import kotlinx.coroutines.Job
@@ -36,6 +35,7 @@ import kotlin.coroutines.resume
3635
class Client @JvmOverloads constructor(
3736
context: Context,
3837
var endPoint: String = "https://appwrite.io/v1",
38+
var endPointRealtime: String? = null,
3939
private var selfSigned: Boolean = false
4040
) : CoroutineScope {
4141

@@ -71,7 +71,7 @@ class Client @JvmOverloads constructor(
7171
"origin" to "appwrite-android://${context.packageName}",
7272
"user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}",
7373
"x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}",
74-
"x-appwrite-response-format" to "0.9.0"
74+
"x-appwrite-response-format" to "0.10.0"
7575
)
7676
config = mutableMapOf()
7777

@@ -171,14 +171,31 @@ class Client @JvmOverloads constructor(
171171
}
172172

173173
/**
174-
* Set endpoint
174+
* Set endpoint and realtime endpoint.
175175
*
176176
* @param endpoint
177177
*
178178
* @return this
179179
*/
180180
fun setEndpoint(endPoint: String): Client {
181181
this.endPoint = endPoint
182+
183+
if (this.endPointRealtime == null && endPoint.startsWith("http")) {
184+
this.endPointRealtime = endPoint.replaceFirst("http", "ws")
185+
}
186+
187+
return this
188+
}
189+
190+
/**
191+
* Set realtime endpoint
192+
*
193+
* @param endpoint
194+
*
195+
* @return this
196+
*/
197+
fun setEndpointRealtime(endPoint: String): Client {
198+
this.endPointRealtime = endPoint
182199
return this
183200
}
184201

@@ -317,9 +334,9 @@ class Client @JvmOverloads constructor(
317334

318335
val contentType: String = response.headers["content-type"] ?: ""
319336
val error = if (contentType.contains("application/json", ignoreCase = true)) {
320-
bodyString.fromJson(Error::class.java)
337+
bodyString.fromJson<AppwriteException>()
321338
} else {
322-
Error(bodyString, response.code)
339+
AppwriteException(bodyString, response.code)
323340
}
324341

325342
it.cancel(AppwriteException(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.appwrite.extensions
2+
3+
import kotlinx.coroutines.Dispatchers.IO
4+
import kotlinx.coroutines.async
5+
import kotlinx.coroutines.awaitAll
6+
import kotlinx.coroutines.withContext
7+
8+
suspend fun <T> Collection<T>.forEachAsync(
9+
callback: suspend (T) -> Unit
10+
) = withContext(IO) {
11+
map { async { callback.invoke(it) } }.awaitAll()
12+
}

library/src/main/java/io/appwrite/extensions/JsonExtensions.kt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,33 @@ package io.appwrite.extensions
22

33
import com.google.gson.Gson
44

5-
object JsonExtensions {
5+
val gson = Gson()
66

7-
fun Any.toJson(): String =
8-
Gson().toJson(this)
7+
fun Any.toJson(): String =
8+
gson.toJson(this)
99

10-
fun <T> String.fromJson(clazz: Class<T>): T =
11-
Gson().fromJson(this, clazz)
12-
}
10+
fun <T> String.fromJson(clazz: Class<T>): T =
11+
gson.fromJson(this, clazz)
12+
13+
inline fun <reified T> String.fromJson(): T =
14+
gson.fromJson(this, T::class.java)
15+
16+
fun <T> Any.jsonCast(to: Class<T>): T =
17+
toJson().fromJson(to)
18+
19+
inline fun <reified T> Any.jsonCast(): T =
20+
toJson().fromJson(T::class.java)
21+
22+
fun <T> Any.tryJsonCast(to: Class<T>): T? = try {
23+
toJson().fromJson(to)
24+
} catch (ex: Exception) {
25+
ex.printStackTrace()
26+
null
27+
}
28+
29+
inline fun <reified T> Any.tryJsonCast(): T? = try {
30+
toJson().fromJson(T::class.java)
31+
} catch (ex: Exception) {
32+
ex.printStackTrace()
33+
null
34+
}

library/src/main/java/io/appwrite/models/Error.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)