Added a data class for the comment types
This commit is contained in:
parent
156d85fee1
commit
0480a72c30
100 changed files with 1760 additions and 343 deletions
|
@ -174,6 +174,9 @@ public class AkismetBuild extends Project {
|
|||
+ "/tree/master/src/main/kotlin/", "#L")
|
||||
.includes("config/dokka/packages.md")
|
||||
.jdkVersion(javaRelease)
|
||||
.externalDocumentationLinks("https://jakarta.ee/specifications/platform/9/apidocs/",
|
||||
"https://jakarta.ee/specifications/platform/9/apidocs/package-list")
|
||||
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
@ -207,6 +210,8 @@ public class AkismetBuild extends Project {
|
|||
.moduleVersion(version.toString())
|
||||
.outputDir(new File(buildDirectory(), "javadoc"))
|
||||
.outputFormat(OutputFormat.JAVADOC)
|
||||
.globalLinks("https://jakarta.ee/specifications/platform/9/apidocs/",
|
||||
"https://jakarta.ee/specifications/platform/9/apidocs/package-list")
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -395,8 +395,8 @@ open class Akismet(apiKey: String) {
|
|||
if (!permalink.isNullOrBlank()) {
|
||||
add("permalink", permalink.toString())
|
||||
}
|
||||
if (!type.isNullOrBlank()) {
|
||||
add("comment_type", type.toString())
|
||||
if (type != CommentType.NONE) {
|
||||
add("comment_type", type.value)
|
||||
}
|
||||
if (!author.isNullOrBlank()) {
|
||||
add("comment_author", author.toString())
|
||||
|
|
|
@ -58,47 +58,23 @@ private fun String?.ifNull() = this ?: ""
|
|||
@Serializable
|
||||
open class AkismetComment(val userIp: String, val userAgent: String) {
|
||||
companion object {
|
||||
/** A blog comment. */
|
||||
const val TYPE_COMMENT = "comment"
|
||||
|
||||
/** A top-level forum post. */
|
||||
const val TYPE_FORUM_POST = "forum-post"
|
||||
|
||||
/** A reply to a top-level forum post. */
|
||||
const val TYPE_REPLY = "reply"
|
||||
|
||||
/** A blog post. */
|
||||
const val TYPE_BLOG_POST = "blog-post"
|
||||
|
||||
/** A contact form or feedback form submission. */
|
||||
const val TYPE_CONTACT_FORM = "contact-form"
|
||||
|
||||
/** A new user account. */
|
||||
const val TYPE_SIGNUP = "signup"
|
||||
|
||||
/** A message sent between just a few users. */
|
||||
const val TYPE_MESSAGE = "message"
|
||||
|
||||
/** A pingback. */
|
||||
const val TYPE_PINGBACK = "pingback"
|
||||
|
||||
/** A trackback. */
|
||||
const val TYPE_TRACKBACK = "trackback"
|
||||
|
||||
/** A Twitter message. */
|
||||
const val TYPE_TWEET = "tweet"
|
||||
|
||||
/** Administrator role. If used, Akismet will always return false. */
|
||||
/**
|
||||
* Administrator role. If used, Akismet will always return `false`.
|
||||
*/
|
||||
const val ADMIN_ROLE = "administrator"
|
||||
}
|
||||
|
||||
/** The content of the referer header should be set here. */
|
||||
/**
|
||||
* The content of the referer header should be set here.
|
||||
*/
|
||||
var referrer: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
}
|
||||
|
||||
/** The full permanent URL of the entry the comment was submitted to. */
|
||||
/**
|
||||
* The full permanent URL of the entry the comment was submitted to.
|
||||
*/
|
||||
var permalink: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
|
@ -107,45 +83,50 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
|
|||
/**
|
||||
* A string that describes the type of content being sent, such as:
|
||||
*
|
||||
* - [TYPE_COMMENT]
|
||||
* - [TYPE_FORUM_POST]
|
||||
* - [TYPE_REPLY]
|
||||
* - [TYPE_BLOG_POST]
|
||||
* - [TYPE_CONTACT_FORM]
|
||||
* - [TYPE_SIGNUP]
|
||||
* - [TYPE_MESSAGE]
|
||||
* - [TYPE_PINGBACK]
|
||||
* - [TYPE_TRACKBACK]
|
||||
* - [TYPE_TWEET]
|
||||
* - [CommentType.COMMENT]
|
||||
* - [CommentType.FORUM_POST]
|
||||
* - [CommentType.REPLY]
|
||||
* - [CommentType.BLOG_POST]
|
||||
* - [CommentType.CONTACT_FORM]
|
||||
* - [CommentType.SIGNUP]
|
||||
* - [CommentType.MESSAGE]
|
||||
* - [CommentType.PINGBACK]
|
||||
* - [CommentType.TRACKBACK]
|
||||
* - [CommentType.TWEET]
|
||||
*
|
||||
* You may send a value not listed above if none of them accurately describe your content.
|
||||
*
|
||||
* This is further explained [here](http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/).
|
||||
*/
|
||||
var type: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
}
|
||||
var type: CommentType = CommentType.NONE
|
||||
|
||||
/** Name submitted with the comment. */
|
||||
/**
|
||||
* Name submitted with the comment.
|
||||
*/
|
||||
var author: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
}
|
||||
|
||||
/** Email address submitted with the comment. */
|
||||
/**
|
||||
* Email address submitted with the comment.
|
||||
*/
|
||||
var authorEmail: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
}
|
||||
|
||||
/** URL submitted with comment. */
|
||||
/**
|
||||
* URL submitted with comment.
|
||||
*/
|
||||
var authorUrl: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
}
|
||||
|
||||
/** The content that was submitted. */
|
||||
/**
|
||||
* The content that was submitted.
|
||||
*/
|
||||
var content: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
|
@ -194,14 +175,16 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
|
|||
/**
|
||||
* The user role of the user who submitted the comment. This is an optional parameter.
|
||||
*
|
||||
* If you set it to [ADMIN_ROLE], Akismet will always return false.
|
||||
* If you set it to [ADMIN_ROLE], Akismet will always return `false`.
|
||||
*/
|
||||
var userRole: String? = ""
|
||||
set(value) {
|
||||
field = value.ifNull()
|
||||
}
|
||||
|
||||
/** This is an optional parameter. You can use it when submitting test queries to Akismet. */
|
||||
/**
|
||||
* This is an optional parameter. You can use it when submitting test queries to Akismet.
|
||||
*/
|
||||
var isTest: Boolean = false
|
||||
|
||||
/**
|
||||
|
@ -230,8 +213,7 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
|
|||
* Creates a new instance extracting the [userIp], [userAgent], [referrer] and [serverEnv] environment variables
|
||||
* from a Servlet request.
|
||||
*
|
||||
* See the
|
||||
* [Akismet API](https://akismet.com/development/api/#comment-check) for more details.
|
||||
* See the [Akismet API](https://akismet.com/development/api/#comment-check) for more details.
|
||||
*
|
||||
* @see [serverEnv]
|
||||
*/
|
||||
|
|
|
@ -32,16 +32,6 @@
|
|||
package net.thauvin.erik.akismet
|
||||
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.ADMIN_ROLE
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_BLOG_POST
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_COMMENT
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_CONTACT_FORM
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_FORUM_POST
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_MESSAGE
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_PINGBACK
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_REPLY
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_SIGNUP
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_TRACKBACK
|
||||
import net.thauvin.erik.akismet.AkismetComment.Companion.TYPE_TWEET
|
||||
|
||||
/**
|
||||
* Provides a comment configuration.
|
||||
|
@ -54,7 +44,7 @@ class CommentConfig @JvmOverloads constructor(
|
|||
var userAgent: String,
|
||||
var referrer: String = "",
|
||||
var permalink: String = "",
|
||||
var type: String = "",
|
||||
var type: CommentType = CommentType.NONE,
|
||||
var author: String = "",
|
||||
var authorEmail: String = "",
|
||||
var authorUrl: String = "",
|
||||
|
@ -96,7 +86,7 @@ class CommentConfig @JvmOverloads constructor(
|
|||
data class Builder(var userIp: String, var userAgent: String) {
|
||||
var referrer = ""
|
||||
var permalink = ""
|
||||
var type = ""
|
||||
var type: CommentType = CommentType.NONE
|
||||
var author = ""
|
||||
var authorEmail = ""
|
||||
var authorUrl = ""
|
||||
|
@ -113,12 +103,12 @@ class CommentConfig @JvmOverloads constructor(
|
|||
/**
|
||||
* Sets the IP address of the comment submitter.
|
||||
*/
|
||||
fun userIp(userIp: String) : Builder = apply { this.userIp = userIp }
|
||||
fun userIp(userIp: String): Builder = apply { this.userIp = userIp }
|
||||
|
||||
/**
|
||||
* Sets the user agent string of the web browser submitting the comment.
|
||||
*/
|
||||
fun userAgent(userAgent: String) : Builder = apply { this.userAgent = userAgent }
|
||||
fun userAgent(userAgent: String): Builder = apply { this.userAgent = userAgent }
|
||||
|
||||
/**
|
||||
* Sets the content of the referrer header.
|
||||
|
@ -133,22 +123,22 @@ class CommentConfig @JvmOverloads constructor(
|
|||
/**
|
||||
* Sets a string that describes the type of content being sent, such as:
|
||||
*
|
||||
* - [TYPE_COMMENT]
|
||||
* - [TYPE_FORUM_POST]
|
||||
* - [TYPE_REPLY]
|
||||
* - [TYPE_BLOG_POST]
|
||||
* - [TYPE_CONTACT_FORM]
|
||||
* - [TYPE_SIGNUP]
|
||||
* - [TYPE_MESSAGE]
|
||||
* - [TYPE_PINGBACK]
|
||||
* - [TYPE_TRACKBACK]
|
||||
* - [TYPE_TWEET]
|
||||
* - [CommentType.COMMENT]
|
||||
* - [CommentType.FORUM_POST]
|
||||
* - [CommentType.REPLY]
|
||||
* - [CommentType.BLOG_POST]
|
||||
* - [CommentType.CONTACT_FORM]
|
||||
* - [CommentType.SIGNUP]
|
||||
* - [CommentType.MESSAGE]
|
||||
* - [CommentType.PINGBACK]
|
||||
* - [CommentType.TRACKBACK]
|
||||
* - [CommentType.TWEET]
|
||||
*
|
||||
* You may send a value not listed above if none of them accurately describe your content.
|
||||
*
|
||||
* This is further explained [here](http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/).
|
||||
*/
|
||||
fun type(type: String): Builder = apply { this.type = type }
|
||||
fun type(type: CommentType): Builder = apply { this.type = type }
|
||||
|
||||
/**
|
||||
* Sets the mame submitted with the comment.
|
||||
|
@ -184,7 +174,7 @@ class CommentConfig @JvmOverloads constructor(
|
|||
*
|
||||
* @see [Akismet.dateToGmt]
|
||||
*/
|
||||
fun postModifiedGmt(postModifiedGmt: String) = apply { this.postModifiedGmt = postModifiedGmt }
|
||||
fun postModifiedGmt(postModifiedGmt: String): Builder = apply { this.postModifiedGmt = postModifiedGmt }
|
||||
|
||||
/**
|
||||
* Indicates the language(s) in use on the blog or site, in ISO 639-1 format, comma-separated.
|
||||
|
@ -201,7 +191,7 @@ class CommentConfig @JvmOverloads constructor(
|
|||
/**
|
||||
* Set the user role of the user who submitted the comment. This is an optional parameter.
|
||||
*
|
||||
* If you set it to [ADMIN_ROLE], Akismet will always return false.
|
||||
* If you set it to [ADMIN_ROLE], Akismet will always return `false`.
|
||||
*/
|
||||
fun userRole(userRole: String): Builder = apply { this.userRole = userRole }
|
||||
|
||||
|
|
107
src/main/kotlin/net/thauvin/erik/akismet/CommentType.kt
Normal file
107
src/main/kotlin/net/thauvin/erik/akismet/CommentType.kt
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* CommentType.kt
|
||||
*
|
||||
* Copyright 2019-2024 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.akismet
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Defines the comment types.
|
||||
*/
|
||||
@Serializable
|
||||
data class CommentType(var value: String) {
|
||||
companion object {
|
||||
/**
|
||||
* A blog comment.
|
||||
*/
|
||||
@JvmField
|
||||
val COMMENT = CommentType("comment")
|
||||
|
||||
/**
|
||||
* A top-level forum post.
|
||||
*/
|
||||
@JvmField
|
||||
val FORUM_POST = CommentType("forum-post")
|
||||
|
||||
/**
|
||||
* A reply to a top-level forum post.
|
||||
*/
|
||||
@JvmField
|
||||
val REPLY = CommentType("reply")
|
||||
|
||||
/**
|
||||
* A blog post.
|
||||
*/
|
||||
@JvmField
|
||||
val BLOG_POST = CommentType("blog-post")
|
||||
|
||||
/**
|
||||
* A contact form or feedback form submission.
|
||||
*/
|
||||
@JvmField
|
||||
val CONTACT_FORM = CommentType("contact-form")
|
||||
|
||||
/** A new user account.
|
||||
*/
|
||||
@JvmField
|
||||
val SIGNUP = CommentType("signup")
|
||||
|
||||
/**
|
||||
* A message sent between just a few users.
|
||||
*/
|
||||
@JvmField
|
||||
val MESSAGE = CommentType("message")
|
||||
|
||||
/**
|
||||
* A pingback.
|
||||
*/
|
||||
@JvmField
|
||||
val PINGBACK = CommentType("pingback")
|
||||
|
||||
/**
|
||||
* A trackback.
|
||||
*/
|
||||
@JvmField
|
||||
val TRACKBACK = CommentType("trackback")
|
||||
|
||||
/**
|
||||
* A Twitter message.
|
||||
*/
|
||||
@JvmField
|
||||
val TWEET = CommentType("tweet")
|
||||
|
||||
/**
|
||||
* Undefined type.
|
||||
*/
|
||||
@JvmField
|
||||
val NONE = CommentType("")
|
||||
}
|
||||
}
|
|
@ -169,7 +169,7 @@ class AkismetTest {
|
|||
prop(AkismetComment::isTest).isFalse()
|
||||
prop(AkismetComment::referrer).isEqualTo("")
|
||||
prop(AkismetComment::permalink).isEqualTo("")
|
||||
prop(AkismetComment::type).isEqualTo("")
|
||||
prop(AkismetComment::type).isEqualTo(CommentType.NONE)
|
||||
prop(AkismetComment::authorEmail).isEqualTo("")
|
||||
prop(AkismetComment::author).isEqualTo("")
|
||||
prop(AkismetComment::authorUrl).isEqualTo("")
|
||||
|
@ -183,11 +183,11 @@ class AkismetTest {
|
|||
prop(AkismetComment::serverEnv).size().isEqualTo(0)
|
||||
}
|
||||
|
||||
with(empty) {
|
||||
with(receiver = empty) {
|
||||
for (s in listOf("test", "", null)) {
|
||||
referrer = s
|
||||
permalink = s
|
||||
type = s
|
||||
if (s != null) type = CommentType(s)
|
||||
authorEmail = s
|
||||
author = s
|
||||
authorUrl = s
|
||||
|
@ -204,7 +204,7 @@ class AkismetTest {
|
|||
assertThat(empty, "AkismetComment($s)").all {
|
||||
prop(AkismetComment::referrer).isEqualTo(expected)
|
||||
prop(AkismetComment::permalink).isEqualTo(expected)
|
||||
prop(AkismetComment::type).isEqualTo(expected)
|
||||
prop(AkismetComment::type).isEqualTo(CommentType(expected))
|
||||
prop(AkismetComment::authorEmail).isEqualTo(expected)
|
||||
prop(AkismetComment::author).isEqualTo(expected)
|
||||
prop(AkismetComment::authorUrl).isEqualTo(expected)
|
||||
|
@ -384,11 +384,11 @@ class AkismetTest {
|
|||
private val config = CommentConfig.Builder(comment.userIp, comment.userAgent)
|
||||
.referrer(REFERER)
|
||||
.permalink("http://yourblogdomainname.com/blog/post=1")
|
||||
.type(AkismetComment.TYPE_COMMENT)
|
||||
.type(CommentType.COMMENT)
|
||||
.author("admin")
|
||||
.authorEmail("test@test.com")
|
||||
.authorUrl("http://www.CheckOutMyCoolSite.com")
|
||||
.content("It means a lot that you would take the time to review our software. Thanks again.")
|
||||
.content("It means a lot that you would take the time to review our software. Thanks again.")
|
||||
.dateGmt(Akismet.dateToGmt(date))
|
||||
.postModifiedGmt(Akismet.dateToGmt(date))
|
||||
.blogLang("en")
|
||||
|
@ -403,7 +403,7 @@ class AkismetTest {
|
|||
with(comment) {
|
||||
referrer = config.referrer
|
||||
permalink = config.permalink
|
||||
type = config.type
|
||||
type = CommentType("comment")
|
||||
author = config.author
|
||||
authorEmail = config.authorEmail
|
||||
authorUrl = config.authorUrl
|
||||
|
@ -428,7 +428,7 @@ class AkismetTest {
|
|||
postModifiedGmt = comment.dateGmt
|
||||
blogLang = comment.blogLang
|
||||
blogCharset = comment.blogCharset
|
||||
userRole = comment.userRole
|
||||
userRole = AkismetComment.ADMIN_ROLE
|
||||
recheckReason = comment.recheckReason
|
||||
isTest = true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue