Skip to content

Commit e526c6a

Browse files
authored
feat: Add Numbers API (#5)
1 parent f4f1dfe commit e526c6a

File tree

13 files changed

+335
-20
lines changed

13 files changed

+335
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.7.0] - 2024-08-??
8+
9+
### Added
10+
- Numbers API
11+
712
## [0.6.0] - 2024-07-30
813

914
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You'll need to have [created a Vonage account](https://dashboard.nexmo.com/sign-
2323
- [Voice](https://developer.vonage.com/en/voice/voice-api/overview)
2424
- [SIM Swap](https://developer.vonage.com/en/sim-swap/overview)
2525
- [Number Verification](https://developer.vonage.com/en/number-verification/overview)
26+
- [Number Management](https://developer.vonage.com/en/numbers/overview)
2627
- [Number Insight](https://developer.vonage.com/en/number-insight/overview)
2728
- [SMS](https://developer.vonage.com/en/messaging/sms/overview)
2829
- [Conversion](https://developer.vonage.com/en/messaging/conversion-api/overview)

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.vonage</groupId>
77
<artifactId>server-sdk-kotlin</artifactId>
8-
<version>0.6.0</version>
8+
<version>0.7.0</version>
99

1010
<name>Vonage Kotlin Server SDK</name>
1111
<description>Kotlin client for Vonage APIs</description>
@@ -59,7 +59,7 @@
5959
<dependency>
6060
<groupId>com.vonage</groupId>
6161
<artifactId>server-sdk</artifactId>
62-
<version>8.9.4</version>
62+
<version>8.10.0</version>
6363
</dependency>
6464
<dependency>
6565
<groupId>org.jetbrains.kotlin</groupId>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.client.kt
17+
18+
import com.vonage.client.numbers.*
19+
20+
class Numbers(private val numbersClient: NumbersClient) {
21+
22+
fun number(countryCode: String, msisdn: String) = ExistingNumber(countryCode, msisdn)
23+
24+
inner class ExistingNumber internal constructor(val countryCode: String, val msisdn: String) {
25+
26+
fun buy(targetApiKey: String? = null) =
27+
numbersClient.buyNumber(countryCode, msisdn, targetApiKey)
28+
29+
fun cancel(targetApiKey: String? = null) =
30+
numbersClient.cancelNumber(countryCode, msisdn, targetApiKey)
31+
32+
fun update(properties: UpdateNumberRequest.Builder.() -> Unit) =
33+
numbersClient.updateNumber(UpdateNumberRequest.builder(msisdn, countryCode).apply(properties).build())
34+
}
35+
36+
fun listOwned(filter: ListNumbersFilter.Builder.() -> Unit = {}) =
37+
numbersClient.listNumbers(ListNumbersFilter.builder().apply(filter).build())
38+
39+
fun searchAvailable(filter: SearchNumbersFilter.Builder.() -> Unit) =
40+
numbersClient.searchNumbers(SearchNumbersFilter.builder().apply(filter).build())
41+
}

src/main/kotlin/com/vonage/client/kt/Voice.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class Voice(private val voiceClient: VoiceClient) {
2525

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

28-
fun call(callId: UUID): ExistingCall = call(callId.toString())
29-
30-
inner class ExistingCall(val callId: String) {
28+
inner class ExistingCall internal constructor(val callId: String) {
3129

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

src/main/kotlin/com/vonage/client/kt/Vonage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ class Vonage(init: VonageClient.Builder.() -> Unit) {
2828
val redact = Redact(vonageClient.redactClient)
2929
val verifyLegacy = VerifyLegacy(vonageClient.verifyClient)
3030
val numberInsight = NumberInsight(vonageClient.insightClient)
31-
val simSwap = SimSwap(vonageClient.simSwapClient)
31+
val numbers = Numbers(vonageClient.numbersClient)
3232
val numberVerification = NumberVerification(vonageClient.numberVerificationClient)
33+
val simSwap = SimSwap(vonageClient.simSwapClient)
3334
}
3435

3536
fun VonageClient.Builder.authFromEnv(): VonageClient.Builder {

src/test/kotlin/com/vonage/client/kt/AbstractTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ abstract class AbstractTest {
5252
protected val testUuid: UUID = UUID.fromString(testUuidStr)
5353
protected val toNumber = "447712345689"
5454
protected val altNumber = "447700900001"
55+
protected val brand = "Nexmo KT"
5556
protected val text = "Hello, World!"
57+
protected val sipUri = "sip:rebekka@sip.example.com"
58+
protected val clientRef = "my-personal-reference"
5659
protected val textHexEncoded = "48656c6c6f2c20576f726c6421"
60+
protected val entityId = "1101407360000017170"
61+
protected val contentId = "1107158078772563946"
5762
protected val smsMessageId = "0C000000217B7F02"
5863
protected val callIdStr = "63f61863-4a51-4f6b-86e1-46edebcf9356"
5964
protected val networkCode = "65512"

src/test/kotlin/com/vonage/client/kt/MessagesTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class MessagesTest : AbstractTest() {
9696

9797
@Test
9898
fun `send SMS text all parameters`() {
99-
val clientRef = "My reference"
10099
val webhookUrl = "https://example.com/status"
101100
val ttl = 9000
102101
val contentId = "1107457532145798767"

src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ class NumberVerificationTest : AbstractTest() {
6262
URLEncoder.encode(redirectUrl, "UTF-8")
6363
}&response_type=code"
6464

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

6867
val expectedUrlWithState = URI.create("$expectedUrlStr&state=$state")
6968
assertEquals(expectedUrlWithState, nvClient.createVerificationUrl(toNumber, redirectUrl, state))

0 commit comments

Comments
 (0)