diff --git a/examples/src/main/java/com/example/AkismetSample.java b/examples/src/main/java/com/example/AkismetSample.java index acc31ed..d17d70f 100644 --- a/examples/src/main/java/com/example/AkismetSample.java +++ b/examples/src/main/java/com/example/AkismetSample.java @@ -7,12 +7,12 @@ import java.util.Date; public class AkismetSample { 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"); comment.setTest(true); - comment.setReferrer("http://www.google.com"); + comment.setReferrer("https://www.google.com"); comment.setPermalink(akismet.getBlog() + "post=1"); comment.setType(AkismetComment.TYPE_COMMENT); comment.setAuthor("admin"); diff --git a/examples/src/main/kotlin/com/example/AkismetExample.kt b/examples/src/main/kotlin/com/example/AkismetExample.kt index 7b1ed37..eabd4a5 100644 --- a/examples/src/main/kotlin/com/example/AkismetExample.kt +++ b/examples/src/main/kotlin/com/example/AkismetExample.kt @@ -6,18 +6,18 @@ import java.util.Date import kotlin.system.exitProcess 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") with(comment) { isTest = true - referrer = "http://www.google.com" + referrer = "https://www.google.com" permalink = "${akismet.blog}post=1" type = AkismetComment.TYPE_COMMENT author = "admin" authorEmail = "test@test.com" - authorUrl = "http://www.CheckOutMyCoolSite.com" + authorUrl = "https://www.CheckOutMyCoolSite.com" dateGmt = Akismet.dateToGmt(Date()) // userRole = AkismetComment.ADMIN_ROLE content = "It means a lot that you would take the time to review our software. Thanks again." diff --git a/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt b/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt index 2c2c90d..c1737ba 100644 --- a/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt +++ b/src/main/kotlin/net/thauvin/erik/akismet/Akismet.kt @@ -105,7 +105,7 @@ open class Akismet(apiKey: String) { */ var blog = "" set(value) { - require(!value.isBlank()) { "A Blog URL must be specified." } + require(value.isNotBlank()) { "A Blog URL must be specified." } field = value } @@ -214,13 +214,11 @@ open class Akismet(apiKey: String) { this.apiKey = apiKey - val logging = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger { - override fun log(message: String) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, message.replace(apiKey, "xxxxxxxx" + apiKey.substring(8), true)) - } + val logging = HttpLoggingInterceptor { message -> + if (logger.isLoggable(Level.FINE)) { + logger.log(Level.FINE, message.replace(apiKey, "xxxxxxxx" + apiKey.substring(8), true)) } - }) + } logging.level = HttpLoggingInterceptor.Level.BODY client = OkHttpClient.Builder().addInterceptor(logging).build() } @@ -344,7 +342,7 @@ open class Akismet(apiKey: String) { if (response == "valid" || response == "true" || response.startsWith("Thanks")) { return true } else if (response != "false" && response != "invalid") { - errorMessage = "Unexpected response: " + if (body.isBlank()) "" else body + errorMessage = "Unexpected response: " + body.ifBlank { "" } } } else { val message = "No response body was received from Akismet." @@ -397,46 +395,46 @@ open class Akismet(apiKey: String) { add("user_ip", userIp) add("user_agent", userAgent) - if (referrer!!.isNotBlank()) { + if (!referrer.isNullOrBlank()) { add("referrer", referrer.toString()) } - if (permalink!!.isNotBlank()) { + if (!permalink.isNullOrBlank()) { add("permalink", permalink.toString()) } - if (type!!.isNotBlank()) { + if (!type.isNullOrBlank()) { add("comment_type", type.toString()) } - if (author!!.isNotBlank()) { + if (!author.isNullOrBlank()) { add("comment_author", author.toString()) } - if (authorEmail!!.isNotBlank()) { + if (!authorEmail.isNullOrBlank()) { add("comment_author_email", authorEmail.toString()) } - if (authorUrl!!.isNotBlank()) { + if (!authorUrl.isNullOrBlank()) { add("comment_author_url", authorUrl.toString()) } - if (content!!.isNotBlank()) { + if (!content.isNullOrBlank()) { add("comment_content", content.toString()) } - if (dateGmt!!.isNotBlank()) { + if (!dateGmt.isNullOrBlank()) { add("comment_date_gmt", dateGmt.toString()) } - if (postModifiedGmt!!.isNotBlank()) { + if (!postModifiedGmt.isNullOrBlank()) { add("comment_post_modified_gmt", postModifiedGmt.toString()) } - if (blogLang!!.isNotBlank()) { + if (!blogLang.isNullOrBlank()) { add("blog_lang", blogLang.toString()) } - if (blogCharset!!.isNotBlank()) { + if (!blogCharset.isNullOrBlank()) { add("blog_charset", blogCharset.toString()) } - if (userRole!!.isNotBlank()) { + if (!userRole.isNullOrBlank()) { add("user_role", userRole.toString()) } if (isTest) { add("is_test", "1") } - if (recheckReason!!.isNotBlank()) { + if (!recheckReason.isNullOrBlank()) { add("recheck_reason", recheckReason.toString()) }