Skip to content

Fix msg91 params #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-kotlin.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-kotlin.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.0-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.4-blue.svg?style=flat-square)
[![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 @@ -39,7 +39,7 @@ repositories {
Next, add the dependency to your project's `build.gradle(.kts)` file:

```groovy
implementation("io.appwrite:sdk-for-kotlin:5.0.0")
implementation("io.appwrite:sdk-for-kotlin:5.0.1")
```

### Maven
Expand All @@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file:
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-kotlin</artifactId>
<version>5.0.0</version>
<version>5.0.1</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/java/messaging/create-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Messaging messaging = new Messaging(client);
messaging.createMsg91Provider(
"<PROVIDER_ID>", // providerId
"<NAME>", // name
"+12065550100", // from (optional)
"<TEMPLATE_ID>", // templateId (optional)
"<SENDER_ID>", // senderId (optional)
"<AUTH_KEY>", // authKey (optional)
false, // enabled (optional)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/java/messaging/update-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ messaging.updateMsg91Provider(
"<PROVIDER_ID>", // providerId
"<NAME>", // name (optional)
false, // enabled (optional)
"<TEMPLATE_ID>", // templateId (optional)
"<SENDER_ID>", // senderId (optional)
"<AUTH_KEY>", // authKey (optional)
"<FROM>", // from (optional)
new CoroutineCallback<>((result, error) -> {
if (error != null) {
error.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/kotlin/messaging/create-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val messaging = Messaging(client)
val response = messaging.createMsg91Provider(
providerId = "<PROVIDER_ID>",
name = "<NAME>",
from = "+12065550100", // optional
templateId = "<TEMPLATE_ID>", // optional
senderId = "<SENDER_ID>", // optional
authKey = "<AUTH_KEY>", // optional
enabled = false // optional
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/kotlin/messaging/update-msg91provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ val response = messaging.updateMsg91Provider(
providerId = "<PROVIDER_ID>",
name = "<NAME>", // optional
enabled = false, // optional
templateId = "<TEMPLATE_ID>", // optional
senderId = "<SENDER_ID>", // optional
authKey = "<AUTH_KEY>", // optional
from = "<FROM>" // optional
authKey = "<AUTH_KEY>" // optional
)
4 changes: 2 additions & 2 deletions src/main/kotlin/io/appwrite/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class Client @JvmOverloads constructor(
init {
headers = mutableMapOf(
"content-type" to "application/json",
"user-agent" to "AppwriteKotlinSDK/5.0.0 ${System.getProperty("http.agent")}",
"user-agent" to "AppwriteKotlinSDK/5.0.1 ${System.getProperty("http.agent")}",
"x-sdk-name" to "Kotlin",
"x-sdk-platform" to "server",
"x-sdk-language" to "kotlin",
"x-sdk-version" to "5.0.0",
"x-sdk-version" to "5.0.1",
"x-appwrite-response-format" to "1.5.0",
)

Expand Down
29 changes: 26 additions & 3 deletions src/main/kotlin/io/appwrite/ID.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
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 = ID.hexTimestamp()
val randomPadding = (1..padding)
.map { Random.nextInt(0, 16).toString(16) }
.joinToString("")

return baseId + randomPadding
}
}
}
}
20 changes: 10 additions & 10 deletions src/main/kotlin/io/appwrite/services/Messaging.kt
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,9 @@ class Messaging(client: Client) : Service(client) {
*
* @param providerId Provider ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
* @param name Provider name.
* @param from Sender Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.
* @param senderId Msg91 Sender ID.
* @param authKey Msg91 Auth Key.
* @param templateId Msg91 template ID
* @param senderId Msg91 sender ID.
* @param authKey Msg91 auth key.
* @param enabled Set as enabled.
* @return [io.appwrite.models.Provider]
*/
Expand All @@ -952,7 +952,7 @@ class Messaging(client: Client) : Service(client) {
suspend fun createMsg91Provider(
providerId: String,
name: String,
from: String? = null,
templateId: String? = null,
senderId: String? = null,
authKey: String? = null,
enabled: Boolean? = null,
Expand All @@ -962,7 +962,7 @@ class Messaging(client: Client) : Service(client) {
val apiParams = mutableMapOf<String, Any?>(
"providerId" to providerId,
"name" to name,
"from" to from,
"templateId" to templateId,
"senderId" to senderId,
"authKey" to authKey,
"enabled" to enabled,
Expand Down Expand Up @@ -991,9 +991,9 @@ class Messaging(client: Client) : Service(client) {
* @param providerId Provider ID.
* @param name Provider name.
* @param enabled Set as enabled.
* @param senderId Msg91 Sender ID.
* @param authKey Msg91 Auth Key.
* @param from Sender number.
* @param templateId Msg91 template ID.
* @param senderId Msg91 sender ID.
* @param authKey Msg91 auth key.
* @return [io.appwrite.models.Provider]
*/
@JvmOverloads
Expand All @@ -1002,19 +1002,19 @@ class Messaging(client: Client) : Service(client) {
providerId: String,
name: String? = null,
enabled: Boolean? = null,
templateId: String? = null,
senderId: String? = null,
authKey: String? = null,
from: String? = null,
): io.appwrite.models.Provider {
val apiPath = "/messaging/providers/msg91/{providerId}"
.replace("{providerId}", providerId)

val apiParams = mutableMapOf<String, Any?>(
"name" to name,
"enabled" to enabled,
"templateId" to templateId,
"senderId" to senderId,
"authKey" to authKey,
"from" to from,
)
val apiHeaders = mutableMapOf(
"content-type" to "application/json",
Expand Down