Skip to content

Commit

Permalink
refactor: Concise MessageRequest builder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Jun 28, 2024
1 parent c350dad commit 930267e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 79 deletions.
129 changes: 51 additions & 78 deletions src/main/kotlin/com/vonage/client/kt/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,106 +16,79 @@ class Messages(private val client: MessagesClient) {
client.useSandboxEndpoint().sendMessage(message).messageUuid
}

fun parseInboundMessage(json: String) : InboundMessage {
return InboundMessage.fromJson(json)
}
fun parseInboundMessage(json: String) : InboundMessage = InboundMessage.fromJson(json)

fun smsText(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest {
return SmsTextRequest.builder().apply(init).build()
}
fun smsText(init: SmsTextRequest.Builder.() -> Unit): SmsTextRequest =
SmsTextRequest.builder().apply(init).build()

fun mmsVcard(init: MmsVcardRequest.Builder.() -> Unit): MmsVcardRequest {
return MmsVcardRequest.builder().apply(init).build()
}
fun mmsVcard(init: MmsVcardRequest.Builder.() -> Unit): MmsVcardRequest =
MmsVcardRequest.builder().apply(init).build()

fun mmsImage(init: MmsImageRequest.Builder.() -> Unit): MmsImageRequest {
return MmsImageRequest.builder().apply(init).build()
}
fun mmsImage(init: MmsImageRequest.Builder.() -> Unit): MmsImageRequest =
MmsImageRequest.builder().apply(init).build()

fun mmsAudio(init: MmsAudioRequest.Builder.() -> Unit): MmsAudioRequest {
return MmsAudioRequest.builder().apply(init).build()
}
fun mmsAudio(init: MmsAudioRequest.Builder.() -> Unit): MmsAudioRequest =
MmsAudioRequest.builder().apply(init).build()

fun mmsVideo(init: MmsVideoRequest.Builder.() -> Unit): MmsVideoRequest {
return MmsVideoRequest.builder().apply(init).build()
}
fun mmsVideo(init: MmsVideoRequest.Builder.() -> Unit): MmsVideoRequest =
MmsVideoRequest.builder().apply(init).build()

fun whatsappText(init: WhatsappTextRequest.Builder.() -> Unit): WhatsappTextRequest {
return WhatsappTextRequest.builder().apply(init).build()
}
fun whatsappText(init: WhatsappTextRequest.Builder.() -> Unit): WhatsappTextRequest =
WhatsappTextRequest.builder().apply(init).build()

fun whatsappImage(init: WhatsappImageRequest.Builder.() -> Unit): WhatsappImageRequest {
return WhatsappImageRequest.builder().apply(init).build()
}
fun whatsappImage(init: WhatsappImageRequest.Builder.() -> Unit): WhatsappImageRequest =
WhatsappImageRequest.builder().apply(init).build()

fun whatsappAudio(init: WhatsappAudioRequest.Builder.() -> Unit): WhatsappAudioRequest {
return WhatsappAudioRequest.builder().apply(init).build()
}
fun whatsappAudio(init: WhatsappAudioRequest.Builder.() -> Unit): WhatsappAudioRequest =
WhatsappAudioRequest.builder().apply(init).build()

fun whatsappVideo(init: WhatsappVideoRequest.Builder.() -> Unit): WhatsappVideoRequest {
return WhatsappVideoRequest.builder().apply(init).build()
}
fun whatsappVideo(init: WhatsappVideoRequest.Builder.() -> Unit): WhatsappVideoRequest =
WhatsappVideoRequest.builder().apply(init).build()

fun whatsappFile(init: WhatsappFileRequest.Builder.() -> Unit): WhatsappFileRequest {
return WhatsappFileRequest.builder().apply(init).build()
}
fun whatsappFile(init: WhatsappFileRequest.Builder.() -> Unit): WhatsappFileRequest =
WhatsappFileRequest.builder().apply(init).build()

fun whatsappSticker(init: WhatsappStickerRequest.Builder.() -> Unit): WhatsappStickerRequest {
return WhatsappStickerRequest.builder().apply(init).build()
}
fun whatsappSticker(init: WhatsappStickerRequest.Builder.() -> Unit): WhatsappStickerRequest =
WhatsappStickerRequest.builder().apply(init).build()

fun whatsappLocation(init: WhatsappLocationRequest.Builder.() -> Unit): WhatsappLocationRequest {
return WhatsappLocationRequest.builder().apply(init).build()
}
fun whatsappLocation(init: WhatsappLocationRequest.Builder.() -> Unit): WhatsappLocationRequest =
WhatsappLocationRequest.builder().apply(init).build()

fun whatsappSingleProduct(init: WhatsappSingleProductRequest.Builder.() -> Unit): WhatsappSingleProductRequest {
return WhatsappSingleProductRequest.builder().apply(init).build()
}
fun whatsappSingleProduct(init: WhatsappSingleProductRequest.Builder.() -> Unit): WhatsappSingleProductRequest =
WhatsappSingleProductRequest.builder().apply(init).build()

fun whatsappMultiProduct(init: WhatsappMultiProductRequest.Builder.() -> Unit): WhatsappMultiProductRequest {
return WhatsappMultiProductRequest.builder().apply(init).build()
}
fun whatsappMultiProduct(init: WhatsappMultiProductRequest.Builder.() -> Unit): WhatsappMultiProductRequest =
WhatsappMultiProductRequest.builder().apply(init).build()

fun whatsappTemplate(init: WhatsappTemplateRequest.Builder.() -> Unit): WhatsappTemplateRequest {
return WhatsappTemplateRequest.builder().apply(init).build()
}
fun whatsappTemplate(init: WhatsappTemplateRequest.Builder.() -> Unit): WhatsappTemplateRequest =
WhatsappTemplateRequest.builder().apply(init).build()

fun whatsappCustom(init: WhatsappCustomRequest.Builder.() -> Unit): WhatsappCustomRequest {
return WhatsappCustomRequest.builder().apply(init).build()
}
fun whatsappCustom(init: WhatsappCustomRequest.Builder.() -> Unit): WhatsappCustomRequest =
WhatsappCustomRequest.builder().apply(init).build()

fun messengerText(init: MessengerTextRequest.Builder.() -> Unit): MessengerTextRequest {
return MessengerTextRequest.builder().apply(init).build()
}
fun messengerText(init: MessengerTextRequest.Builder.() -> Unit): MessengerTextRequest =
MessengerTextRequest.builder().apply(init).build()

fun messengerImage(init: MessengerImageRequest.Builder.() -> Unit): MessengerImageRequest {
return MessengerImageRequest.builder().apply(init).build()
}
fun messengerImage(init: MessengerImageRequest.Builder.() -> Unit): MessengerImageRequest =
MessengerImageRequest.builder().apply(init).build()

fun messengerAudio(init: MessengerAudioRequest.Builder.() -> Unit): MessengerAudioRequest {
return MessengerAudioRequest.builder().apply(init).build()
}
fun messengerAudio(init: MessengerAudioRequest.Builder.() -> Unit): MessengerAudioRequest =
MessengerAudioRequest.builder().apply(init).build()

fun messengerVideo(init: MessengerVideoRequest.Builder.() -> Unit): MessengerVideoRequest {
return MessengerVideoRequest.builder().apply(init).build()
}
fun messengerVideo(init: MessengerVideoRequest.Builder.() -> Unit): MessengerVideoRequest =
MessengerVideoRequest.builder().apply(init).build()

fun messengerFile(init: MessengerFileRequest.Builder.() -> Unit): MessengerFileRequest {
return MessengerFileRequest.builder().apply(init).build()
}
fun messengerFile(init: MessengerFileRequest.Builder.() -> Unit): MessengerFileRequest =
MessengerFileRequest.builder().apply(init).build()

fun viberText(init: ViberTextRequest.Builder.() -> Unit): ViberTextRequest {
return ViberTextRequest.builder().apply(init).build()
}
fun viberText(init: ViberTextRequest.Builder.() -> Unit): ViberTextRequest =
ViberTextRequest.builder().apply(init).build()

fun viberImage(init: ViberImageRequest.Builder.() -> Unit): ViberImageRequest {
return ViberImageRequest.builder().apply(init).build()
}
fun viberImage(init: ViberImageRequest.Builder.() -> Unit): ViberImageRequest =
ViberImageRequest.builder().apply(init).build()

fun viberVideo(init: ViberVideoRequest.Builder.() -> Unit): ViberVideoRequest {
return ViberVideoRequest.builder().apply(init).build()
}
fun viberVideo(init: ViberVideoRequest.Builder.() -> Unit): ViberVideoRequest =
ViberVideoRequest.builder().apply(init).build()

fun viberFile(init: ViberFileRequest.Builder.() -> Unit): ViberFileRequest {
return ViberFileRequest.builder().apply(init).build()
}
fun viberFile(init: ViberFileRequest.Builder.() -> Unit): ViberFileRequest =
ViberFileRequest.builder().apply(init).build()
2 changes: 1 addition & 1 deletion src/test/kotlin/com/vonage/client/kt/VoiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class VoiceTest : AbstractTest() {
"direction" to "inbound",
"rate" to rate,
"price" to price,
"duration" to "$duration",
"duration" to duration,
"start_time" to startTime,
"end_time" to endTime,
"network" to networkCode
Expand Down

0 comments on commit 930267e

Please sign in to comment.