Skip to content

Commit

Permalink
feat: Add Application API (#8)
Browse files Browse the repository at this point in the history
* feat: Add Application API

* build: Bump GPG plugin version

* test: 401 Application endpoints
  • Loading branch information
SMadani authored Aug 16, 2024
1 parent 5a060d8 commit 86b66ad
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You'll need to have [created a Vonage account](https://dashboard.nexmo.com/sign-

## Supported APIs
- [Account](https://developer.vonage.com/en/account/overview)
- [Application](https://developer.vonage.com/en/application/overview)
- [Conversion](https://developer.vonage.com/en/messaging/conversion-api/overview)
- [Messages](https://developer.vonage.com/en/messages/overview)
- [Number Insight](https://developer.vonage.com/en/number-insight/overview)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<plugins>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.4</version>
<version>3.2.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
100 changes: 100 additions & 0 deletions src/main/kotlin/com/vonage/client/kt/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.application.*
import com.vonage.client.application.Application
import com.vonage.client.application.capabilities.*
import com.vonage.client.application.capabilities.Messages
import com.vonage.client.application.capabilities.Verify
import com.vonage.client.application.capabilities.Voice
import com.vonage.client.common.Webhook
import java.util.*

class Application internal constructor(private val client: ApplicationClient) {

fun application(applicationId: String): ExistingApplication = ExistingApplication(applicationId)

fun application(applicationId: UUID) = application(applicationId.toString())

inner class ExistingApplication internal constructor(val id: String) {
fun get(): Application = client.getApplication(id)

fun update(properties: Application.Builder.() -> Unit): Application =
client.updateApplication(Application.builder(get()).apply(properties).build())

fun delete(): Unit = client.deleteApplication(id)
}

fun listAll(): List<Application> = client.listAllApplications()

fun list(page: Int? = null, pageSize: Int? = null): List<Application> {
val filter = ListApplicationRequest.builder()
if (page != null) filter.page(page.toLong())
if (pageSize != null) filter.pageSize(pageSize.toLong())
return client.listApplications(filter.build()).applications
}

fun create(properties: Application.Builder.() -> Unit): Application =
client.createApplication(Application.builder().apply(properties).build())
}

private fun webhookBuilder(properties: Webhook.Builder.() -> Unit): Webhook =
Webhook.builder().apply(properties).build()

fun Webhook.Builder.url(url: String): Webhook.Builder = address(url)

fun Voice.Builder.answer(properties: Webhook.Builder.() -> Unit): Voice.Builder =
addWebhook(Webhook.Type.ANSWER, webhookBuilder(properties))

fun Voice.Builder.fallbackAnswer(properties: Webhook.Builder.() -> Unit): Voice.Builder =
addWebhook(Webhook.Type.FALLBACK_ANSWER, webhookBuilder(properties))

fun Voice.Builder.event(properties: Webhook.Builder.() -> Unit): Voice.Builder =
addWebhook(Webhook.Type.EVENT, webhookBuilder(properties))

fun Rtc.Builder.event(properties: Webhook.Builder.() -> Unit): Rtc.Builder =
addWebhook(Webhook.Type.EVENT, webhookBuilder(properties))

fun Verify.Builder.status(properties: Webhook.Builder.() -> Unit): Verify.Builder =
addWebhook(Webhook.Type.STATUS, webhookBuilder(properties))

fun Messages.Builder.inbound(properties: Webhook.Builder.() -> Unit): Messages.Builder =
addWebhook(Webhook.Type.INBOUND, webhookBuilder(properties))

fun Messages.Builder.status(properties: Webhook.Builder.() -> Unit): Messages.Builder =
addWebhook(Webhook.Type.STATUS, webhookBuilder(properties))

fun Application.Builder.removeCapabilities(vararg capabilities: Capability.Type): Application.Builder {
for (capability in capabilities) {
removeCapability(capability)
}
return this
}

fun Application.Builder.voice(capability: Voice.Builder.() -> Unit): Application.Builder =
addCapability(Voice.builder().apply(capability).build())

fun Application.Builder.messages(capability: Messages.Builder.() -> Unit): Application.Builder =
addCapability(Messages.builder().apply(capability).build())

fun Application.Builder.verify(capability: Verify.Builder.() -> Unit): Application.Builder =
addCapability(Verify.builder().apply(capability).build())

fun Application.Builder.rtc(capability: Rtc.Builder.() -> Unit): Application.Builder =
addCapability(Rtc.builder().apply(capability).build())

fun Application.Builder.vbc(): Application.Builder = addCapability(Vbc.builder().build())
1 change: 1 addition & 0 deletions src/main/kotlin/com/vonage/client/kt/Vonage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.vonage.client.VonageClient
class Vonage(init: VonageClient.Builder.() -> Unit) {
private val client : VonageClient = VonageClient.builder().apply(init).build()
val account = Account(client.accountClient)
val application = Application(client.applicationClient)
val conversion = Conversion(client.conversionClient)
val messages = Messages(client.messagesClient)
val numberInsight = NumberInsight(client.insightClient)
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ abstract class AbstractTest {
protected val timestamp2: Instant = Instant.parse(timestamp2Str)
protected val currency = "EUR"
protected val exampleUrlBase = "https://example.com"
protected val eventUrl = "$exampleUrlBase/event"
protected val callbackUrl = "$exampleUrlBase/callback"
protected val statusCallbackUrl = "$callbackUrl/status"
protected val moCallbackUrl = "$callbackUrl/inbound-sms"
Expand Down
Loading

0 comments on commit 86b66ad

Please sign in to comment.