Minor cleanups
This commit is contained in:
parent
80fac24b4d
commit
c9cd086ba1
6 changed files with 27 additions and 32 deletions
|
@ -51,7 +51,7 @@ final AkismetComment comment = new AkismetComment(
|
|||
.authorUrl("https://www.CheckOutMyCoolSite.com")
|
||||
.dateGmt(Akismet.dateToGmt(new Date()))
|
||||
.content("Thanks for reviewing our software.")
|
||||
.build
|
||||
.build()
|
||||
);
|
||||
//...
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" ?>
|
||||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
<ID>CyclomaticComplexMethod:Akismet.kt$Akismet$private fun buildFormBody(comment: AkismetComment): FormBody</ID>
|
||||
<ID>CyclomaticComplexMethod:AkismetComment.kt$AkismetComment$@Suppress("DuplicatedCode") override fun equals(other: Any?): Boolean</ID>
|
||||
|
@ -9,9 +9,9 @@
|
|||
<ID>MagicNumber:Akismet.kt$Akismet$8</ID>
|
||||
<ID>NestedBlockDepth:Akismet.kt$Akismet$@JvmOverloads fun executeMethod(apiUrl: HttpUrl, formBody: FormBody, trueOnError: Boolean = false): Boolean</ID>
|
||||
<ID>NestedBlockDepth:AkismetExample.kt$fun main(args: Array<String>)</ID>
|
||||
<ID>NestedBlockDepth:AkismetTest.kt$fun getKey(key: String): String</ID>
|
||||
<ID>ReturnCount:Akismet.kt$Akismet$@JvmOverloads fun executeMethod(apiUrl: HttpUrl, formBody: FormBody, trueOnError: Boolean = false): Boolean</ID>
|
||||
<ID>ReturnCount:AkismetTest.kt$fun getKey(key: String): String</ID>
|
||||
<ID>TooManyFunctions:CommentConfig.kt$CommentConfig$Builder</ID>
|
||||
<ID>WildcardImport:AkismetTest.kt$import assertk.assertions.*</ID>
|
||||
<ID>WildcardImport:AkismetTests.kt$import assertk.assertions.*</ID>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
||||
|
|
|
@ -233,7 +233,7 @@ open class Akismet(apiKey: String) {
|
|||
*
|
||||
* See the [Akismet API](https://akismet.com/development/api/#verify-key) for more details.
|
||||
*
|
||||
* @return `true` if the key is valid, `false` otherwise.
|
||||
* @return `true` if the key is valid, `false` otherwise
|
||||
* @see [Akismet.isVerifiedKey]
|
||||
*/
|
||||
fun verifyKey(): Boolean {
|
||||
|
@ -258,8 +258,8 @@ open class Akismet(apiKey: String) {
|
|||
*
|
||||
* See the [Akismet API](https://akismet.com/development/api/#comment-check) for more details.
|
||||
*
|
||||
* @param trueOnError Set to return `true` on error.
|
||||
* @return `true` if the comment is spam, `false` if the comment is not.
|
||||
* @param trueOnError Set to return `true` on error
|
||||
* @return `true` if the comment is spam, `false` if the comment is not
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun checkComment(comment: AkismetComment, trueOnError: Boolean = false): Boolean {
|
||||
|
@ -280,7 +280,7 @@ open class Akismet(apiKey: String) {
|
|||
*
|
||||
* See the [Akismet API](https://akismet.com/development/api/#submit-spam) for more details.
|
||||
*
|
||||
* @return `true` if the comment was submitted, `false` otherwise.
|
||||
* @return `true` if the comment was submitted, `false` otherwise
|
||||
*/
|
||||
fun submitSpam(comment: AkismetComment): Boolean {
|
||||
return executeMethod("submit-spam".toApiUrl(), buildFormBody(comment))
|
||||
|
@ -302,7 +302,7 @@ open class Akismet(apiKey: String) {
|
|||
*
|
||||
* See the [Akismet API](https://akismet.com/development/api/#submit-ham) for more details.
|
||||
*
|
||||
* @return `true` if the comment was submitted, `false` otherwise.
|
||||
* @return `true` if the comment was submitted, `false` otherwise
|
||||
*/
|
||||
fun submitHam(comment: AkismetComment): Boolean {
|
||||
return executeMethod("submit-ham".toApiUrl(), buildFormBody(comment))
|
||||
|
@ -311,8 +311,8 @@ open class Akismet(apiKey: String) {
|
|||
/**
|
||||
* Executes a call to an Akismet REST API method.
|
||||
*
|
||||
* @param apiUrl The Akismet API URL endpoint. (e.g. https://rest.akismet.com/1.1/verify-key)
|
||||
* @param formBody The HTTP POST form body containing the request parameters to be submitted.
|
||||
* @param apiUrl The Akismet API URL endpoint. (e.g., https://rest.akismet.com/1.1/verify-key)
|
||||
* @param formBody The HTTP POST form body containing the request parameters to be submitted
|
||||
* @param trueOnError Set to return `true` on error (IO, empty response, etc.)
|
||||
*/
|
||||
@JvmOverloads
|
||||
|
|
|
@ -33,9 +33,7 @@ package net.thauvin.erik.akismet
|
|||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.collections.set
|
||||
|
||||
private fun String?.ifNull() = this ?: ""
|
||||
|
||||
|
@ -52,8 +50,8 @@ private fun String?.ifNull() = this ?: ""
|
|||
*
|
||||
* See the [Akismet API](https://akismet.com/development/api/#comment-check) for more details.
|
||||
*
|
||||
* @param userIp IP address of the comment submitter.
|
||||
* @param userAgent User agent string of the web browser submitting the comment.
|
||||
* @param userIp IP address of the comment submitter
|
||||
* @param userAgent User agent string of the web browser submitting the comment
|
||||
*/
|
||||
@Serializable
|
||||
open class AkismetComment(val userIp: String, val userAgent: String) {
|
||||
|
|
|
@ -56,8 +56,8 @@ class CommentConfig private constructor(builder: Builder) {
|
|||
/**
|
||||
* Provides a configuration builder.
|
||||
*
|
||||
* @param userIp IP address of the comment submitter.
|
||||
* @param userAgent User agent string of the web browser submitting the comment.
|
||||
* @param userIp IP address of the comment submitter
|
||||
* @param userAgent User agent string of the web browser submitting the comment
|
||||
*/
|
||||
data class Builder(var userIp: String, var userAgent: String) {
|
||||
var referrer = ""
|
||||
|
|
|
@ -144,21 +144,8 @@ class AkismetTests {
|
|||
}
|
||||
|
||||
private fun getKey(key: String): String {
|
||||
var value = System.getenv(key) ?: ""
|
||||
if (value.isBlank()) {
|
||||
val localProps = File("local.properties")
|
||||
localProps.apply {
|
||||
if (exists()) {
|
||||
FileInputStream(this).use { fis ->
|
||||
Properties().apply {
|
||||
load(fis)
|
||||
value = getProperty(key, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return value
|
||||
return System.getenv(key)?.takeUnless { it.isBlank() }
|
||||
?: loadPropertyValue(key)
|
||||
}
|
||||
|
||||
private fun getMockRequest(): HttpServletRequest {
|
||||
|
@ -176,6 +163,16 @@ class AkismetTests {
|
|||
}
|
||||
return request
|
||||
}
|
||||
|
||||
private fun loadPropertyValue(key: String): String {
|
||||
return File("local.properties")
|
||||
.takeIf { it.exists() }
|
||||
?.let { file ->
|
||||
FileInputStream(file).use { fis ->
|
||||
Properties().apply { load(fis) }.getProperty(key, "")
|
||||
}
|
||||
}.orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue