From f4f1dfef1e5b52e9655ac905d7e4375aa852307a Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Tue, 30 Jul 2024 13:25:17 +0100 Subject: [PATCH] refactor!: Use boolean param for Messages sandbox --- CHANGELOG.md | 3 ++- src/main/kotlin/com/vonage/client/kt/Messages.kt | 10 ++++------ src/test/kotlin/com/vonage/client/kt/MessagesTest.kt | 5 ----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d1fa2d..f862754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Number Verification API ### Changed -- `InputAction.Builder.dtmf` extension method uses `DtmfSettings` builder instead of setters +- `InputAction.Builder#dtmf` extension method uses `DtmfSettings` builder instead of setters +- `Messages#send` now uses optional Boolean parameter for sandbox instead of separate method ## [0.5.0] - 2024-07-25 diff --git a/src/main/kotlin/com/vonage/client/kt/Messages.kt b/src/main/kotlin/com/vonage/client/kt/Messages.kt index d98a9a4..60a18e8 100644 --- a/src/main/kotlin/com/vonage/client/kt/Messages.kt +++ b/src/main/kotlin/com/vonage/client/kt/Messages.kt @@ -23,12 +23,10 @@ import com.vonage.client.messages.messenger.* import com.vonage.client.messages.viber.* import java.util.UUID -class Messages(private val client: MessagesClient) { - fun send(message: MessageRequest): UUID = - client.useRegularEndpoint().sendMessage(message).messageUuid - - fun sendSandbox(message: MessageRequest): UUID = - client.useSandboxEndpoint().sendMessage(message).messageUuid +class Messages(private val messagesClient: MessagesClient) { + fun send(message: MessageRequest, sandbox: Boolean = false): UUID = + (if (sandbox) messagesClient.useSandboxEndpoint() + else messagesClient.useRegularEndpoint()).sendMessage(message).messageUuid } fun smsText(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest = diff --git a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt index f06a669..b46f40a 100644 --- a/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/MessagesTest.kt @@ -53,11 +53,6 @@ class MessagesTest : AbstractTest() { status = status, expectedResponseParams = expectedResponseParams ) assertEquals(messageUuid, messagesClient.send(req)) - - // TODO fix mocking full url - //val sandboxUrl = "https://messages-sandbox.nexmo.com$sendUrl" - //mockJsonJwtPost(sandboxUrl, expectedBodyParams, status, expectedResponseParams) - //assertEquals(messageUuid, messagesClient.sendSandbox(req)) } private fun baseBody(messageType: String, channel: String): Map =