Skip to content

Commit

Permalink
feat: Add Verify v1 (#1)
Browse files Browse the repository at this point in the history
* wip: Verify v1

* Test check code

* Bump versions

* All success tests

* Test errors

* Test check failure

* Fix failing build on older JDK
  • Loading branch information
SMadani authored Jul 23, 2024
1 parent dd94d77 commit f7ade8a
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.4.0] - 2024-07-??

### Added
- Verify v1 API

## [0.3.1] - 2024-07-12

### Changed
Expand Down
24 changes: 10 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

<groupId>com.vonage</groupId>
<artifactId>server-sdk-kotlin</artifactId>
<version>0.3.1</version>
<version>0.4.0</version>

<packaging>jar</packaging>
<name>Vonage Kotlin Server SDK</name>
<description>Kotlin client for Vonage APIs</description>
<url>https://github.com/Vonage/vonage-kotlin-sdk</url>
Expand Down Expand Up @@ -48,6 +47,7 @@
<kotlin.compiler.languageVersion>2.0</kotlin.compiler.languageVersion>
<kotlin.compiler.apiVersion>2.0</kotlin.compiler.apiVersion>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
<java.version>8</java.version>
</properties>

<dependencies>
Expand All @@ -59,7 +59,7 @@
<dependency>
<groupId>com.vonage</groupId>
<artifactId>server-sdk</artifactId>
<version>8.9.2</version>
<version>8.9.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
Expand All @@ -76,7 +76,7 @@
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.8.0</version>
<version>3.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -93,7 +93,6 @@
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
Expand All @@ -108,17 +107,16 @@
<version>3.6.3</version>
</requireMavenVersion>
<requireJavaVersion>
<version>1.8</version>
<version>${java.version}</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Expand Down Expand Up @@ -154,7 +152,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
<executions>
<execution>
<id>dokka-jar</id>
Expand All @@ -170,7 +168,6 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
Expand All @@ -185,13 +182,12 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>8</source>
<target>8</target>
<release>8</release>
<release>${java.version}</release>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand Down
44 changes: 44 additions & 0 deletions src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.vonage.client.kt

import com.vonage.client.verify.*

class VerifyLegacy(private val verifyClient: VerifyClient) {

fun verify(number: String, brand: String, properties: (VerifyRequest.Builder.() -> Unit) = {}): VerifyResponse =
verifyClient.verify(VerifyRequest.builder(number, brand).apply(properties).build())

fun psd2Verify(number: String, amount: Double, payee: String,
properties: (Psd2Request.Builder.() -> Unit) = {}): VerifyResponse =
verifyClient.psd2Verify(Psd2Request.builder(number, amount, payee).apply(properties).build())

fun search(vararg requestIds: String): SearchVerifyResponse = verifyClient.search(*requestIds)

fun request(requestId: String): ExistingRequest = ExistingRequest(requestId)

fun request(response: VerifyResponse): ExistingRequest = request(response.requestId)

inner class ExistingRequest internal constructor(private val requestId: String) {

fun cancel(): ControlResponse = verifyClient.cancelVerification(requestId)

fun advance(): ControlResponse = verifyClient.advanceVerification(requestId)

fun check(code: String): CheckResponse = verifyClient.check(requestId, code)

fun search(): SearchVerifyResponse = verifyClient.search(requestId)

@Override
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ExistingRequest
return requestId == other.requestId
}

@Override
override fun hashCode(): Int {
return requestId.hashCode()
}
}

}
1 change: 1 addition & 0 deletions src/main/kotlin/com/vonage/client/kt/Vonage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Vonage(init: VonageClient.Builder.() -> Unit) {
val sms = Sms(vonageClient.smsClient)
val conversion = Conversion(vonageClient.conversionClient)
val redact = Redact(vonageClient.redactClient)
val verifyLegacy = VerifyLegacy(vonageClient.verifyClient)
}

fun VonageClient.Builder.authFromEnv(): VonageClient.Builder {
Expand Down
11 changes: 9 additions & 2 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.vonage.client.kt

import com.fasterxml.jackson.databind.ObjectMapper
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.*
Expand All @@ -12,6 +11,7 @@ import com.vonage.client.common.HttpMethod
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.assertThrows
import com.fasterxml.jackson.databind.ObjectMapper
import java.net.URI
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
Expand All @@ -25,9 +25,9 @@ abstract class AbstractTest {
private val apiSecret = "1234567890abcdef"
private val apiKeySecretEncoded = "YTFiMmMzZDQ6MTIzNDU2Nzg5MGFiY2RlZg=="
private val privateKeyPath = "src/test/resources/com/vonage/client/kt/application_key"
private val signatureSecretName = "sig"
private val apiSecretName = "api_secret"
private val apiKeyName = "api_key"
private val signatureSecretName = "sig"
protected val testUuidStr = "aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
protected val testUuid: UUID = UUID.fromString(testUuidStr)
protected val toNumber = "447712345689"
Expand All @@ -43,9 +43,13 @@ abstract class AbstractTest {
protected val endTime: Instant = Instant.parse(endTimeStr)
protected val timestampStr = "2016-11-14T07:45:14Z"
protected val timestampDateStr = "2016-11-14 07:45:14"
protected val timestampDate = strToDate(timestampDateStr)
protected val timestampDate2Str = "2019-03-02 18:46:57"
protected val timestampDate2 = strToDate(timestampDate2Str)
protected val timestamp: Instant = Instant.parse(timestampStr)
protected val timestamp2Str = "2020-01-29T14:08:30.201Z"
protected val timestamp2: Instant = Instant.parse(timestamp2Str)
protected val currency = "EUR"

private val port = 8081
private val wiremock: WireMockServer = WireMockServer(
Expand All @@ -71,6 +75,9 @@ abstract class AbstractTest {
wiremock.stop()
}

protected fun strToDate(dateStr: String): Date =
Date(Instant.parse(dateStr.replace(' ', 'T') + 'Z').toEpochMilli())

protected enum class ContentType(val mime: String) {
APPLICATION_JSON("application/json"),
FORM_URLENCODED("application/x-www-form-urlencoded");
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/vonage/client/kt/ConversionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ConversionTest : AbstractTest() {
fun `submit sms conversion with timestamp`() {
val delivered = true
mockSuccess(smsMessageId, smsEndpoint, delivered, true)
conversionClient.convertSms(smsMessageId, delivered, timestamp)
conversionClient.convertSms(smsMessageId, delivered, timestampDate.toInstant())
}

@Test
Expand Down
Loading

0 comments on commit f7ade8a

Please sign in to comment.