This commit is contained in:
Erik C. Thauvin 2022-04-28 22:03:37 -07:00
parent 89c0acdf42
commit 453bb95617
3 changed files with 24 additions and 26 deletions

View file

@ -7,12 +7,12 @@ import java.util.Date;
public class AkismetSample { public class AkismetSample {
public static void main(String[] args) { public static void main(String[] args) {
final Akismet akismet = new Akismet("YOUR_API_KEY", "http://yourblogdomainname.com/blog/"); final Akismet akismet = new Akismet("YOUR_API_KEY", "https://yourblogdomainname.com/blog/");
final AkismetComment comment = new AkismetComment("127.0.0.1", "curl/7.29.0"); final AkismetComment comment = new AkismetComment("127.0.0.1", "curl/7.29.0");
comment.setTest(true); comment.setTest(true);
comment.setReferrer("http://www.google.com"); comment.setReferrer("https://www.google.com");
comment.setPermalink(akismet.getBlog() + "post=1"); comment.setPermalink(akismet.getBlog() + "post=1");
comment.setType(AkismetComment.TYPE_COMMENT); comment.setType(AkismetComment.TYPE_COMMENT);
comment.setAuthor("admin"); comment.setAuthor("admin");

View file

@ -6,18 +6,18 @@ import java.util.Date
import kotlin.system.exitProcess import kotlin.system.exitProcess
fun main() { fun main() {
val akismet = Akismet(apiKey = "YOUR_API_KEY", blog = "http://yourblogdomainname.com/blog/") val akismet = Akismet(apiKey = "YOUR_API_KEY", blog = "https://yourblogdomainname.com/blog/")
val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0") val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0")
with(comment) { with(comment) {
isTest = true isTest = true
referrer = "http://www.google.com" referrer = "https://www.google.com"
permalink = "${akismet.blog}post=1" permalink = "${akismet.blog}post=1"
type = AkismetComment.TYPE_COMMENT type = AkismetComment.TYPE_COMMENT
author = "admin" author = "admin"
authorEmail = "test@test.com" authorEmail = "test@test.com"
authorUrl = "http://www.CheckOutMyCoolSite.com" authorUrl = "https://www.CheckOutMyCoolSite.com"
dateGmt = Akismet.dateToGmt(Date()) dateGmt = Akismet.dateToGmt(Date())
// userRole = AkismetComment.ADMIN_ROLE // userRole = AkismetComment.ADMIN_ROLE
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."

View file

@ -105,7 +105,7 @@ open class Akismet(apiKey: String) {
*/ */
var blog = "" var blog = ""
set(value) { set(value) {
require(!value.isBlank()) { "A Blog URL must be specified." } require(value.isNotBlank()) { "A Blog URL must be specified." }
field = value field = value
} }
@ -214,13 +214,11 @@ open class Akismet(apiKey: String) {
this.apiKey = apiKey this.apiKey = apiKey
val logging = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { val logging = HttpLoggingInterceptor { message ->
override fun log(message: String) { if (logger.isLoggable(Level.FINE)) {
if (logger.isLoggable(Level.FINE)) { logger.log(Level.FINE, message.replace(apiKey, "xxxxxxxx" + apiKey.substring(8), true))
logger.log(Level.FINE, message.replace(apiKey, "xxxxxxxx" + apiKey.substring(8), true))
}
} }
}) }
logging.level = HttpLoggingInterceptor.Level.BODY logging.level = HttpLoggingInterceptor.Level.BODY
client = OkHttpClient.Builder().addInterceptor(logging).build() client = OkHttpClient.Builder().addInterceptor(logging).build()
} }
@ -344,7 +342,7 @@ open class Akismet(apiKey: String) {
if (response == "valid" || response == "true" || response.startsWith("Thanks")) { if (response == "valid" || response == "true" || response.startsWith("Thanks")) {
return true return true
} else if (response != "false" && response != "invalid") { } else if (response != "false" && response != "invalid") {
errorMessage = "Unexpected response: " + if (body.isBlank()) "<blank>" else body errorMessage = "Unexpected response: " + body.ifBlank { "<blank>" }
} }
} else { } else {
val message = "No response body was received from Akismet." val message = "No response body was received from Akismet."
@ -397,46 +395,46 @@ 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.isNullOrBlank()) {
add("referrer", referrer.toString()) add("referrer", referrer.toString())
} }
if (permalink!!.isNotBlank()) { if (!permalink.isNullOrBlank()) {
add("permalink", permalink.toString()) add("permalink", permalink.toString())
} }
if (type!!.isNotBlank()) { if (!type.isNullOrBlank()) {
add("comment_type", type.toString()) add("comment_type", type.toString())
} }
if (author!!.isNotBlank()) { if (!author.isNullOrBlank()) {
add("comment_author", author.toString()) add("comment_author", author.toString())
} }
if (authorEmail!!.isNotBlank()) { if (!authorEmail.isNullOrBlank()) {
add("comment_author_email", authorEmail.toString()) add("comment_author_email", authorEmail.toString())
} }
if (authorUrl!!.isNotBlank()) { if (!authorUrl.isNullOrBlank()) {
add("comment_author_url", authorUrl.toString()) add("comment_author_url", authorUrl.toString())
} }
if (content!!.isNotBlank()) { if (!content.isNullOrBlank()) {
add("comment_content", content.toString()) add("comment_content", content.toString())
} }
if (dateGmt!!.isNotBlank()) { if (!dateGmt.isNullOrBlank()) {
add("comment_date_gmt", dateGmt.toString()) add("comment_date_gmt", dateGmt.toString())
} }
if (postModifiedGmt!!.isNotBlank()) { if (!postModifiedGmt.isNullOrBlank()) {
add("comment_post_modified_gmt", postModifiedGmt.toString()) add("comment_post_modified_gmt", postModifiedGmt.toString())
} }
if (blogLang!!.isNotBlank()) { if (!blogLang.isNullOrBlank()) {
add("blog_lang", blogLang.toString()) add("blog_lang", blogLang.toString())
} }
if (blogCharset!!.isNotBlank()) { if (!blogCharset.isNullOrBlank()) {
add("blog_charset", blogCharset.toString()) add("blog_charset", blogCharset.toString())
} }
if (userRole!!.isNotBlank()) { if (!userRole.isNullOrBlank()) {
add("user_role", userRole.toString()) add("user_role", userRole.toString())
} }
if (isTest) { if (isTest) {
add("is_test", "1") add("is_test", "1")
} }
if (recheckReason!!.isNotBlank()) { if (!recheckReason.isNullOrBlank()) {
add("recheck_reason", recheckReason.toString()) add("recheck_reason", recheckReason.toString())
} }