From da23213e6fed22f8552a6938a67301139aef290e Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 6 Jun 2024 13:16:44 +0100 Subject: [PATCH] Add Messages DSL --- pom.xml | 40 +++---- .../kotlin/com/vonage/client/kt/Messages.kt | 105 +++++++++++++++++- .../kotlin/com/vonage/client/kt/Vonage.kt | 22 ++-- 3 files changed, 132 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index cea3967..b6ec0d1 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,8 @@ + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin org.apache.maven.plugins @@ -107,25 +109,6 @@ - - kotlin-maven-plugin - org.jetbrains.kotlin - ${kotlin.version} - true - - - org.jetbrains.dokka - dokka-maven-plugin - 1.9.20 - - - pre-site - - dokka - - - - maven-source-plugin 3.3.1 @@ -188,6 +171,25 @@ + + org.jetbrains.dokka + dokka-maven-plugin + 1.9.20 + + + pre-site + + dokka + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + true + diff --git a/src/main/kotlin/com/vonage/client/kt/Messages.kt b/src/main/kotlin/com/vonage/client/kt/Messages.kt index c2f068c..5a3ad47 100644 --- a/src/main/kotlin/com/vonage/client/kt/Messages.kt +++ b/src/main/kotlin/com/vonage/client/kt/Messages.kt @@ -1,12 +1,111 @@ -package org.example.com.vonage.client.kt +package com.vonage.client.kt -import com.vonage.client.messages.sms.SmsTextRequest -import com.vonage.client.messages.whatsapp.WhatsappTextRequest +import com.vonage.client.messages.* +import com.vonage.client.messages.sms.* +import com.vonage.client.messages.mms.* +import com.vonage.client.messages.whatsapp.* +import com.vonage.client.messages.messenger.* +import com.vonage.client.messages.viber.* +import java.util.UUID + +class Messages (private val messagesClient: MessagesClient) { + fun send(message : MessageRequest) : UUID { + return messagesClient.sendMessage(message).messageUuid + } +} fun sms(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest { return SmsTextRequest.builder().apply(init).build() } +fun vcard(init: MmsVcardRequest.Builder.() -> Unit): MmsVcardRequest { + return MmsVcardRequest.builder().apply(init).build() +} + +fun mmsImage(init: MmsImageRequest.Builder.() -> Unit): MmsImageRequest { + return MmsImageRequest.builder().apply(init).build() +} + +fun mmsAudio(init: MmsAudioRequest.Builder.() -> Unit): MmsAudioRequest { + return MmsAudioRequest.builder().apply(init).build() +} + +fun mmsVideo(init: MmsVideoRequest.Builder.() -> Unit): MmsVideoRequest { + return MmsVideoRequest.builder().apply(init).build() +} + fun whatsappText(init: WhatsappTextRequest.Builder.() -> Unit): WhatsappTextRequest { return WhatsappTextRequest.builder().apply(init).build() +} + +fun whatsappImage(init: WhatsappImageRequest.Builder.() -> Unit): WhatsappImageRequest { + return WhatsappImageRequest.builder().apply(init).build() +} + +fun whatsappAudio(init: WhatsappAudioRequest.Builder.() -> Unit): WhatsappAudioRequest { + return WhatsappAudioRequest.builder().apply(init).build() +} + +fun whatsappVideo(init: WhatsappVideoRequest.Builder.() -> Unit): WhatsappVideoRequest { + return WhatsappVideoRequest.builder().apply(init).build() +} + +fun whatsappFile(init: WhatsappFileRequest.Builder.() -> Unit): WhatsappFileRequest { + return WhatsappFileRequest.builder().apply(init).build() +} + +fun whatsappSticker(init: WhatsappStickerRequest.Builder.() -> Unit): WhatsappStickerRequest { + return WhatsappStickerRequest.builder().apply(init).build() +} + +fun whatsappLocation(init: WhatsappLocationRequest.Builder.() -> Unit): WhatsappLocationRequest { + return WhatsappLocationRequest.builder().apply(init).build() +} + +fun whatsappSingleProduct(init: WhatsappSingleProductRequest.Builder.() -> Unit): WhatsappSingleProductRequest { + return WhatsappSingleProductRequest.builder().apply(init).build() +} + +fun whatsappMultiProduct(init: WhatsappMultiProductRequest.Builder.() -> Unit): WhatsappMultiProductRequest { + return WhatsappMultiProductRequest.builder().apply(init).build() +} + +fun whatsappTemplate(init: WhatsappTemplateRequest.Builder.() -> Unit): WhatsappTemplateRequest { + return WhatsappTemplateRequest.builder().apply(init).build() +} + +fun messengerText(init: MessengerTextRequest.Builder.() -> Unit): MessengerTextRequest { + return MessengerTextRequest.builder().apply(init).build() +} + +fun messengerImage(init: MessengerImageRequest.Builder.() -> Unit): MessengerImageRequest { + return MessengerImageRequest.builder().apply(init).build() +} + +fun messengerAudio(init: MessengerAudioRequest.Builder.() -> Unit): MessengerAudioRequest { + return MessengerAudioRequest.builder().apply(init).build() +} + +fun messengerVideo(init: MessengerVideoRequest.Builder.() -> Unit): MessengerVideoRequest { + return MessengerVideoRequest.builder().apply(init).build() +} + +fun messengerFile(init: MessengerFileRequest.Builder.() -> Unit): MessengerFileRequest { + return MessengerFileRequest.builder().apply(init).build() +} + +fun viberText(init: ViberTextRequest.Builder.() -> Unit): ViberTextRequest { + return ViberTextRequest.builder().apply(init).build() +} + +fun viberImage(init: ViberImageRequest.Builder.() -> Unit): ViberImageRequest { + return ViberImageRequest.builder().apply(init).build() +} + +fun viberVideo(init: ViberVideoRequest.Builder.() -> Unit): ViberVideoRequest { + return ViberVideoRequest.builder().apply(init).build() +} + +fun viberFile(init: ViberFileRequest.Builder.() -> Unit): ViberFileRequest { + return ViberFileRequest.builder().apply(init).build() } \ No newline at end of file diff --git a/src/main/kotlin/com/vonage/client/kt/Vonage.kt b/src/main/kotlin/com/vonage/client/kt/Vonage.kt index 6a0cec4..0af2c7e 100644 --- a/src/main/kotlin/com/vonage/client/kt/Vonage.kt +++ b/src/main/kotlin/com/vonage/client/kt/Vonage.kt @@ -2,22 +2,12 @@ package org.example.com.vonage.client.kt import com.vonage.client.HttpConfig import com.vonage.client.VonageClient -import com.vonage.client.messages.MessageRequest -import com.vonage.client.verify2.Verify2Client -import java.time.Instant -import java.util.* +import com.vonage.client.kt.Messages class Vonage constructor(init: VonageClient.Builder.() -> Unit) { private val vonageClient : VonageClient = VonageClient.builder().apply(init).build(); - val verify: Verify2Client = vonageClient.verify2Client - - fun sendMessage(request: MessageRequest) : UUID { - return vonageClient.messagesClient.sendMessage(request).messageUuid - } - - fun simSwapDate(phoneNumber: String): Instant { - return vonageClient.simSwapClient.retrieveSimSwapDate(phoneNumber) - } + val verify = vonageClient.verify2Client + val messages = Messages(vonageClient.messagesClient) } fun VonageClient.Builder.authFromEnv() : VonageClient.Builder { @@ -35,4 +25,10 @@ fun httpConfig(init: HttpConfig.Builder.() -> Unit): HttpConfig { private fun env(variable : String) : String { return System.getenv(variable) +} + +fun main() { + val client = Vonage { + authFromEnv() + } } \ No newline at end of file