Skip to content

Commit

Permalink
feat: Add Numbers API (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani authored Aug 5, 2024
1 parent f4f1dfe commit e526c6a
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.7.0] - 2024-08-??

### Added
- Numbers API

## [0.6.0] - 2024-07-30

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You'll need to have [created a Vonage account](https://dashboard.nexmo.com/sign-
- [Voice](https://developer.vonage.com/en/voice/voice-api/overview)
- [SIM Swap](https://developer.vonage.com/en/sim-swap/overview)
- [Number Verification](https://developer.vonage.com/en/number-verification/overview)
- [Number Management](https://developer.vonage.com/en/numbers/overview)
- [Number Insight](https://developer.vonage.com/en/number-insight/overview)
- [SMS](https://developer.vonage.com/en/messaging/sms/overview)
- [Conversion](https://developer.vonage.com/en/messaging/conversion-api/overview)
Expand Down
4 changes: 2 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.6.0</version>
<version>0.7.0</version>

<name>Vonage Kotlin Server SDK</name>
<description>Kotlin client for Vonage APIs</description>
Expand Down Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>com.vonage</groupId>
<artifactId>server-sdk</artifactId>
<version>8.9.4</version>
<version>8.10.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down
41 changes: 41 additions & 0 deletions src/main/kotlin/com/vonage/client/kt/Numbers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client.kt

import com.vonage.client.numbers.*

class Numbers(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) =
numbersClient.buyNumber(countryCode, msisdn, targetApiKey)

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

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

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

fun searchAvailable(filter: SearchNumbersFilter.Builder.() -> Unit) =
numbersClient.searchNumbers(SearchNumbersFilter.builder().apply(filter).build())
}
4 changes: 1 addition & 3 deletions src/main/kotlin/com/vonage/client/kt/Voice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class Voice(private val voiceClient: VoiceClient) {

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

fun call(callId: UUID): ExistingCall = call(callId.toString())

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

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

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/vonage/client/kt/Vonage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class Vonage(init: VonageClient.Builder.() -> Unit) {
val redact = Redact(vonageClient.redactClient)
val verifyLegacy = VerifyLegacy(vonageClient.verifyClient)
val numberInsight = NumberInsight(vonageClient.insightClient)
val simSwap = SimSwap(vonageClient.simSwapClient)
val numbers = Numbers(vonageClient.numbersClient)
val numberVerification = NumberVerification(vonageClient.numberVerificationClient)
val simSwap = SimSwap(vonageClient.simSwapClient)
}

fun VonageClient.Builder.authFromEnv(): VonageClient.Builder {
Expand Down
5 changes: 5 additions & 0 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ abstract class AbstractTest {
protected val testUuid: UUID = UUID.fromString(testUuidStr)
protected val toNumber = "447712345689"
protected val altNumber = "447700900001"
protected val brand = "Nexmo KT"
protected val text = "Hello, World!"
protected val sipUri = "sip:[email protected]"
protected val clientRef = "my-personal-reference"
protected val textHexEncoded = "48656c6c6f2c20576f726c6421"
protected val entityId = "1101407360000017170"
protected val contentId = "1107158078772563946"
protected val smsMessageId = "0C000000217B7F02"
protected val callIdStr = "63f61863-4a51-4f6b-86e1-46edebcf9356"
protected val networkCode = "65512"
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/com/vonage/client/kt/MessagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class MessagesTest : AbstractTest() {

@Test
fun `send SMS text all parameters`() {
val clientRef = "My reference"
val webhookUrl = "https://example.com/status"
val ttl = 9000
val contentId = "1107457532145798767"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class NumberVerificationTest : AbstractTest() {
URLEncoder.encode(redirectUrl, "UTF-8")
}&response_type=code"

val expectedUrlWithoutState = URI.create("$expectedUrlStr&state=null")
assertEquals(expectedUrlWithoutState, nvClient.createVerificationUrl(toNumber, redirectUrl))
assertEquals(URI.create(expectedUrlStr), nvClient.createVerificationUrl(toNumber, redirectUrl))

val expectedUrlWithState = URI.create("$expectedUrlStr&state=$state")
assertEquals(expectedUrlWithState, nvClient.createVerificationUrl(toNumber, redirectUrl, state))
Expand Down
Loading

0 comments on commit e526c6a

Please sign in to comment.