Skip to content

Commit

Permalink
Merge pull request #52 from appwrite/dev
Browse files Browse the repository at this point in the history
Fix okttp with AGP 8.2+
  • Loading branch information
abnegate authored Apr 24, 2024
2 parents 4826572 + 8ef821b commit 20a109f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 42 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.1-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.4-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)
Expand Down Expand Up @@ -38,7 +38,7 @@ repositories {
Next, add the dependency to your project's `build.gradle(.kts)` file:

```groovy
implementation("io.appwrite:sdk-for-android:5.0.0")
implementation("io.appwrite:sdk-for-android:5.1.0")
```

### Maven
Expand All @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file:
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-android</artifactId>
<version>5.0.0</version>
<version>5.1.0</version>
</dependency>
</dependencies>
```
Expand Down
5 changes: 1 addition & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ dependencies {
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1")

api(platform("com.squareup.okhttp3:okhttp-bom:4.12.0"))
api("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:okhttp-urlconnection")
implementation("com.squareup.okhttp3:logging-interceptor")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.google.code.gson:gson:2.10.1")

implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/io/appwrite/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Client @JvmOverloads constructor(
"x-sdk-name" to "Android",
"x-sdk-platform" to "client",
"x-sdk-language" to "android",
"x-sdk-version" to "5.0.0",
"x-sdk-version" to "5.1.0",
"x-appwrite-response-format" to "1.5.0"
)
config = mutableMapOf()
Expand Down
30 changes: 27 additions & 3 deletions library/src/main/java/io/appwrite/ID.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
package io.appwrite

import java.time.Instant
import kotlin.math.floor
import kotlin.random.Random

class ID {
companion object {
// Generate an hex ID based on timestamp
// Recreated from https://www.php.net/manual/en/function.uniqid.php
private fun hexTimestamp(): String {
val now = Instant.now()
val sec = now.epochSecond
val usec = (System.nanoTime() / 1000) % 1000

val hexTimestamp = "%08x%05x".format(sec, usec)

return hexTimestamp
}

fun custom(id: String): String
= id
fun unique(): String
= "unique()"

// Generate a unique ID with padding to have a longer ID
fun unique(padding: Int = 7): String {
val baseId = hexTimestamp()
val randomPadding = (1..padding)
.map { Random.nextInt(0, 16).toString(16) }
.joinToString("")

return baseId + randomPadding
}
}
}
}
14 changes: 11 additions & 3 deletions library/src/main/java/io/appwrite/models/MfaFactors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@ import io.appwrite.extensions.jsonCast
*/
data class MfaFactors(
/**
* TOTP
* Can TOTP be used for MFA challenge for this account.
*/
@SerializedName("totp")
val totp: Boolean,

/**
* Phone
* Can phone (SMS) be used for MFA challenge for this account.
*/
@SerializedName("phone")
val phone: Boolean,

/**
* Email
* Can email be used for MFA challenge for this account.
*/
@SerializedName("email")
val email: Boolean,

/**
* Can recovery code be used for MFA challenge for this account.
*/
@SerializedName("recoveryCode")
val recoveryCode: Boolean,

) {
fun toMap(): Map<String, Any> = mapOf(
"totp" to totp as Any,
"phone" to phone as Any,
"email" to email as Any,
"recoveryCode" to recoveryCode as Any,
)

companion object {
Expand All @@ -41,6 +48,7 @@ data class MfaFactors(
totp = map["totp"] as Boolean,
phone = map["phone"] as Boolean,
email = map["email"] as Boolean,
recoveryCode = map["recoveryCode"] as Boolean,
)
}
}
8 changes: 8 additions & 0 deletions library/src/main/java/io/appwrite/models/Session.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ data class Session(
@SerializedName("\$createdAt")
val createdAt: String,

/**
* Session update date in ISO 8601 format.
*/
@SerializedName("\$updatedAt")
val updatedAt: String,

/**
* User ID.
*/
Expand Down Expand Up @@ -179,6 +185,7 @@ data class Session(
fun toMap(): Map<String, Any> = mapOf(
"\$id" to id as Any,
"\$createdAt" to createdAt as Any,
"\$updatedAt" to updatedAt as Any,
"userId" to userId as Any,
"expire" to expire as Any,
"provider" to provider as Any,
Expand Down Expand Up @@ -215,6 +222,7 @@ data class Session(
) = Session(
id = map["\$id"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
userId = map["userId"] as String,
expire = map["expire"] as String,
provider = map["provider"] as String,
Expand Down
32 changes: 4 additions & 28 deletions library/src/main/java/io/appwrite/services/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,12 @@ class Account(client: Client) : Service(client) {
*
* @param type Type of authenticator.
* @param otp Valid verification token.
* @return [io.appwrite.models.User<T>]
* @return [Any]
*/
suspend fun <T> deleteMfaAuthenticator(
suspend fun deleteMfaAuthenticator(
type: io.appwrite.enums.AuthenticatorType,
otp: String,
nestedType: Class<T>,
): io.appwrite.models.User<T> {
): Any {
val apiPath = "/account/mfa/authenticators/{type}"
.replace("{type}", type.value)

Expand All @@ -482,38 +481,15 @@ class Account(client: Client) : Service(client) {
val apiHeaders = mutableMapOf(
"content-type" to "application/json",
)
val converter: (Any) -> io.appwrite.models.User<T> = {
@Suppress("UNCHECKED_CAST")
io.appwrite.models.User.from(map = it as Map<String, Any>, nestedType)
}
return client.call(
"DELETE",
apiPath,
apiHeaders,
apiParams,
responseType = classOf(),
converter,
responseType = Any::class.java,
)
}

/**
* Delete Authenticator
*
* Delete an authenticator for a user by ID.
*
* @param type Type of authenticator.
* @param otp Valid verification token.
* @return [io.appwrite.models.User<T>]
*/
@Throws(AppwriteException::class)
suspend fun deleteMfaAuthenticator(
type: io.appwrite.enums.AuthenticatorType,
otp: String,
): io.appwrite.models.User<Map<String, Any>> = deleteMfaAuthenticator(
type,
otp,
nestedType = classOf(),
)

/**
* Create 2FA Challenge
Expand Down

0 comments on commit 20a109f

Please sign in to comment.