diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81377fe..ac52e8a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,7 @@ jobs: strategy: fail-fast: false matrix: - java: [17, 22] + java: [17, 23] os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Checkout the repo diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e3bafc..0e03854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ 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/). -## [1.0.0-RC2] - 2024-09-2? +## [1.0.0-RC2] - 2024-09-26 Messages API updates based on Java SDK v8.11.0 ### Added @@ -12,6 +12,9 @@ Messages API updates based on Java SDK v8.11.0 - WhatsApp Reaction builder - Ability to read and revoke messages (support for the `PATCH` endpoint in Messages API) +### Changed +- User agent string now includes `vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION` + ## [1.0.0-RC1] - 2024-09-12 First release candidate diff --git a/bumpversion.sh b/bumpversion.sh new file mode 100755 index 0000000..9e8cd0c --- /dev/null +++ b/bumpversion.sh @@ -0,0 +1,11 @@ +if [ "$1" = "" ] +then + echo "Usage: $0 " + exit 1 +fi + +mvn versions:set -DnewVersion=$1 +mvn validate +rm pom.xml.versionsBackup #pom.xml.releaseBackup +#mvn versions:display-plugin-updates +#mvn versions:display-dependency-updates \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3d99590..a187506 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,27 @@ ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin + + maven-antrun-plugin + 3.1.0 + + + validate + + run + + + + + + + + + maven-enforcer-plugin 3.5.0 diff --git a/src/main/kotlin/com/vonage/client/kt/Vonage.kt b/src/main/kotlin/com/vonage/client/kt/Vonage.kt index 5a38c78..8b48438 100644 --- a/src/main/kotlin/com/vonage/client/kt/Vonage.kt +++ b/src/main/kotlin/com/vonage/client/kt/Vonage.kt @@ -18,6 +18,9 @@ package com.vonage.client.kt import com.vonage.client.HttpConfig import com.vonage.client.VonageClient +const val VONAGE_KOTLIN_SDK_VERSION = "1.0.0-RC2" +private const val SDK_USER_AGENT = "vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION" + /** * Entry point for the SDK. This class provides access to all the Vonage APIs via its properties. * The constructor takes a lambda that configures the client. At a minimum, you must provide @@ -34,7 +37,7 @@ import com.vonage.client.VonageClient * @param config The configuration lambda, where you provide your Vonage account credentials. */ class Vonage(config: VonageClient.Builder.() -> Unit) { - private val client : VonageClient = VonageClient.builder().apply(config).build() + private val client : VonageClient = VonageClient.builder().httpConfig{}.apply(config).build() /** * Access to the Vonage Account API. @@ -181,4 +184,4 @@ fun VonageClient.Builder.authFromEnv(): VonageClient.Builder { * @return The builder. */ fun VonageClient.Builder.httpConfig(init: HttpConfig.Builder.() -> Unit): VonageClient.Builder = - httpConfig(HttpConfig.builder().apply(init).build()) + httpConfig(HttpConfig.builder().apply(init).appendUserAgent(SDK_USER_AGENT).build()) diff --git a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt index 80ed331..701d7eb 100644 --- a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt @@ -27,6 +27,7 @@ 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 com.vonage.client.HttpWrapper import com.vonage.client.users.channels.Websocket import java.net.URI import java.net.URLEncoder @@ -36,6 +37,9 @@ import java.util.* import kotlin.test.assertEquals abstract class AbstractTest { + private val userAgent = "vonage-java-sdk/${HttpWrapper().clientVersion} " + + "java/${System.getProperty("java.version")} " + + "vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION" protected val apiKey = "a1b2c3d4" protected val apiKey2 = "f9e8d7c6" protected val applicationId = "00000000-0000-4000-8000-000000000000" @@ -205,7 +209,7 @@ abstract class AbstractTest { expectedParams: Map? = null): BuildingStep = wiremock.requestServerBuilderStep({ urlPath equalTo expectedUrl - headers contains "User-Agent" like "vonage-java-sdk\\/.+ java\\/.+" + headers contains "User-Agent" equalTo userAgent if (contentType != null) { headers contains contentTypeHeaderName equalTo contentType.mime } diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index b5eb35a..003e37a 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -30,6 +30,7 @@ import kotlin.test.assertNotNull class MessagesTest : AbstractTest() { private val client = vonage.messages + private val authType = AuthType.JWT private val sendUrl = "/v1/messages" private val messageUuid = testUuid private val messageUuidStr = testUuidStr @@ -43,12 +44,9 @@ class MessagesTest : AbstractTest() { private fun testSend(expectedBodyParams: Map, req: MessageRequest) { - val status = 202 - val expectedResponseParams = mapOf("message_uuid" to messageUuidStr) - - mockPost( - expectedUrl = sendUrl, expectedRequestParams = expectedBodyParams, - status = status, expectedResponseParams = expectedResponseParams + mockPost(expectedUrl = sendUrl, status = 202, authType = authType, + expectedRequestParams = expectedBodyParams, + expectedResponseParams = mapOf("message_uuid" to messageUuidStr) ) assertEquals(messageUuid, client.send(req)) } @@ -558,9 +556,9 @@ class MessagesTest : AbstractTest() { @Test fun `revoke outbound message`() { mockPatch( - expectedUrl = "/v1/messages/$messageUuidStr", + expectedUrl = "$sendUrl/$messageUuidStr", expectedRequestParams = mapOf("status" to "revoked"), - authType = AuthType.JWT, status = 200 + authType = authType, status = 200 ) client.existingMessage(messageUuidStr, ApiRegion.API_US).revoke() } diff --git a/src/test/kotlin/com/vonage/client/kt/VonageTest.kt b/src/test/kotlin/com/vonage/client/kt/VonageTest.kt index 58317d8..f97daf2 100644 --- a/src/test/kotlin/com/vonage/client/kt/VonageTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VonageTest.kt @@ -15,6 +15,9 @@ */ package com.vonage.client.kt +import com.vonage.client.HttpWrapper +import com.vonage.client.VonageClient +import org.apache.commons.lang3.reflect.FieldUtils import kotlin.test.* class VonageTest { @@ -24,4 +27,21 @@ class VonageTest { val client = Vonage { authFromEnv(); signatureSecret(null) } println("Finished") // Place debug breakpoint here } + + @Test + fun `test user agent is not overriden`() { + val timeout = 36000 + val customUa = "MyCustomUserAgent" + val client = Vonage { httpConfig { timeoutMillis(timeout); appendUserAgent(customUa) } } + val wrapper = FieldUtils.readField( + client::class.java.getDeclaredField("client").apply { isAccessible = true }.get(client), + "httpWrapper", true + ) as HttpWrapper + + assertEquals( + "vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION", + wrapper.httpConfig.customUserAgent + ) + assertEquals(timeout, wrapper.httpConfig.timeoutMillis) + } } \ No newline at end of file