Skip to content

Commit

Permalink
refactor: Set SDK User-Agent name & version
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Sep 26, 2024
1 parent f93e5cd commit 60a8c3f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ 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
- RCS message type builders
- 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

Expand Down
11 changes: 11 additions & 0 deletions bumpversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if [ "$1" = "" ]
then
echo "Usage: $0 <new version>"
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
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<replaceregexp
file="src/main/kotlin/com/vonage/client/kt/Vonage.kt"
match="VONAGE_KOTLIN_SDK_VERSION = &quot;.+&quot;"
replace="VONAGE_KOTLIN_SDK_VERSION = &quot;${project.version}&quot;"
/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/com/vonage/client/kt/Vonage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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())
6 changes: 5 additions & 1 deletion src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -205,7 +209,7 @@ abstract class AbstractTest {
expectedParams: Map<String, Any>? = 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
}
Expand Down
14 changes: 6 additions & 8 deletions src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,12 +44,9 @@ class MessagesTest : AbstractTest() {


private fun testSend(expectedBodyParams: Map<String, Any>, 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))
}
Expand Down Expand Up @@ -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()
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/kotlin/com/vonage/client/kt/VonageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}

0 comments on commit 60a8c3f

Please sign in to comment.