Skip to content

Commit

Permalink
fix: Explicit return types & internal constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Aug 5, 2024
1 parent e526c6a commit abbd8f7
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 37 deletions.
9 changes: 5 additions & 4 deletions src/main/kotlin/com/vonage/client/kt/Conversion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import com.vonage.client.conversion.*
import java.time.Instant
import java.util.*

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

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

fun convertSms(messageId: String, delivered: Boolean, timestamp: Instant? = null) =
fun convertSms(messageId: String, delivered: Boolean, timestamp: Instant? = null): Unit =
convert(ConversionRequest.Type.SMS, messageId, delivered, timestamp)

fun convertVoice(callId: String, delivered: Boolean, timestamp: Instant? = null) =
fun convertVoice(callId: String, delivered: Boolean, timestamp: Instant? = null): Unit =
convert(ConversionRequest.Type.VOICE, callId, delivered, timestamp)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/vonage/client/kt/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.vonage.client.messages.messenger.*
import com.vonage.client.messages.viber.*
import java.util.UUID

class Messages(private val messagesClient: MessagesClient) {
class Messages internal constructor(private val messagesClient: MessagesClient) {
fun send(message: MessageRequest, sandbox: Boolean = false): UUID =
(if (sandbox) messagesClient.useSandboxEndpoint()
else messagesClient.useRegularEndpoint()).sendMessage(message).messageUuid
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/vonage/client/kt/NumberInsight.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.vonage.client.kt

import com.vonage.client.insight.*

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

fun basic(number: String, countryCode: String? = null): BasicInsightResponse =
niClient.getBasicNumberInsight(number, countryCode)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/vonage/client/kt/NumberVerification.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.camara.numberverification.*
import java.net.URI

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

fun createVerificationUrl(phoneNumber: String, redirectUrl: String, state: String? = null): URI {
Expand Down
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(private val numbersClient: NumbersClient) {
class Numbers internal constructor(private val numbersClient: 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) =
fun buy(targetApiKey: String? = null): Unit =
numbersClient.buyNumber(countryCode, msisdn, targetApiKey)

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

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

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

fun searchAvailable(filter: SearchNumbersFilter.Builder.() -> Unit) =
fun searchAvailable(filter: SearchNumbersFilter.Builder.() -> Unit): SearchNumbersResponse =
numbersClient.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(private val redactClient: RedactClient) {
class Redact internal constructor(private val redactClient: RedactClient) {

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

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

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

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

fun redactVerification(requestId: String) =
fun redactVerification(requestId: String): Unit =
redactClient.redactTransaction(requestId, RedactRequest.Product.VERIFY)
}
5 changes: 3 additions & 2 deletions src/main/kotlin/com/vonage/client/kt/SimSwap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
package com.vonage.client.kt

import com.vonage.client.camara.simswap.*
import java.time.Instant

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

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

fun retrieveSimSwapDate(phoneNumber: String) =
fun retrieveSimSwapDate(phoneNumber: String): Instant? =
simSwapClient.retrieveSimSwapDate(phoneNumber)
}
2 changes: 1 addition & 1 deletion 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(private val smsClient: SmsClient) {
class Sms internal constructor(private val smsClient: SmsClient) {

private fun send(msgObj: Message, statusReport: Boolean?, ttl: Int?,
messageClass: Message.MessageClass?, clientRef: String?,
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/vonage/client/kt/Verify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ class Verify(private val verify2Client: Verify2Client) {
VerificationRequest.builder().brand(brand).apply(init).build()
)

fun cancelVerification(requestId: UUID) = verify2Client.cancelVerification(requestId)
fun cancelVerification(requestId: UUID): Unit = verify2Client.cancelVerification(requestId)

fun cancelVerification(requestId: String) = cancelVerification(UUID.fromString(requestId))
fun cancelVerification(requestId: String): Unit = cancelVerification(UUID.fromString(requestId))

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

fun nextWorkflow(requestId: String) = nextWorkflow(UUID.fromString(requestId))
fun nextWorkflow(requestId: String): Unit = nextWorkflow(UUID.fromString(requestId))

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

fun checkVerificationCode(requestId: String, code: String) =
fun checkVerificationCode(requestId: String, code: String): VerifyCodeResponse =
checkVerificationCode(UUID.fromString(requestId), code)

fun isValidVerificationCode(requestId: String, code: String): Boolean =
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.vonage.client.kt

import com.vonage.client.verify.*

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

fun verify(number: String, brand: String, properties: (VerifyRequest.Builder.() -> Unit) = {}): VerifyResponse =
verifyClient.verify(VerifyRequest.builder(number, brand).apply(properties).build())
Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/com/vonage/client/kt/Voice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ class Voice(private val voiceClient: VoiceClient) {

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

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

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

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

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

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

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

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

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

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

Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class VerifyLegacyTest : AbstractTest() {
fun `existing request hashCode is based on the requestId`() {
assertEquals(requestId.hashCode(), existingRequest.hashCode())
assertEquals(existingRequest, verifyClient.request(requestId))
assertEquals(existingRequest, existingRequest)
assertFalse(existingRequest.equals(requestId))
}

@Test
Expand Down

0 comments on commit abbd8f7

Please sign in to comment.