-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,9 @@ | |
<nexusUrl>https://oss.sonatype.org</nexusUrl> | ||
<project.scm.connection>scm:[email protected]: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> | ||
|
@@ -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> | ||
|
@@ -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> | ||
|
@@ -187,7 +186,6 @@ | |
<plugin> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<version>${kotlin.version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters