Allow null strings in comment properties.

This commit is contained in:
Erik C. Thauvin 2019-10-01 22:11:44 -07:00
parent 8d0cdbbf46
commit 1b0146ebb4
2 changed files with 78 additions and 39 deletions

View file

@ -401,47 +401,47 @@ open class Akismet(apiKey: String) {
add("user_ip", userIp) add("user_ip", userIp)
add("user_agent", userAgent) add("user_agent", userAgent)
if (referrer.isNotBlank()) { if (referrer!!.isNotBlank()) {
add("referrer", referrer) add("referrer", referrer.toString())
} }
if (permalink.isNotBlank()) { if (permalink!!.isNotBlank()) {
add("permalink", permalink) add("permalink", permalink.toString())
} }
if (type.isNotBlank()) { if (type!!.isNotBlank()) {
add("comment_type", type) add("comment_type", type.toString())
} }
if (author.isNotBlank()) { if (author!!.isNotBlank()) {
add("comment_author", author) add("comment_author", author.toString())
} }
if (authorEmail.isNotBlank()) { if (authorEmail!!.isNotBlank()) {
add("comment_author_email", authorEmail) add("comment_author_email", authorEmail.toString())
} }
if (authorUrl.isNotBlank()) { if (authorUrl!!.isNotBlank()) {
add("comment_author_url", authorUrl) add("comment_author_url", authorUrl.toString())
} }
if (content.isNotBlank()) { if (content!!.isNotBlank()) {
add("comment_content", content) add("comment_content", content.toString())
} }
if (dateGmt.isNotBlank()) { if (dateGmt!!.isNotBlank()) {
add("comment_date_gmt", dateGmt) add("comment_date_gmt", dateGmt.toString())
} }
if (postModifiedGmt.isNotBlank()) { if (postModifiedGmt!!.isNotBlank()) {
add("comment_post_modified_gmt", postModifiedGmt) add("comment_post_modified_gmt", postModifiedGmt.toString())
} }
if (blogLang.isNotBlank()) { if (blogLang!!.isNotBlank()) {
add("blog_lang", blogLang) add("blog_lang", blogLang.toString())
} }
if (blogCharset.isNotBlank()) { if (blogCharset!!.isNotBlank()) {
add("blog_charset", blogCharset) add("blog_charset", blogCharset.toString())
} }
if (userRole.isNotBlank()) { if (userRole!!.isNotBlank()) {
add("user_role", userRole) add("user_role", userRole.toString())
} }
if (isTest) { if (isTest) {
add("is_test", "1") add("is_test", "1")
} }
if (recheckReason.isNotBlank()) { if (recheckReason!!.isNotBlank()) {
add("recheck_reason", recheckReason) add("recheck_reason", recheckReason.toString())
} }
serverEnv.forEach { (k, v) -> add(k, v) } serverEnv.forEach { (k, v) -> add(k, v) }

View file

@ -84,10 +84,16 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
} }
/** The content of the referer header should be set here. */ /** The content of the referer header should be set here. */
var referrer: String = "" 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 = "" var permalink: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* A string that describes the type of content being sent, such as: * A string that describes the type of content being sent, such as:
@ -107,19 +113,34 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
* *
* This is further explained [here](http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/). * This is further explained [here](http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/).
*/ */
var type: String = "" var type: String? = ""
set(value) {
field = value.ifNull()
}
/** Name submitted with the comment. */ /** Name submitted with the comment. */
var author: String = "" var author: String? = ""
set(value) {
field = value.ifNull()
}
/** Email address submitted with the comment. */ /** Email address submitted with the comment. */
var authorEmail: String = "" var authorEmail: String? = ""
set(value) {
field = value.ifNull()
}
/** URL submitted with comment. */ /** URL submitted with comment. */
var authorUrl: String = "" var authorUrl: String? = ""
set(value) {
field = value.ifNull()
}
/** The content that was submitted. */ /** The content that was submitted. */
var content: String = "" var content: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* The UTC timestamp of the creation of the comment, in ISO 8601 format. * The UTC timestamp of the creation of the comment, in ISO 8601 format.
@ -128,33 +149,48 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
* *
* @see [Akismet.dateToGmt] * @see [Akismet.dateToGmt]
*/ */
var dateGmt: String = "" var dateGmt: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* The UTC timestamp of the publication time for the post, page or thread on which the comment was posted. * The UTC timestamp of the publication time for the post, page or thread on which the comment was posted.
* *
* @see [Akismet.dateToGmt] * @see [Akismet.dateToGmt]
*/ */
var postModifiedGmt: String = "" var postModifiedGmt: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* Indicates the language(s) in use on the blog or site, in ISO 639-1 format, comma-separated. * Indicates the language(s) in use on the blog or site, in ISO 639-1 format, comma-separated.
* *
* A site with articles in English and French might use: `en, fr_ca` * A site with articles in English and French might use: `en, fr_ca`
*/ */
var blogLang: String = "" var blogLang: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* The character encoding for the form values included in comment parameters, such as UTF-8 or ISO-8859-1 * The character encoding for the form values included in comment parameters, such as UTF-8 or ISO-8859-1
*/ */
var blogCharset: String = "" var blogCharset: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* The user role of the user who submitted the comment. This is an optional parameter. * 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 = "" 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 var isTest: Boolean = false
@ -166,7 +202,10 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
* *
* For example: `edit` * For example: `edit`
*/ */
var recheckReason: String = "" var recheckReason: String? = ""
set(value) {
field = value.ifNull()
}
/** /**
* In PHP, there is an array of environmental variables called `$_SERVER` that contains information about the Web * In PHP, there is an array of environmental variables called `$_SERVER` that contains information about the Web