Skip to content

Commit 60a8c3f

Browse files
committed
refactor: Set SDK User-Agent name & version
1 parent f93e5cd commit 60a8c3f

File tree

8 files changed

+73
-13
lines changed

8 files changed

+73
-13
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
strategy:
4444
fail-fast: false
4545
matrix:
46-
java: [17, 22]
46+
java: [17, 23]
4747
os: [ubuntu-latest, macos-latest, windows-latest]
4848
steps:
4949
- name: Checkout the repo

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [1.0.0-RC2] - 2024-09-2?
7+
## [1.0.0-RC2] - 2024-09-26
88
Messages API updates based on Java SDK v8.11.0
99

1010
### Added
1111
- RCS message type builders
1212
- WhatsApp Reaction builder
1313
- Ability to read and revoke messages (support for the `PATCH` endpoint in Messages API)
1414

15+
### Changed
16+
- User agent string now includes `vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION`
17+
1518
## [1.0.0-RC1] - 2024-09-12
1619
First release candidate
1720

bumpversion.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if [ "$1" = "" ]
2+
then
3+
echo "Usage: $0 <new version>"
4+
exit 1
5+
fi
6+
7+
mvn versions:set -DnewVersion=$1
8+
mvn validate
9+
rm pom.xml.versionsBackup #pom.xml.releaseBackup
10+
#mvn versions:display-plugin-updates
11+
#mvn versions:display-dependency-updates

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@
9393
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
9494
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
9595
<plugins>
96+
<plugin>
97+
<artifactId>maven-antrun-plugin</artifactId>
98+
<version>3.1.0</version>
99+
<executions>
100+
<execution>
101+
<phase>validate</phase>
102+
<goals>
103+
<goal>run</goal>
104+
</goals>
105+
<configuration>
106+
<target>
107+
<replaceregexp
108+
file="src/main/kotlin/com/vonage/client/kt/Vonage.kt"
109+
match="VONAGE_KOTLIN_SDK_VERSION = &quot;.+&quot;"
110+
replace="VONAGE_KOTLIN_SDK_VERSION = &quot;${project.version}&quot;"
111+
/>
112+
</target>
113+
</configuration>
114+
</execution>
115+
</executions>
116+
</plugin>
96117
<plugin>
97118
<artifactId>maven-enforcer-plugin</artifactId>
98119
<version>3.5.0</version>

src/main/kotlin/com/vonage/client/kt/Vonage.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package com.vonage.client.kt
1818
import com.vonage.client.HttpConfig
1919
import com.vonage.client.VonageClient
2020

21+
const val VONAGE_KOTLIN_SDK_VERSION = "1.0.0-RC2"
22+
private const val SDK_USER_AGENT = "vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION"
23+
2124
/**
2225
* Entry point for the SDK. This class provides access to all the Vonage APIs via its properties.
2326
* The constructor takes a lambda that configures the client. At a minimum, you must provide
@@ -34,7 +37,7 @@ import com.vonage.client.VonageClient
3437
* @param config The configuration lambda, where you provide your Vonage account credentials.
3538
*/
3639
class Vonage(config: VonageClient.Builder.() -> Unit) {
37-
private val client : VonageClient = VonageClient.builder().apply(config).build()
40+
private val client : VonageClient = VonageClient.builder().httpConfig{}.apply(config).build()
3841

3942
/**
4043
* Access to the Vonage Account API.
@@ -181,4 +184,4 @@ fun VonageClient.Builder.authFromEnv(): VonageClient.Builder {
181184
* @return The builder.
182185
*/
183186
fun VonageClient.Builder.httpConfig(init: HttpConfig.Builder.() -> Unit): VonageClient.Builder =
184-
httpConfig(HttpConfig.builder().apply(init).build())
187+
httpConfig(HttpConfig.builder().apply(init).appendUserAgent(SDK_USER_AGENT).build())

src/test/kotlin/com/vonage/client/kt/AbstractTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.AfterEach
2727
import org.junit.jupiter.api.BeforeEach
2828
import org.junit.jupiter.api.assertThrows
2929
import com.fasterxml.jackson.databind.ObjectMapper
30+
import com.vonage.client.HttpWrapper
3031
import com.vonage.client.users.channels.Websocket
3132
import java.net.URI
3233
import java.net.URLEncoder
@@ -36,6 +37,9 @@ import java.util.*
3637
import kotlin.test.assertEquals
3738

3839
abstract class AbstractTest {
40+
private val userAgent = "vonage-java-sdk/${HttpWrapper().clientVersion} " +
41+
"java/${System.getProperty("java.version")} " +
42+
"vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION"
3943
protected val apiKey = "a1b2c3d4"
4044
protected val apiKey2 = "f9e8d7c6"
4145
protected val applicationId = "00000000-0000-4000-8000-000000000000"
@@ -205,7 +209,7 @@ abstract class AbstractTest {
205209
expectedParams: Map<String, Any>? = null): BuildingStep =
206210
wiremock.requestServerBuilderStep({
207211
urlPath equalTo expectedUrl
208-
headers contains "User-Agent" like "vonage-java-sdk\\/.+ java\\/.+"
212+
headers contains "User-Agent" equalTo userAgent
209213
if (contentType != null) {
210214
headers contains contentTypeHeaderName equalTo contentType.mime
211215
}

src/test/kotlin/com/vonage/client/kt/MessagesTest.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import kotlin.test.assertNotNull
3030

3131
class MessagesTest : AbstractTest() {
3232
private val client = vonage.messages
33+
private val authType = AuthType.JWT
3334
private val sendUrl = "/v1/messages"
3435
private val messageUuid = testUuid
3536
private val messageUuidStr = testUuidStr
@@ -43,12 +44,9 @@ class MessagesTest : AbstractTest() {
4344

4445

4546
private fun testSend(expectedBodyParams: Map<String, Any>, req: MessageRequest) {
46-
val status = 202
47-
val expectedResponseParams = mapOf("message_uuid" to messageUuidStr)
48-
49-
mockPost(
50-
expectedUrl = sendUrl, expectedRequestParams = expectedBodyParams,
51-
status = status, expectedResponseParams = expectedResponseParams
47+
mockPost(expectedUrl = sendUrl, status = 202, authType = authType,
48+
expectedRequestParams = expectedBodyParams,
49+
expectedResponseParams = mapOf("message_uuid" to messageUuidStr)
5250
)
5351
assertEquals(messageUuid, client.send(req))
5452
}
@@ -558,9 +556,9 @@ class MessagesTest : AbstractTest() {
558556
@Test
559557
fun `revoke outbound message`() {
560558
mockPatch(
561-
expectedUrl = "/v1/messages/$messageUuidStr",
559+
expectedUrl = "$sendUrl/$messageUuidStr",
562560
expectedRequestParams = mapOf("status" to "revoked"),
563-
authType = AuthType.JWT, status = 200
561+
authType = authType, status = 200
564562
)
565563
client.existingMessage(messageUuidStr, ApiRegion.API_US).revoke()
566564
}

src/test/kotlin/com/vonage/client/kt/VonageTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package com.vonage.client.kt
1717

18+
import com.vonage.client.HttpWrapper
19+
import com.vonage.client.VonageClient
20+
import org.apache.commons.lang3.reflect.FieldUtils
1821
import kotlin.test.*
1922

2023
class VonageTest {
@@ -24,4 +27,21 @@ class VonageTest {
2427
val client = Vonage { authFromEnv(); signatureSecret(null) }
2528
println("Finished") // Place debug breakpoint here
2629
}
30+
31+
@Test
32+
fun `test user agent is not overriden`() {
33+
val timeout = 36000
34+
val customUa = "MyCustomUserAgent"
35+
val client = Vonage { httpConfig { timeoutMillis(timeout); appendUserAgent(customUa) } }
36+
val wrapper = FieldUtils.readField(
37+
client::class.java.getDeclaredField("client").apply { isAccessible = true }.get(client),
38+
"httpWrapper", true
39+
) as HttpWrapper
40+
41+
assertEquals(
42+
"vonage-kotlin-sdk/$VONAGE_KOTLIN_SDK_VERSION",
43+
wrapper.httpConfig.customUserAgent
44+
)
45+
assertEquals(timeout, wrapper.httpConfig.timeoutMillis)
46+
}
2747
}

0 commit comments

Comments
 (0)