From bff35372539847fc02ad41f0189b1ffb26002574 Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Fri, 7 Jun 2019 18:38:49 -0400 Subject: [PATCH] Updated Jackson version, and did a quick reformat --- .gitignore | 3 +++ build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Versions.kt | 10 ++++---- src/main/kotlin/Main.kt | 34 ++++++++++++++++++---------- 4 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b740e72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Project exclude paths +/.gradle/ +/build/ \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index c7c1d0d..84bc1a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("com.github.johnrengelman.shadow") version Versions.com_github_johnrengelman_shadow_gradle_plugin id("de.fayard.buildSrcVersions") version Versions.de_fayard_buildsrcversions_gradle_plugin - kotlin("jvm") version "1.3.21" + kotlin("jvm") version "1.3.31" application } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index c38bbeb..2ed73e4 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -7,7 +7,7 @@ import kotlin.String * * YOU are responsible for updating manually the dependency version. */ object Versions { - const val jackson_databind: String = "2.9.8" + const val jackson_databind: String = "2.9.9" const val com_github_johnrengelman_shadow_gradle_plugin: String = "5.0.0" @@ -15,9 +15,9 @@ object Versions { const val javalin: String = "2.8.0" - const val org_jetbrains_kotlin_jvm_gradle_plugin: String = "1.3.31" + const val org_jetbrains_kotlin_jvm_gradle_plugin: String = "1.3.31" - const val org_jetbrains_kotlin: String = "1.3.31" + const val org_jetbrains_kotlin: String = "1.3.31" const val slf4j_simple: String = "1.7.26" @@ -31,8 +31,8 @@ object Versions { const val currentVersion: String = "5.4.1" - const val nightlyVersion: String = "5.5-20190505000026+0000" + const val nightlyVersion: String = "5.6-20190607000159+0000" - const val releaseCandidate: String = "" + const val releaseCandidate: String = "5.5-rc-2" } } diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 0eccbf4..ce0412d 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -8,16 +8,16 @@ fun main() { val app = Javalin.create().start(7000) app.get("/") { ctx -> ctx.result("Hello World") } - app.post("/slack/receive") { - ctx -> handleSlackEvent(ctx) + app.post("/slack/receive") { ctx -> + handleSlackEvent(ctx) } - app.post("/api/v1/spongebob") { - ctx -> ctx.json(TextResponse(200, ctx.body().toSpongemock())) + app.post("/api/v1/spongebob") { ctx -> + ctx.json(TextResponse(200, ctx.body().toSpongemock())) } - app.post("/api/v1/uppercase") { - ctx -> ctx.json(TextResponse(200, ctx.body().toUpperCase())) + app.post("/api/v1/uppercase") { ctx -> + ctx.json(TextResponse(200, ctx.body().toUpperCase())) } } @@ -30,7 +30,7 @@ fun handleSlackEvent(ctx: Context) { } val responseObj = RespObj( - command = ctx.formParamMap().get("command")?.get(0).processtoCommand(), + command = ctx.formParamMap().get("command")?.get(0).processToCommand(), text = ctx.formParamMap().get("text")?.get(0) ?: "", response_url = ctx.formParamMap().get("response_url")?.get(0) ?: "", team_id = ctx.formParamMap().get("team_id")?.get(0) ?: "", @@ -40,7 +40,7 @@ fun handleSlackEvent(ctx: Context) { sendResponse(ctx, responseObj) } -private fun String?.processtoCommand(): Commands { +private fun String?.processToCommand(): Commands { return when (this) { "/spongemock2" -> Commands.Spongebob "/uppercase" -> Commands.Uppercase @@ -52,9 +52,15 @@ fun sendResponse(ctx: Context, respObj: RespObj) { val returnMap = mutableMapOf() with(returnMap) { when (respObj.command) { - Commands.Spongebob -> {put("text", respObj.text.toSpongemock()); put("response_type", "in_channel")} - Commands.Uppercase -> {put("text", respObj.text.toUpperCase()); put("response_type", "in_channel")} - Commands.Error -> {put("text", respObj.text); put("response_type", "ephemeral")} + Commands.Spongebob -> { + put("text", respObj.text.toSpongemock()); put("response_type", "in_channel") + } + Commands.Uppercase -> { + put("text", respObj.text.toUpperCase()); put("response_type", "in_channel") + } + Commands.Error -> { + put("text", respObj.text); put("response_type", "ephemeral") + } } } @@ -64,7 +70,11 @@ fun sendResponse(ctx: Context, respObj: RespObj) { data class TextResponse(val status: Int, val response: String) private fun String.toSpongemock(): String { - return this.mapIndexed { index, c -> if (!index.isOdd()) { c.toUpperCase() } else c }.joinToString(separator = "") + return this.mapIndexed { index, c -> + if (!index.isOdd()) { + c.toUpperCase() + } else c + }.joinToString(separator = "") } private fun Int.isOdd(): Boolean = this.rem(2) == 0 \ No newline at end of file