From 527530e89d1acf50ef813c868c5e36afa8650698 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 5 Mar 2020 22:49:24 -0800 Subject: [PATCH] Added toJson(). --- README.md | 2 +- examples/src/main/kotlin/com/example/AkismetServlet.kt | 2 +- .../kotlin/net/thauvin/erik/akismet/AkismetComment.kt | 9 +++++++++ src/test/kotlin/net/thauvin/erik/akismet/AkismetTest.kt | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f4accbf..5abef53 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ This will ensure that the user's IP, agent, referrer and various environment var Since comments mis-identified as spam or ham can be submitted to Askimet to improve the service. A comment can be saved as a JSON object to be stored in a database, etc. ```kotlin -var json = comment.toString() +var json = comment.toJson() ``` At a latter time, the comment can the be submitted: diff --git a/examples/src/main/kotlin/com/example/AkismetServlet.kt b/examples/src/main/kotlin/com/example/AkismetServlet.kt index 5cee89e..307ed23 100644 --- a/examples/src/main/kotlin/com/example/AkismetServlet.kt +++ b/examples/src/main/kotlin/com/example/AkismetServlet.kt @@ -38,7 +38,7 @@ class AkismetServlet : HttpServlet() { email = comment.authorEmail, date = comment.dateGmt, comment = comment.content, - json = comment.toString(), + json = comment.toJson(), isSpam = isSpam ) diff --git a/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt b/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt index e332a31..9f42b40 100644 --- a/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt +++ b/src/main/kotlin/net/thauvin/erik/akismet/AkismetComment.kt @@ -234,6 +234,15 @@ open class AkismetComment(val userIp: String, val userAgent: String) { serverEnv = buildServerEnv(request) } + /** + * Returns a JSON representation of the comment. + * + * @see [Akismet.jsonComment] + */ + fun toJson(): String { + return toString() + } + /** * Returns a JSON representation of the comment. * diff --git a/src/test/kotlin/net/thauvin/erik/akismet/AkismetTest.kt b/src/test/kotlin/net/thauvin/erik/akismet/AkismetTest.kt index 6ad6f29..63a040f 100644 --- a/src/test/kotlin/net/thauvin/erik/akismet/AkismetTest.kt +++ b/src/test/kotlin/net/thauvin/erik/akismet/AkismetTest.kt @@ -130,7 +130,7 @@ class AkismetTest { isTest = true } - akismet.logger.info(mockComment.toString()) + akismet.logger.info(mockComment.toJson()) } @Test