Skip to content

Commit

Permalink
refactor: Rename internal clients
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Aug 7, 2024
1 parent c72cf47 commit 11586bd
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
java-version: ${{ matrix.java }}
cache: maven
- name: Compile with Maven
run: mvn -e --batch-mode compile
run: mvn -e --batch-mode compile -T 1C

verify:
runs-on: ${{ matrix.os }}
Expand All @@ -62,7 +62,7 @@ jobs:
VONAGE_SIGNATURE_SECRET: abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQR
VONAGE_APPLICATION_ID: 00000000-0000-4000-8000-000000000000
VONAGE_PRIVATE_KEY_PATH: src/test/resources/com/vonage/client/kt/application_key
run: mvn -e --batch-mode clean verify
run: mvn -e --batch-mode clean verify -T 1C
- name: Run Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.vonage</groupId>
<artifactId>server-sdk-kotlin</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>

<name>Vonage Kotlin Server SDK</name>
<description>Kotlin client for Vonage APIs</description>
Expand Down Expand Up @@ -40,6 +40,7 @@
</issueManagement>

<properties>
<nexusUrl>https://oss.sonatype.org</nexusUrl>
<project.scm.connection>scm:[email protected]:Vonage/vonage-kotlin-sdk</project.scm.connection>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -269,7 +270,7 @@
<extensions>true</extensions>
<configuration>
<serverId>nexus-releases</serverId>
<nexusUrl>https://oss.sonatype.org</nexusUrl>
<nexusUrl>${nexusUrl}</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/com/vonage/client/kt/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ package com.vonage.client.kt

import com.vonage.client.account.*

class Account internal constructor(private val accountClient: AccountClient) {
class Account internal constructor(private val client: AccountClient) {

fun getBalance(): BalanceResponse = accountClient.balance
fun getBalance(): BalanceResponse = client.balance

fun topUp(transactionId: String): Unit = accountClient.topUp(transactionId)
fun topUp(transactionId: String): Unit = client.topUp(transactionId)

fun updateSettings(incomingSmsUrl: String? = null, deliverReceiptUrl: String? = null): SettingsResponse =
accountClient.updateSettings(SettingsRequest(incomingSmsUrl, deliverReceiptUrl))
client.updateSettings(SettingsRequest(incomingSmsUrl, deliverReceiptUrl))

fun secrets(apiKey: String? = null): Secrets = Secrets(apiKey)

inner class Secrets internal constructor(val apiKey: String? = null) {

fun list(): List<SecretResponse> = (
if (apiKey == null) accountClient.listSecrets()
else accountClient.listSecrets(apiKey)
if (apiKey == null) client.listSecrets()
else client.listSecrets(apiKey)
).secrets

fun create(secret: String): SecretResponse =
if (apiKey == null) accountClient.createSecret(secret)
else accountClient.createSecret(apiKey, secret)
if (apiKey == null) client.createSecret(secret)
else client.createSecret(apiKey, secret)

fun get(secretId: String): SecretResponse =
if (apiKey == null) accountClient.getSecret(secretId)
else accountClient.getSecret(apiKey, secretId)
if (apiKey == null) client.getSecret(secretId)
else client.getSecret(apiKey, secretId)

fun delete(secretId: String): Unit =
if (apiKey == null) accountClient.revokeSecret(secretId)
else accountClient.revokeSecret(apiKey, secretId)
if (apiKey == null) client.revokeSecret(secretId)
else client.revokeSecret(apiKey, secretId)
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/vonage/client/kt/Conversion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import com.vonage.client.conversion.*
import java.time.Instant
import java.util.*

class Conversion internal constructor(private val conversionClient: ConversionClient) {
class Conversion internal constructor(private val client: ConversionClient) {

private fun convert(type: ConversionRequest.Type,
messageId: String, delivered: Boolean, timestamp: Instant?): Unit =
conversionClient.submitConversion(type, messageId, delivered,
client.submitConversion(type, messageId, delivered,
if (timestamp != null) Date.from(timestamp) else null
)

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/vonage/client/kt/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import com.vonage.client.messages.messenger.*
import com.vonage.client.messages.viber.*
import java.util.UUID

class Messages internal constructor(private val messagesClient: MessagesClient) {
class Messages internal constructor(private val client: MessagesClient) {
fun send(message: MessageRequest, sandbox: Boolean = false): UUID =
(if (sandbox) messagesClient.useSandboxEndpoint()
else messagesClient.useRegularEndpoint()).sendMessage(message).messageUuid
(if (sandbox) client.useSandboxEndpoint()
else client.useRegularEndpoint()).sendMessage(message).messageUuid
}

fun smsText(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest =
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/vonage/client/kt/NumberInsight.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ package com.vonage.client.kt

import com.vonage.client.insight.*

class NumberInsight internal constructor(private val niClient: InsightClient) {
class NumberInsight internal constructor(private val client: InsightClient) {

fun basic(number: String, countryCode: String? = null): BasicInsightResponse =
niClient.getBasicNumberInsight(number, countryCode)
client.getBasicNumberInsight(number, countryCode)

fun standard(number: String, countryCode: String? = null, cnam: Boolean? = null): StandardInsightResponse =
niClient.getStandardNumberInsight(StandardInsightRequest.builder()
client.getStandardNumberInsight(StandardInsightRequest.builder()
.number(number).country(countryCode).cnam(cnam).build()
)

fun advanced(number: String, countryCode: String? = null, cnam: Boolean = false,
realTimeData: Boolean = false): AdvancedInsightResponse =
niClient.getAdvancedNumberInsight(AdvancedInsightRequest.builder().async(false)
client.getAdvancedNumberInsight(AdvancedInsightRequest.builder().async(false)
.number(number).country(countryCode).cnam(cnam).realTimeData(realTimeData).build()
)

fun advancedAsync(number: String, callbackUrl: String, countryCode: String? = null, cnam: Boolean = false) {
niClient.getAdvancedNumberInsight(
client.getAdvancedNumberInsight(
AdvancedInsightRequest.builder().async(true)
.number(number).country(countryCode).cnam(cnam).callback(callbackUrl).build()
)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/vonage/client/kt/NumberVerification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ package com.vonage.client.kt
import com.vonage.client.camara.numberverification.*
import java.net.URI

class NumberVerification internal constructor(private val nvClient: NumberVerificationClient) {
class NumberVerification internal constructor(private val client: NumberVerificationClient) {
private var redirectUri: URI? = null

fun createVerificationUrl(phoneNumber: String, redirectUrl: String, state: String? = null): URI {
redirectUri = URI.create(redirectUrl)
return nvClient.initiateVerification(phoneNumber, redirectUri, state)
return client.initiateVerification(phoneNumber, redirectUri, state)
}

fun verifyNumberWithCode(phoneNumber: String, code: String, redirectUrl: String? = null): Boolean {
if (redirectUrl != null) redirectUri = URI.create(redirectUrl)
return nvClient.verifyNumber(phoneNumber, redirectUri, code)
return client.verifyNumber(phoneNumber, redirectUri, code)
}
}
12 changes: 6 additions & 6 deletions src/main/kotlin/com/vonage/client/kt/Numbers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ package com.vonage.client.kt

import com.vonage.client.numbers.*

class Numbers internal constructor(private val numbersClient: NumbersClient) {
class Numbers internal constructor(private val client: NumbersClient) {

fun number(countryCode: String, msisdn: String) = ExistingNumber(countryCode, msisdn)

inner class ExistingNumber internal constructor(val countryCode: String, val msisdn: String) {

fun buy(targetApiKey: String? = null): Unit =
numbersClient.buyNumber(countryCode, msisdn, targetApiKey)
client.buyNumber(countryCode, msisdn, targetApiKey)

fun cancel(targetApiKey: String? = null): Unit =
numbersClient.cancelNumber(countryCode, msisdn, targetApiKey)
client.cancelNumber(countryCode, msisdn, targetApiKey)

fun update(properties: UpdateNumberRequest.Builder.() -> Unit): Unit =
numbersClient.updateNumber(UpdateNumberRequest.builder(msisdn, countryCode).apply(properties).build())
client.updateNumber(UpdateNumberRequest.builder(msisdn, countryCode).apply(properties).build())
}

fun listOwned(filter: ListNumbersFilter.Builder.() -> Unit = {}): ListNumbersResponse =
numbersClient.listNumbers(ListNumbersFilter.builder().apply(filter).build())
client.listNumbers(ListNumbersFilter.builder().apply(filter).build())

fun searchAvailable(filter: SearchNumbersFilter.Builder.() -> Unit): SearchNumbersResponse =
numbersClient.searchNumbers(SearchNumbersFilter.builder().apply(filter).build())
client.searchNumbers(SearchNumbersFilter.builder().apply(filter).build())
}
12 changes: 6 additions & 6 deletions src/main/kotlin/com/vonage/client/kt/Redact.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ package com.vonage.client.kt

import com.vonage.client.redact.*

class Redact internal constructor(private val redactClient: RedactClient) {
class Redact internal constructor(private val client: RedactClient) {

fun redactSms(messageId: String, direction: RedactRequest.Type = RedactRequest.Type.OUTBOUND): Unit =
redactClient.redactTransaction(messageId, RedactRequest.Product.SMS, direction)
client.redactTransaction(messageId, RedactRequest.Product.SMS, direction)

fun redactMessage(messageId: String, direction: RedactRequest.Type = RedactRequest.Type.OUTBOUND): Unit =
redactClient.redactTransaction(messageId, RedactRequest.Product.MESSAGES, direction)
client.redactTransaction(messageId, RedactRequest.Product.MESSAGES, direction)

fun redactCall(callId: String, direction: RedactRequest.Type = RedactRequest.Type.OUTBOUND): Unit =
redactClient.redactTransaction(callId, RedactRequest.Product.VOICE, direction)
client.redactTransaction(callId, RedactRequest.Product.VOICE, direction)

fun redactInsight(requestId: String): Unit =
redactClient.redactTransaction(requestId, RedactRequest.Product.NUMBER_INSIGHTS)
client.redactTransaction(requestId, RedactRequest.Product.NUMBER_INSIGHTS)

fun redactVerification(requestId: String): Unit =
redactClient.redactTransaction(requestId, RedactRequest.Product.VERIFY)
client.redactTransaction(requestId, RedactRequest.Product.VERIFY)
}
6 changes: 3 additions & 3 deletions src/main/kotlin/com/vonage/client/kt/SimSwap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package com.vonage.client.kt
import com.vonage.client.camara.simswap.*
import java.time.Instant

class SimSwap internal constructor(private val simSwapClient: SimSwapClient) {
class SimSwap internal constructor(private val client: SimSwapClient) {

fun checkSimSwap(phoneNumber: String, maxAgeHours: Int = 240): Boolean =
simSwapClient.checkSimSwap(phoneNumber, maxAgeHours)
client.checkSimSwap(phoneNumber, maxAgeHours)

fun retrieveSimSwapDate(phoneNumber: String): Instant? =
simSwapClient.retrieveSimSwapDate(phoneNumber)
client.retrieveSimSwapDate(phoneNumber)
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/vonage/client/kt/Sms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.vonage.client.kt
import com.vonage.client.sms.*
import com.vonage.client.sms.messages.*

class Sms internal constructor(private val smsClient: SmsClient) {
class Sms internal constructor(private val client: SmsClient) {

private fun send(msgObj: Message, statusReport: Boolean?, ttl: Int?,
messageClass: Message.MessageClass?, clientRef: String?,
Expand All @@ -31,7 +31,7 @@ class Sms internal constructor(private val smsClient: SmsClient) {
msgObj.contentId = contentId
msgObj.entityId = entityId
msgObj.callbackUrl = callbackUrl
return smsClient.submitMessage(msgObj).messages
return client.submitMessage(msgObj).messages
}

fun sendText(from: String, to: String, message: String, unicode: Boolean = false,
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/vonage/client/kt/Verify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ package com.vonage.client.kt
import com.vonage.client.verify2.*
import java.util.*

class Verify(private val verify2Client: Verify2Client) {
class Verify(private val client: Verify2Client) {

fun sendVerification(
brand: String = "Vonage",
init: VerificationRequest.Builder.() -> Unit
): VerificationResponse = verify2Client.sendVerification(
): VerificationResponse = client.sendVerification(
VerificationRequest.builder().brand(brand).apply(init).build()
)

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

fun cancel(): Unit = verify2Client.cancelVerification(requestId)
fun cancel(): Unit = client.cancelVerification(requestId)

fun nextWorkflow(): Unit = verify2Client.nextWorkflow(requestId)
fun nextWorkflow(): Unit = client.nextWorkflow(requestId)

fun checkVerificationCode(code: String): VerifyCodeResponse =
verify2Client.checkVerificationCode(requestId, code)
client.checkVerificationCode(requestId, code)

fun isValidVerificationCode(code: String): Boolean {
try {
Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ package com.vonage.client.kt

import com.vonage.client.verify.*

class VerifyLegacy internal constructor(private val verifyClient: VerifyClient) {
class VerifyLegacy internal constructor(private val client: VerifyClient) {

fun verify(number: String, brand: String, properties: (VerifyRequest.Builder.() -> Unit) = {}): VerifyResponse =
verifyClient.verify(VerifyRequest.builder(number, brand).apply(properties).build())
client.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())
client.psd2Verify(Psd2Request.builder(number, amount, payee).apply(properties).build())

fun search(vararg requestIds: String): SearchVerifyResponse = verifyClient.search(*requestIds)
fun search(vararg requestIds: String): SearchVerifyResponse = client.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 cancel(): ControlResponse = client.cancelVerification(requestId)

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

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

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

@Override
override fun equals(other: Any?): Boolean {
Expand Down
34 changes: 17 additions & 17 deletions src/main/kotlin/com/vonage/client/kt/Voice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@ import java.net.URI
import java.time.Instant
import java.util.*

class Voice(private val voiceClient: VoiceClient) {
class Voice internal constructor(private val client: VoiceClient) {

fun call(callId: String): ExistingCall = ExistingCall(callId)

inner class ExistingCall internal constructor(val callId: String) {

fun info(): CallInfo = voiceClient.getCallDetails(callId)
fun info(): CallInfo = client.getCallDetails(callId)

fun hangup(): Unit = voiceClient.terminateCall(callId)
fun hangup(): Unit = client.terminateCall(callId)

fun mute(): Unit = voiceClient.muteCall(callId)
fun mute(): Unit = client.muteCall(callId)

fun unmute(): Unit = voiceClient.unmuteCall(callId)
fun unmute(): Unit = client.unmuteCall(callId)

fun earmuff(): Unit = voiceClient.earmuffCall(callId)
fun earmuff(): Unit = client.earmuffCall(callId)

fun unearmuff(): Unit = voiceClient.unearmuffCall(callId)
fun unearmuff(): Unit = client.unearmuffCall(callId)

fun transfer(vararg actions: Action): Unit = voiceClient.transferCall(callId, Ncco(actions.asList()))
fun transfer(vararg actions: Action): Unit = client.transferCall(callId, Ncco(actions.asList()))

fun transfer(nccoUrl: String): Unit = voiceClient.transferCall(callId, nccoUrl)
fun transfer(nccoUrl: String): Unit = client.transferCall(callId, nccoUrl)

fun transfer(nccoUrl: URI): Unit = transfer(nccoUrl.toString())

fun sendDtmf(digits: String): DtmfResponse = voiceClient.sendDtmf(callId, digits)
fun sendDtmf(digits: String): DtmfResponse = client.sendDtmf(callId, digits)

fun streamAudio(streamUrl: String, loop: Int = 1, level: Double = 0.0): StreamResponse =
voiceClient.startStream(callId, streamUrl, loop, level)
client.startStream(callId, streamUrl, loop, level)

fun stopStream(): StreamResponse = voiceClient.stopStream(callId)
fun stopStream(): StreamResponse = client.stopStream(callId)

fun startTalk(text: String, properties: (TalkPayload.Builder.() -> Unit) = {}): TalkResponse =
voiceClient.startTalk(callId, TalkPayload.builder(text).apply(properties).build())
client.startTalk(callId, TalkPayload.builder(text).apply(properties).build())

fun stopTalk(): TalkResponse = voiceClient.stopTalk(callId)
fun stopTalk(): TalkResponse = client.stopTalk(callId)
}

fun listCalls(filter: (CallsFilter.Builder.() -> Unit)? = null): CallInfoPage =
if (filter == null) voiceClient.listCalls()
else voiceClient.listCalls(CallsFilter.builder().apply(filter).build())
if (filter == null) client.listCalls()
else client.listCalls(CallsFilter.builder().apply(filter).build())

fun createCall(call: Call.Builder.() -> Unit): CallEvent =
voiceClient.createCall(Call.builder().apply(call).build())
client.createCall(Call.builder().apply(call).build())
}

fun CallsFilter.Builder.dateStart(dateStart: String): CallsFilter.Builder =
Expand Down
Loading

0 comments on commit 11586bd

Please sign in to comment.