Skip to content

Commit

Permalink
Add Messages DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 6, 2024
1 parent c0bac85 commit da23213
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 35 deletions.
40 changes: 21 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
</distributionManagement>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -107,25 +109,6 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>1.9.20</version>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>dokka</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
Expand Down Expand Up @@ -188,6 +171,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>1.9.20</version>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>dokka</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

Expand Down
105 changes: 102 additions & 3 deletions src/main/kotlin/com/vonage/client/kt/Messages.kt
Original file line number Diff line number Diff line change
@@ -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()
}
22 changes: 9 additions & 13 deletions src/main/kotlin/com/vonage/client/kt/Vonage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}

0 comments on commit da23213

Please sign in to comment.