Skip to content

Commit

Permalink
Wrap Verify2 client
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 6, 2024
1 parent da23213 commit 3433e55
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
12 changes: 5 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@
<nexusUrl>https://oss.sonatype.org</nexusUrl>
<project.scm.connection>scm:git@github.com:Vonage/vonage-kotlin-sdk</project.scm.connection>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>8</java.version>
<kotlin.version>2.0.0</kotlin.version>
<kotlin.compiler.languageVersion>${kotlin.version}</kotlin.compiler.languageVersion>
<kotlin.compiler.apiVersion>${kotlin.version}</kotlin.compiler.apiVersion>
<java.version>1.8</java.version>
<kotlin.compiler.languageVersion>2.0</kotlin.compiler.languageVersion>
<kotlin.compiler.apiVersion>2.0</kotlin.compiler.apiVersion>
<kotlin.compiler.jvmTarget>${java.version}</kotlin.compiler.jvmTarget>
<maven.compiler.release>${java.version}</maven.compiler.release>
</properties>
Expand All @@ -56,7 +55,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.vonage</groupId>
Expand All @@ -66,7 +65,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -187,7 +186,6 @@
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/vonage/client/kt/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import com.vonage.client.messages.messenger.*
import com.vonage.client.messages.viber.*
import java.util.UUID

class Messages (private val messagesClient: MessagesClient) {
fun send(message : MessageRequest) : UUID {
return messagesClient.sendMessage(message).messageUuid
class Messages(private val client: MessagesClient) {
fun send(message: MessageRequest): UUID {
return client.sendMessage(message).messageUuid
}
}

fun sms(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest {
fun smsText(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest {
return SmsTextRequest.builder().apply(init).build()
}

fun vcard(init: MmsVcardRequest.Builder.() -> Unit): MmsVcardRequest {
fun mmsVcard(init: MmsVcardRequest.Builder.() -> Unit): MmsVcardRequest {
return MmsVcardRequest.builder().apply(init).build()
}

Expand Down
70 changes: 60 additions & 10 deletions src/main/kotlin/com/vonage/client/kt/Verify.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
package org.example.com.vonage.client.kt
package com.vonage.client.kt

import com.vonage.client.verify2.SmsWorkflow
import com.vonage.client.verify2.VerificationRequest
import com.vonage.client.verify2.Verify2Client
import com.vonage.client.verify2.VoiceWorkflow
import com.vonage.client.verify2.*
import java.util.*

fun Verify2Client.sendVerification(init: VerificationRequest.Builder.() -> Unit) : UUID {
return this.sendVerification(VerificationRequest.builder().apply(init).build()).requestId
class Verify(private val verify2Client: Verify2Client) {

fun sendVerification(
brand: String = "Vonage",
init: VerificationRequest.Builder.() -> Unit
): UUID {

return verify2Client.sendVerification(
VerificationRequest.builder().brand(brand).apply(init).build()
).requestId
}

fun cancelVerification(requestId: String) {
verify2Client.cancelVerification(UUID.fromString(requestId))
}

fun nextWorkflow(requestId: String) {
verify2Client.nextWorkflow(UUID.fromString(requestId))
}

fun checkVerificationCode(requestId: String, code: String) {
verify2Client.checkVerificationCode(UUID.fromString(requestId), code)
}

fun isValidVerificationCode(requestId: String, code: String): Boolean {
try {
verify2Client.checkVerificationCode(UUID.fromString(requestId), code)
return true
} catch (ex: VerifyResponseException) {
if (ex.statusCode == 400 || ex.statusCode == 410) {
return false
} else {
throw ex
}
}
}
}

fun VerificationRequest.Builder.silentAuth(number: String): VerificationRequest.Builder {
return this.addWorkflow(SilentAuthWorkflow(number))
}

fun VerificationRequest.Builder.sms(number: String, init: SmsWorkflow.Builder.() -> Unit = {}) : VerificationRequest.Builder {
fun VerificationRequest.Builder.sms(
number: String,
init: SmsWorkflow.Builder.() -> Unit = {}
): VerificationRequest.Builder {
return this.addWorkflow(SmsWorkflow.builder(number).apply(init).build())
}

fun VerificationRequest.Builder.voice(number: String) : VerificationRequest.Builder {
fun VerificationRequest.Builder.voice(number: String): VerificationRequest.Builder {
return this.addWorkflow(VoiceWorkflow(number))
}
}

fun VerificationRequest.Builder.email(to: String, from: String? = null): VerificationRequest.Builder {
return this.addWorkflow(EmailWorkflow(to, from))
}

fun VerificationRequest.Builder.whatsapp(to: String, from: String): VerificationRequest.Builder {
return this.addWorkflow(WhatsappWorkflow(to, from))
}

fun VerificationRequest.Builder.whatsappCodeless(to: String, from: String): VerificationRequest.Builder {
return this.addWorkflow(WhatsappCodelessWorkflow(to, from))
}
17 changes: 10 additions & 7 deletions src/main/kotlin/com/vonage/client/kt/Vonage.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.example.com.vonage.client.kt
package com.vonage.client.kt

import com.vonage.client.HttpConfig
import com.vonage.client.VonageClient
import com.vonage.client.kt.Messages
import com.vonage.client.account.AccountClient
import com.vonage.client.messages.MessagesClient
import com.vonage.client.verify2.SmsWorkflow
import com.vonage.client.verify2.Verify2Client
import com.vonage.client.voice.VoiceClient

class Vonage constructor(init: VonageClient.Builder.() -> Unit) {
private val vonageClient : VonageClient = VonageClient.builder().apply(init).build();
val verify = vonageClient.verify2Client
val messages = Messages(vonageClient.messagesClient)
val verify: Verify2Client = vonageClient.verify2Client

}

fun VonageClient.Builder.authFromEnv() : VonageClient.Builder {
Expand All @@ -23,12 +28,10 @@ fun httpConfig(init: HttpConfig.Builder.() -> Unit): HttpConfig {
return HttpConfig.builder().apply(init).build()
}

private fun env(variable : String) : String {
private fun env(variable: String) : String? {
return System.getenv(variable)
}

fun main() {
val client = Vonage {
authFromEnv()
}
val client = Vonage { authFromEnv() }
}

0 comments on commit 3433e55

Please sign in to comment.