Skip to content

Commit

Permalink
Add NIv1 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jul 24, 2024
1 parent b6aac91 commit 6ce4122
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 12 deletions.
21 changes: 20 additions & 1 deletion src/main/kotlin/com/vonage/client/kt/NumberInsight.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
package com.vonage.client.kt

import com.vonage.client.insight.InsightClient
import com.vonage.client.insight.*

class NumberInsight(private val niClient: InsightClient) {

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

fun standard(number: String, countryCode: String? = null, cnam: Boolean? = null): StandardInsightResponse =
niClient.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)
.number(number).country(countryCode).cnam(cnam).realTimeData(realTimeData).build()
)

/*fun advancedAsync(number: String, countryCode: String? = null, cnam: Boolean = false,
callbackUrl: String? = null) =
niClient.getAdvancedNumberInsight(AdvancedInsightRequest.builder().async(true)
.number(number).country(countryCode).cnam(cnam).callback(callbackUrl).build()
)*/
}
15 changes: 5 additions & 10 deletions src/main/kotlin/com/vonage/client/kt/Redact.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@ import com.vonage.client.redact.*

class Redact(private val redactClient: RedactClient) {

fun redactSms(messageId: String, direction: RedactRequest.Type = RedactRequest.Type.OUTBOUND) {
fun redactSms(messageId: String, direction: RedactRequest.Type = RedactRequest.Type.OUTBOUND) =
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) =
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) =
redactClient.redactTransaction(callId, RedactRequest.Product.VOICE, direction)
}

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

fun redactVerification(requestId: String) {
fun redactVerification(requestId: String) =
redactClient.redactTransaction(requestId, RedactRequest.Product.VERIFY)
}
}
119 changes: 118 additions & 1 deletion src/test/kotlin/com/vonage/client/kt/NumberInsightTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,129 @@
package com.vonage.client.kt

import com.vonage.client.insight.*
import kotlin.test.*

class NumberInsightTest : AbstractTest() {
private val niClient = vonage.numberInsight
private val cnam = true
private val realTimeData = true
private val statusMessage = "Success"
private val nationalNumber = "07712 345689"
private val countryCode = "GB"
private val countryCodeIso3 = "GBR"
private val countryName = "United Kingdom"
private val countryPrefix = "44"
private val requestPrice = "0.035900000"
private val refundPrice = "0.01500000"
private val remainingBalance = "1.23456789"
private val reachable = "reachable"


private enum class InsightType {
BASIC, STANDARD, ADVANCED
}

private fun mockInsight(type: InsightType, optionalParams: Boolean = false) {
val expectedRequestParams = mutableMapOf<String, Any>("number" to toNumber)
if (optionalParams) {
expectedRequestParams["country"] = countryCode
if (type != InsightType.BASIC) {
expectedRequestParams["cnam"] = true
}
if (type == InsightType.ADVANCED) {
expectedRequestParams["real_time_data"] = true
}
}

val expectedResponseParams = mutableMapOf(
"status" to 0,
"status_message" to statusMessage,
"request_id" to testUuidStr,
"international_format_number" to toNumber,
"national_format_number" to nationalNumber,
"country_code" to countryCode,
"country_code_iso3" to countryCodeIso3,
"country_name" to countryName,
"country_prefix" to countryPrefix
)
if (type != InsightType.BASIC) {
expectedResponseParams.putAll(mapOf(
"request_price" to requestPrice,
"refund_price" to refundPrice,
"remaining_balance" to remainingBalance,
// TODO: the rest
))
}
if (type == InsightType.ADVANCED) {
expectedResponseParams.putAll(mapOf(
"reachable" to reachable
// TODO: the rest
))
}

mockPostQueryParams(
expectedUrl = "/ni/${type.name.lowercase()}/json",
expectedRequestParams = expectedRequestParams,
expectedResponseParams = expectedResponseParams
)
}

private fun assertBasicResponse(response: BasicInsightResponse) {
assertNotNull(response)
assertEquals(InsightStatus.SUCCESS, response.status)
assertEquals(statusMessage, response.statusMessage)
assertEquals(testUuidStr, response.requestId)
assertEquals(toNumber, response.internationalFormatNumber)
assertEquals(nationalNumber, response.nationalFormatNumber)
assertEquals(countryCode, response.countryCode)
assertEquals(countryCodeIso3, response.countryCodeIso3)
assertEquals(countryName, response.countryName)
assertEquals(countryPrefix, response.countryPrefix)
}

private fun assertStandardResponse(response: StandardInsightResponse) {
assertBasicResponse(response)
// TODO
}

private fun assertAdvancedResponse(response: AdvancedInsightResponse) {
assertStandardResponse(response)
// TODO
}

@Test
fun `basic insight`() {
fun `basic insight required params`() {
mockInsight(InsightType.BASIC, false)
assertBasicResponse(niClient.basic(toNumber))
}

@Test
fun `basic insight all params`() {
mockInsight(InsightType.BASIC, true)
assertBasicResponse(niClient.basic(toNumber, countryCode))
}

@Test
fun `standard insight required params`() {
mockInsight(InsightType.STANDARD, false)
assertStandardResponse(niClient.standard(toNumber))
}

@Test
fun `standard insight all params`() {
mockInsight(InsightType.STANDARD, true)
assertStandardResponse(niClient.standard(toNumber, countryCode, cnam))
}

@Test
fun `advanced insight required params`() {
mockInsight(InsightType.ADVANCED, false)
assertStandardResponse(niClient.advanced(toNumber))
}

@Test
fun `advanced insight all params`() {
mockInsight(InsightType.ADVANCED, true)
assertStandardResponse(niClient.advanced(toNumber, countryCode, cnam, realTimeData))
}
}

0 comments on commit 6ce4122

Please sign in to comment.