Skip to content

Commit 79f3cee

Browse files
authored
Merge pull request #58 from appwrite/dev
feat: Kotlin SDK update for version 12.1.0
2 parents 7e749d7 + 736b109 commit 79f3cee

File tree

11 files changed

+201
-44
lines changed

11 files changed

+201
-44
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 12.1.0
4+
5+
* Deprecate `createVerification` method in `Account` service
6+
* Add `createEmailVerification` method in `Account` service
7+
38
## 9.1.0
49

510
* Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repositories {
3939
Next, add the dependency to your project's `build.gradle(.kts)` file:
4040

4141
```groovy
42-
implementation("io.appwrite:sdk-for-kotlin:12.0.0")
42+
implementation("io.appwrite:sdk-for-kotlin:12.1.0")
4343
```
4444

4545
### Maven
@@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file:
5050
<dependency>
5151
<groupId>io.appwrite</groupId>
5252
<artifactId>sdk-for-kotlin</artifactId>
53-
<version>12.0.0</version>
53+
<version>12.1.0</version>
5454
</dependency>
5555
</dependencies>
5656
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Account;
4+
5+
Client client = new Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setSession(""); // The user session to authenticate with
9+
10+
Account account = new Account(client);
11+
12+
account.createEmailVerification(
13+
"https://example.com", // url
14+
new CoroutineCallback<>((result, error) -> {
15+
if (error != null) {
16+
error.printStackTrace();
17+
return;
18+
}
19+
20+
System.out.println(result);
21+
})
22+
);
23+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import io.appwrite.Client;
2+
import io.appwrite.coroutines.CoroutineCallback;
3+
import io.appwrite.services.Account;
4+
5+
Client client = new Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setSession(""); // The user session to authenticate with
9+
10+
Account account = new Account(client);
11+
12+
account.updateEmailVerification(
13+
"<USER_ID>", // userId
14+
"<SECRET>", // secret
15+
new CoroutineCallback<>((result, error) -> {
16+
if (error != null) {
17+
error.printStackTrace();
18+
return;
19+
}
20+
21+
System.out.println(result);
22+
})
23+
);
24+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import io.appwrite.Client
2+
import io.appwrite.coroutines.CoroutineCallback
3+
import io.appwrite.services.Account
4+
5+
val client = Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setSession("") // The user session to authenticate with
9+
10+
val account = Account(client)
11+
12+
val response = account.createEmailVerification(
13+
url = "https://example.com"
14+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import io.appwrite.Client
2+
import io.appwrite.coroutines.CoroutineCallback
3+
import io.appwrite.services.Account
4+
5+
val client = Client()
6+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
7+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
8+
.setSession("") // The user session to authenticate with
9+
10+
val account = Account(client)
11+
12+
val response = account.updateEmailVerification(
13+
userId = "<USER_ID>",
14+
secret = "<SECRET>"
15+
)

src/main/kotlin/io/appwrite/Client.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ class Client @JvmOverloads constructor(
5858
init {
5959
headers = mutableMapOf(
6060
"content-type" to "application/json",
61-
"user-agent" to "AppwriteKotlinSDK/12.0.0 ${System.getProperty("http.agent")}",
61+
"user-agent" to "AppwriteKotlinSDK/12.1.0 ${System.getProperty("http.agent")}",
6262
"x-sdk-name" to "Kotlin",
6363
"x-sdk-platform" to "server",
6464
"x-sdk-language" to "kotlin",
65-
"x-sdk-version" to "12.0.0",
65+
"x-sdk-version" to "12.1.0",
6666
"x-appwrite-response-format" to "1.8.0",
6767
)
6868

src/main/kotlin/io/appwrite/services/Account.kt

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,10 +1780,48 @@ class Account(client: Client) : Service(client) {
17801780
* @return [io.appwrite.models.Token]
17811781
*/
17821782
@Throws(AppwriteException::class)
1783+
suspend fun createEmailVerification(
1784+
url: String,
1785+
): io.appwrite.models.Token {
1786+
val apiPath = "/account/verifications/email"
1787+
1788+
val apiParams = mutableMapOf<String, Any?>(
1789+
"url" to url,
1790+
)
1791+
val apiHeaders = mutableMapOf<String, String>(
1792+
"content-type" to "application/json",
1793+
)
1794+
val converter: (Any) -> io.appwrite.models.Token = {
1795+
io.appwrite.models.Token.from(map = it as Map<String, Any>)
1796+
}
1797+
return client.call(
1798+
"POST",
1799+
apiPath,
1800+
apiHeaders,
1801+
apiParams,
1802+
responseType = io.appwrite.models.Token::class.java,
1803+
converter,
1804+
)
1805+
}
1806+
1807+
/**
1808+
* 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.
1809+
*
1810+
* 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.
1811+
*
1812+
*
1813+
* @param url URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.
1814+
* @return [io.appwrite.models.Token]
1815+
*/
1816+
@Deprecated(
1817+
message = "This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.",
1818+
replaceWith = ReplaceWith("io.appwrite.services.Account.createEmailVerification")
1819+
)
1820+
@Throws(AppwriteException::class)
17831821
suspend fun createVerification(
17841822
url: String,
17851823
): io.appwrite.models.Token {
1786-
val apiPath = "/account/verification"
1824+
val apiPath = "/account/verifications/email"
17871825

17881826
val apiParams = mutableMapOf<String, Any?>(
17891827
"url" to url,
@@ -1812,11 +1850,49 @@ class Account(client: Client) : Service(client) {
18121850
* @return [io.appwrite.models.Token]
18131851
*/
18141852
@Throws(AppwriteException::class)
1853+
suspend fun updateEmailVerification(
1854+
userId: String,
1855+
secret: String,
1856+
): io.appwrite.models.Token {
1857+
val apiPath = "/account/verifications/email"
1858+
1859+
val apiParams = mutableMapOf<String, Any?>(
1860+
"userId" to userId,
1861+
"secret" to secret,
1862+
)
1863+
val apiHeaders = mutableMapOf<String, String>(
1864+
"content-type" to "application/json",
1865+
)
1866+
val converter: (Any) -> io.appwrite.models.Token = {
1867+
io.appwrite.models.Token.from(map = it as Map<String, Any>)
1868+
}
1869+
return client.call(
1870+
"PUT",
1871+
apiPath,
1872+
apiHeaders,
1873+
apiParams,
1874+
responseType = io.appwrite.models.Token::class.java,
1875+
converter,
1876+
)
1877+
}
1878+
1879+
/**
1880+
* 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.
1881+
*
1882+
* @param userId User ID.
1883+
* @param secret Valid verification token.
1884+
* @return [io.appwrite.models.Token]
1885+
*/
1886+
@Deprecated(
1887+
message = "This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.",
1888+
replaceWith = ReplaceWith("io.appwrite.services.Account.updateEmailVerification")
1889+
)
1890+
@Throws(AppwriteException::class)
18151891
suspend fun updateVerification(
18161892
userId: String,
18171893
secret: String,
18181894
): io.appwrite.models.Token {
1819-
val apiPath = "/account/verification"
1895+
val apiPath = "/account/verifications/email"
18201896

18211897
val apiParams = mutableMapOf<String, Any?>(
18221898
"userId" to userId,
@@ -1846,7 +1922,7 @@ class Account(client: Client) : Service(client) {
18461922
@Throws(AppwriteException::class)
18471923
suspend fun createPhoneVerification(
18481924
): io.appwrite.models.Token {
1849-
val apiPath = "/account/verification/phone"
1925+
val apiPath = "/account/verifications/phone"
18501926

18511927
val apiParams = mutableMapOf<String, Any?>(
18521928
)
@@ -1878,7 +1954,7 @@ class Account(client: Client) : Service(client) {
18781954
userId: String,
18791955
secret: String,
18801956
): io.appwrite.models.Token {
1881-
val apiPath = "/account/verification/phone"
1957+
val apiPath = "/account/verifications/phone"
18821958

18831959
val apiParams = mutableMapOf<String, Any?>(
18841960
"userId" to userId,

src/main/kotlin/io/appwrite/services/Functions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class Functions(client: Client) : Service(client) {
491491
/**
492492
* Create a deployment based on a template.
493493
*
494-
* Use this endpoint with combination of [listTemplates](https://appwrite.io/docs/server/functions#listTemplates) to find the template details.
494+
* Use this endpoint with combination of [listTemplates](https://appwrite.io/docs/products/functions/templates) to find the template details.
495495
*
496496
* @param functionId Function ID.
497497
* @param repository Repository name of the template.

src/main/kotlin/io/appwrite/services/Sites.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class Sites(client: Client) : Service(client) {
486486
/**
487487
* Create a deployment based on a template.
488488
*
489-
* Use this endpoint with combination of [listTemplates](https://appwrite.io/docs/server/sites#listTemplates) to find the template details.
489+
* Use this endpoint with combination of [listTemplates](https://appwrite.io/docs/products/sites/templates) to find the template details.
490490
*
491491
* @param siteId Site ID.
492492
* @param repository Repository name of the template.

0 commit comments

Comments
 (0)