Added comment config and builder
This commit is contained in:
parent
539bb6fbc0
commit
c5810c1986
18 changed files with 366 additions and 130 deletions
26
README.md
26
README.md
|
@ -19,16 +19,14 @@ A pretty complete and straightforward implementation of the [Automattic's Akisme
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val akismet = Akismet(apiKey = "YOUR_API_KEY", blog = "YOUR_BLOG_URL")
|
val akismet = Akismet(apiKey = "YOUR_API_KEY", blog = "YOUR_BLOG_URL")
|
||||||
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").apply {
|
||||||
|
|
||||||
with(comment) {
|
|
||||||
referrer = "https://www.google.com"
|
referrer = "https://www.google.com"
|
||||||
type = AkismetComment.TYPE_COMMENT
|
type = AkismetComment.TYPE_COMMENT
|
||||||
author = "admin"
|
author = "admin"
|
||||||
authorEmail = "test@test.com"
|
authorEmail = "test@test.com"
|
||||||
authorUrl = "https://www.CheckOutMyCoolSite.com"
|
authorUrl = "https://www.CheckOutMyCoolSite.com"
|
||||||
dateGmt = Akismet.dateToGmt(Date())
|
dateGmt = Akismet.dateToGmt(Date())
|
||||||
content = "It means a lot that you would take the time to review our software."
|
content = "Thanks for reviewing our software."
|
||||||
}
|
}
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
@ -44,15 +42,17 @@ if (isSpam) {
|
||||||
|
|
||||||
```java
|
```java
|
||||||
final Akismet akismet = new Akismet("YOUR_API_KEY", "YOUR_BLOG_URL");
|
final Akismet akismet = new Akismet("YOUR_API_KEY", "YOUR_BLOG_URL");
|
||||||
final AkismetComment comment = new AkismetComment("127.0.0.1", "curl/7.29.0");
|
final AkismetComment comment = new AkismetComment(
|
||||||
|
new CommentConfig.Builder("127.0.0.1", "curl/7.29.0")
|
||||||
comment.setReferrer("https://www.google.com");
|
.referrer("https://www.google.com")
|
||||||
comment.setType(AkismetComment.TYPE_COMMENT);
|
.type(Akismet.TYPE_COMMENT)
|
||||||
comment.setAuthor("admin");
|
.author("admin")
|
||||||
comment.setAuthorEmail("test@test.com");
|
.authorEmail("test@test.com")
|
||||||
comment.setAuthorUrl("https://www.CheckOutMyCoolSite.com");
|
.authorUrl("https://www.CheckOutMyCoolSite.com")
|
||||||
comment.setDateGmt(Akismet.dateToGmt(new Date()));
|
.dateGmt(Akismet.dateToGmt(new Date()))
|
||||||
comment.setContent("It means a lot that you would take the time to review our software.");
|
.content("Thanks for reviewing our software.")
|
||||||
|
.build
|
||||||
|
);
|
||||||
//...
|
//...
|
||||||
|
|
||||||
final boolean isSpam = akismet.checkComment(comment);
|
final boolean isSpam = akismet.checkComment(comment);
|
||||||
|
|
|
@ -5,12 +5,14 @@
|
||||||
<ID>CyclomaticComplexMethod:Akismet.kt$Akismet$private fun buildFormBody(comment: AkismetComment): FormBody</ID>
|
<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>
|
<ID>CyclomaticComplexMethod:AkismetComment.kt$AkismetComment$@Suppress("DuplicatedCode") override fun equals(other: Any?): Boolean</ID>
|
||||||
<ID>LongParameterList:AkismetServlet.kt$AkismetServlet$( id: String, name: String?, email: String?, date: String?, comment: String?, json: String, isSpam: Boolean )</ID>
|
<ID>LongParameterList:AkismetServlet.kt$AkismetServlet$( id: String, name: String?, email: String?, date: String?, comment: String?, json: String, isSpam: Boolean )</ID>
|
||||||
|
<ID>LongParameterList:CommentConfig.kt$CommentConfig$( var userIp: String, var userAgent: String, var referrer: String = "", var permalink: String = "", var type: String = "", var author: String = "", var authorEmail: String = "", var authorUrl: String = "", var content: String = "", var dateGmt: String = "", var postModifiedGmt: String = "", var blogLang: String = "", var blogCharset: String = "", var userRole: String = "", var isTest: Boolean = false, var recheckReason: String = "", var serverEnv: Map<String, String> = emptyMap() )</ID>
|
||||||
<ID>MagicNumber:Akismet.kt$Akismet$12</ID>
|
<ID>MagicNumber:Akismet.kt$Akismet$12</ID>
|
||||||
<ID>MagicNumber:Akismet.kt$Akismet$8</ID>
|
<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: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:AkismetExample.kt$fun main(args: Array<String>)</ID>
|
||||||
<ID>NestedBlockDepth:AkismetTest.kt$fun getKey(key: String): 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:Akismet.kt$Akismet$@JvmOverloads fun executeMethod(apiUrl: HttpUrl, formBody: FormBody, trueOnError: Boolean = false): Boolean</ID>
|
||||||
|
<ID>TooManyFunctions:CommentConfig.kt$CommentConfig$Builder</ID>
|
||||||
<ID>WildcardImport:AkismetTest.kt$import assertk.assertions.*</ID>
|
<ID>WildcardImport:AkismetTest.kt$import assertk.assertions.*</ID>
|
||||||
</CurrentIssues>
|
</CurrentIssues>
|
||||||
</SmellBaseline>
|
</SmellBaseline>
|
||||||
|
|
|
@ -8,7 +8,6 @@ To compile & run the Kotlin example:
|
||||||
```
|
```
|
||||||
|
|
||||||
## Java Example
|
## Java Example
|
||||||
cd
|
|
||||||
To compile & run the Java example:
|
To compile & run the Java example:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.example;
|
||||||
|
|
||||||
import net.thauvin.erik.akismet.Akismet;
|
import net.thauvin.erik.akismet.Akismet;
|
||||||
import net.thauvin.erik.akismet.AkismetComment;
|
import net.thauvin.erik.akismet.AkismetComment;
|
||||||
|
import net.thauvin.erik.akismet.CommentConfig;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -9,25 +10,26 @@ public class AkismetSample {
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
if (args.length == 1 && !args[0].isBlank()) {
|
if (args.length == 1 && !args[0].isBlank()) {
|
||||||
final Akismet akismet = new Akismet(args[0], "https://yourblogdomainname.com/blog/");
|
final Akismet akismet = new Akismet(args[0], "https://yourblogdomainname.com/blog/");
|
||||||
final AkismetComment comment = new AkismetComment("127.0.0.1", "curl/7.29.0");
|
final AkismetComment comment = new AkismetComment(
|
||||||
|
new CommentConfig.Builder("127.0.0.1", "curl/7.29.0")
|
||||||
|
.isTest(true)
|
||||||
|
.referrer("https://www.google.com")
|
||||||
|
.permalink(akismet.getBlog() + "post=1")
|
||||||
|
.type(AkismetComment.TYPE_COMMENT)
|
||||||
|
.author("admin")
|
||||||
|
.authorEmail("test@test.com")
|
||||||
|
.authorUrl("http://www.CheckOutMyCoolSite.com")
|
||||||
|
.dateGmt(Akismet.dateToGmt(new Date()))
|
||||||
|
// .userRole(AkismetComment.ADMIN_ROLE)
|
||||||
|
.content("It means a lot that you would take the time to review our software. Thanks again.")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
comment.setTest(true);
|
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||||
|
// consoleHandler.setLevel(Level.FINE);
|
||||||
comment.setReferrer("https://www.google.com");
|
// final Logger logger = akismet.getLogger();
|
||||||
comment.setPermalink(akismet.getBlog() + "post=1");
|
// logger.addHandler(consoleHandler);
|
||||||
comment.setType(AkismetComment.TYPE_COMMENT);
|
// logger.setLevel(Level.FINE);
|
||||||
comment.setAuthor("admin");
|
|
||||||
comment.setAuthorEmail("test@test.com");
|
|
||||||
comment.setAuthorUrl("http://www.CheckOutMyCoolSite.com");
|
|
||||||
comment.setDateGmt(Akismet.dateToGmt(new Date()));
|
|
||||||
// comment.setUserRole(AkismetComment.ADMIN_ROLE);
|
|
||||||
comment.setContent("It means a lot that you would take the time to review our software. Thanks again.");
|
|
||||||
|
|
||||||
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
|
||||||
// consoleHandler.setLevel(Level.FINE);
|
|
||||||
// final Logger logger = akismet.getLogger();
|
|
||||||
// logger.addHandler(consoleHandler);
|
|
||||||
// logger.setLevel(Level.FINE);
|
|
||||||
|
|
||||||
if (akismet.verifyKey()) {
|
if (akismet.verifyKey()) {
|
||||||
final boolean isSpam = akismet.checkComment(comment);
|
final boolean isSpam = akismet.checkComment(comment);
|
||||||
|
|
|
@ -2,18 +2,14 @@ package com.example
|
||||||
|
|
||||||
import net.thauvin.erik.akismet.Akismet
|
import net.thauvin.erik.akismet.Akismet
|
||||||
import net.thauvin.erik.akismet.AkismetComment
|
import net.thauvin.erik.akismet.AkismetComment
|
||||||
import java.util.Date
|
import java.util.*
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
if (args.size == 1 && args[0].isNotEmpty()) {
|
if (args.size == 1 && args[0].isNotEmpty()) {
|
||||||
val akismet = Akismet(apiKey = args[0], blog = "https://yourblogdomainname.com/blog/")
|
val akismet = Akismet(apiKey = args[0], 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").apply {
|
||||||
|
|
||||||
with(comment) {
|
|
||||||
isTest = true
|
isTest = true
|
||||||
|
|
||||||
referrer = "https://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
|
||||||
|
@ -21,7 +17,7 @@ fun main(args: Array<String>) {
|
||||||
authorEmail = "test@test.com"
|
authorEmail = "test@test.com"
|
||||||
authorUrl = "https://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."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ class AkismetServlet : HttpServlet() {
|
||||||
|
|
||||||
akismet.appUserAgent = request.servletContext.serverInfo
|
akismet.appUserAgent = request.servletContext.serverInfo
|
||||||
|
|
||||||
val comment = AkismetComment(request)
|
val comment = AkismetComment(request).apply {
|
||||||
with(comment) {
|
|
||||||
permalink = "${akismet.blog}/comment/$id"
|
permalink = "${akismet.blog}/comment/$id"
|
||||||
type = AkismetComment.TYPE_COMMENT
|
type = AkismetComment.TYPE_COMMENT
|
||||||
author = request.getParameter("name")
|
author = request.getParameter("name")
|
||||||
|
|
2
examples/gradle/.idea/.name
generated
2
examples/gradle/.idea/.name
generated
|
@ -1 +1 @@
|
||||||
akismet-examples
|
akismet-examples-gradle
|
2
examples/gradle/.idea/kotlinc.xml
generated
2
examples/gradle/.idea/kotlinc.xml
generated
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KotlinJpsPluginSettings">
|
<component name="KotlinJpsPluginSettings">
|
||||||
<option name="version" value="1.9.20" />
|
<option name="version" value="2.0.0" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
5
examples/gradle/.idea/misc.xml
generated
5
examples/gradle/.idea/misc.xml
generated
|
@ -6,10 +6,7 @@
|
||||||
<list size="0" />
|
<list size="0" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="PDMPlugin">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||||
<option name="skipTestSources" value="false" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="20" project-jdk-type="JavaSDK" />
|
|
||||||
<component name="SuppressionsComponent">
|
<component name="SuppressionsComponent">
|
||||||
<option name="suppComments" value="[]" />
|
<option name="suppComments" value="[]" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("application")
|
id("application")
|
||||||
id("com.github.ben-manes.versions") version "0.51.0"
|
id("com.github.ben-manes.versions") version "0.51.0"
|
||||||
|
@ -15,7 +13,7 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("jakarta.servlet:jakarta.servlet-api:6.0.0")
|
implementation("jakarta.servlet:jakarta.servlet-api:6.0.0")
|
||||||
implementation("net.thauvin.erik:akismet-kotlin:1.0.0")
|
implementation("net.thauvin.erik:akismet-kotlin:1.0.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -27,11 +25,11 @@ application {
|
||||||
mainClass.set("com.example.AkismetExampleKt")
|
mainClass.set("com.example.AkismetExampleKt")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
kotlin {
|
||||||
withType<KotlinCompile>().configureEach {
|
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
|
||||||
kotlinOptions.jvmTarget = java.targetCompatibility.toString()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
tasks {
|
||||||
register("runJava", JavaExec::class) {
|
register("runJava", JavaExec::class) {
|
||||||
group = "application"
|
group = "application"
|
||||||
mainClass.set("com.example.AkismetSample")
|
mainClass.set("com.example.AkismetSample")
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.example;
|
||||||
|
|
||||||
import net.thauvin.erik.akismet.Akismet;
|
import net.thauvin.erik.akismet.Akismet;
|
||||||
import net.thauvin.erik.akismet.AkismetComment;
|
import net.thauvin.erik.akismet.AkismetComment;
|
||||||
|
import net.thauvin.erik.akismet.CommentConfig;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -9,25 +10,26 @@ public class AkismetSample {
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
if (args.length == 1 && !args[0].isBlank()) {
|
if (args.length == 1 && !args[0].isBlank()) {
|
||||||
final Akismet akismet = new Akismet(args[0], "https://yourblogdomainname.com/blog/");
|
final Akismet akismet = new Akismet(args[0], "https://yourblogdomainname.com/blog/");
|
||||||
final AkismetComment comment = new AkismetComment("127.0.0.1", "curl/7.29.0");
|
final AkismetComment comment = new AkismetComment(
|
||||||
|
new CommentConfig.Builder("127.0.0.1", "curl/7.29.0")
|
||||||
|
.isTest(true)
|
||||||
|
.referrer("https://www.google.com")
|
||||||
|
.permalink(akismet.getBlog() + "post=1")
|
||||||
|
.type(AkismetComment.TYPE_COMMENT)
|
||||||
|
.author("admin")
|
||||||
|
.authorEmail("test@test.com")
|
||||||
|
.authorUrl("http://www.CheckOutMyCoolSite.com")
|
||||||
|
.dateGmt(Akismet.dateToGmt(new Date()))
|
||||||
|
// .userRole(AkismetComment.ADMIN_ROLE)
|
||||||
|
.content("It means a lot that you would take the time to review our software. Thanks again.")
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
comment.setTest(true);
|
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||||
|
// consoleHandler.setLevel(Level.FINE);
|
||||||
comment.setReferrer("https://www.google.com");
|
// final Logger logger = akismet.getLogger();
|
||||||
comment.setPermalink(akismet.getBlog() + "post=1");
|
// logger.addHandler(consoleHandler);
|
||||||
comment.setType(AkismetComment.TYPE_COMMENT);
|
// logger.setLevel(Level.FINE);
|
||||||
comment.setAuthor("admin");
|
|
||||||
comment.setAuthorEmail("test@test.com");
|
|
||||||
comment.setAuthorUrl("http://www.CheckOutMyCoolSite.com");
|
|
||||||
comment.setDateGmt(Akismet.dateToGmt(new Date()));
|
|
||||||
// comment.setUserRole(AkismetComment.ADMIN_ROLE);
|
|
||||||
comment.setContent("It means a lot that you would take the time to review our software. Thanks again.");
|
|
||||||
|
|
||||||
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
|
||||||
// consoleHandler.setLevel(Level.FINE);
|
|
||||||
// final Logger logger = akismet.getLogger();
|
|
||||||
// logger.addHandler(consoleHandler);
|
|
||||||
// logger.setLevel(Level.FINE);
|
|
||||||
|
|
||||||
if (akismet.verifyKey()) {
|
if (akismet.verifyKey()) {
|
||||||
final boolean isSpam = akismet.checkComment(comment);
|
final boolean isSpam = akismet.checkComment(comment);
|
||||||
|
|
|
@ -2,18 +2,14 @@ package com.example
|
||||||
|
|
||||||
import net.thauvin.erik.akismet.Akismet
|
import net.thauvin.erik.akismet.Akismet
|
||||||
import net.thauvin.erik.akismet.AkismetComment
|
import net.thauvin.erik.akismet.AkismetComment
|
||||||
import java.util.Date
|
import java.util.*
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
if (args.size == 1 && args[0].isNotEmpty()) {
|
if (args.size == 1 && args[0].isNotEmpty()) {
|
||||||
val akismet = Akismet(apiKey = args[0], blog = "https://yourblogdomainname.com/blog/")
|
val akismet = Akismet(apiKey = args[0], 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").apply {
|
||||||
|
|
||||||
with(comment) {
|
|
||||||
isTest = true
|
isTest = true
|
||||||
|
|
||||||
referrer = "https://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
|
||||||
|
@ -21,7 +17,7 @@ fun main(args: Array<String>) {
|
||||||
authorEmail = "test@test.com"
|
authorEmail = "test@test.com"
|
||||||
authorUrl = "https://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."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ class AkismetServlet : HttpServlet() {
|
||||||
|
|
||||||
akismet.appUserAgent = request.servletContext.serverInfo
|
akismet.appUserAgent = request.servletContext.serverInfo
|
||||||
|
|
||||||
val comment = AkismetComment(request)
|
val comment = AkismetComment(request).apply {
|
||||||
with(comment) {
|
|
||||||
permalink = "${akismet.blog}/comment/$id"
|
permalink = "${akismet.blog}/comment/$id"
|
||||||
type = AkismetComment.TYPE_COMMENT
|
type = AkismetComment.TYPE_COMMENT
|
||||||
author = request.getParameter("name")
|
author = request.getParameter("name")
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
bld.downloadExtensionJavadoc=false
|
bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.extensions-detekt=com.uwyn.rife2:bld-detekt:0.9.2
|
|
||||||
bld.extensions=com.uwyn.rife2:bld-generated-version:0.9.5
|
bld.extensions=com.uwyn.rife2:bld-generated-version:0.9.5
|
||||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
|
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
|
||||||
bld.extensions-kotlin=com.uwyn.rife2:bld-kotlin:0.9.7
|
bld.extensions-kotlin=com.uwyn.rife2:bld-kotlin:0.9.5
|
||||||
|
bld.extensions-detekt=com.uwyn.rife2:bld-detekt:0.9.4
|
||||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.sourceDirectories=
|
bld.sourceDirectories=
|
||||||
|
|
|
@ -243,6 +243,24 @@ open class AkismetComment(val userIp: String, val userAgent: String) {
|
||||||
serverEnv = buildServerEnv(request)
|
serverEnv = buildServerEnv(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(config: CommentConfig) : this(config.userIp, config.userAgent) {
|
||||||
|
referrer = config.referrer
|
||||||
|
permalink = config.permalink
|
||||||
|
type = config.type
|
||||||
|
author = config.author
|
||||||
|
authorEmail = config.authorEmail
|
||||||
|
authorUrl = config.authorUrl
|
||||||
|
content = config.content
|
||||||
|
dateGmt = config.dateGmt
|
||||||
|
postModifiedGmt = config.postModifiedGmt
|
||||||
|
blogLang = config.blogLang
|
||||||
|
blogCharset = config.blogCharset
|
||||||
|
userRole = config.userRole
|
||||||
|
isTest = config.isTest
|
||||||
|
recheckReason = config.recheckReason
|
||||||
|
serverEnv = config.serverEnv
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a JSON representation of the comment.
|
* Returns a JSON representation of the comment.
|
||||||
*
|
*
|
||||||
|
|
237
src/main/kotlin/net/thauvin/erik/akismet/CommentConfig.kt
Normal file
237
src/main/kotlin/net/thauvin/erik/akismet/CommentConfig.kt
Normal file
|
@ -0,0 +1,237 @@
|
||||||
|
/*
|
||||||
|
* CommentConfig.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 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.
|
||||||
|
*
|
||||||
|
* @param userIp IP address of the comment submitter.
|
||||||
|
* @param userAgent User agent string of the web browser submitting the comment.
|
||||||
|
*/
|
||||||
|
class CommentConfig @JvmOverloads constructor(
|
||||||
|
var userIp: String,
|
||||||
|
var userAgent: String,
|
||||||
|
var referrer: String = "",
|
||||||
|
var permalink: String = "",
|
||||||
|
var type: String = "",
|
||||||
|
var author: String = "",
|
||||||
|
var authorEmail: String = "",
|
||||||
|
var authorUrl: String = "",
|
||||||
|
var content: String = "",
|
||||||
|
var dateGmt: String = "",
|
||||||
|
var postModifiedGmt: String = "",
|
||||||
|
var blogLang: String = "",
|
||||||
|
var blogCharset: String = "",
|
||||||
|
var userRole: String = "",
|
||||||
|
var isTest: Boolean = false,
|
||||||
|
var recheckReason: String = "",
|
||||||
|
var serverEnv: Map<String, String> = emptyMap()
|
||||||
|
|
||||||
|
) {
|
||||||
|
constructor(builder: Builder) : this(builder.userIp, builder.userAgent) {
|
||||||
|
referrer = builder.referrer
|
||||||
|
permalink = builder.permalink
|
||||||
|
type = builder.type
|
||||||
|
author = builder.author
|
||||||
|
authorEmail = builder.authorEmail
|
||||||
|
authorUrl = builder.authorUrl
|
||||||
|
content = builder.content
|
||||||
|
dateGmt = builder.dateGmt
|
||||||
|
postModifiedGmt = builder.postModifiedGmt
|
||||||
|
blogLang = builder.blogLang
|
||||||
|
blogCharset = builder.blogCharset
|
||||||
|
userRole = builder.userRole
|
||||||
|
isTest = builder.isTest
|
||||||
|
recheckReason = builder.recheckReason
|
||||||
|
serverEnv = builder.serverEnv
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a configuration builder.
|
||||||
|
*
|
||||||
|
* @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 = ""
|
||||||
|
var permalink = ""
|
||||||
|
var type = ""
|
||||||
|
var author = ""
|
||||||
|
var authorEmail = ""
|
||||||
|
var authorUrl = ""
|
||||||
|
var content = ""
|
||||||
|
var dateGmt = ""
|
||||||
|
var postModifiedGmt = ""
|
||||||
|
var blogLang = ""
|
||||||
|
var blogCharset = ""
|
||||||
|
var userRole = ""
|
||||||
|
var isTest = false
|
||||||
|
var recheckReason = ""
|
||||||
|
var serverEnv: Map<String, String> = emptyMap()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the IP address of the comment submitter.
|
||||||
|
*/
|
||||||
|
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 }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the content of the referrer header.
|
||||||
|
*/
|
||||||
|
fun referrer(referrer: String): Builder = apply { this.referrer = referrer }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the full permanent URL of the entry the comment was submitted to.
|
||||||
|
*/
|
||||||
|
fun permalink(permalink: String): Builder = apply { this.permalink = permalink }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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]
|
||||||
|
*
|
||||||
|
* 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 }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the mame submitted with the comment.
|
||||||
|
*/
|
||||||
|
fun author(author: String): Builder = apply { this.author = author }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the email address submitted with the comment.
|
||||||
|
*/
|
||||||
|
fun authorEmail(authorEmail: String): Builder = apply { this.authorEmail = authorEmail }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the URL submitted with comment.
|
||||||
|
*/
|
||||||
|
fun authorUrl(authorUrl: String): Builder = apply { this.authorUrl = authorUrl }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the content that was submitted.
|
||||||
|
*/
|
||||||
|
fun content(content: String): Builder = apply { this.content = content }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the UTC timestamp of the creation of the comment, in ISO 8601 format.
|
||||||
|
*
|
||||||
|
* May be omitted if the comment is sent to the API at the time it is created.
|
||||||
|
*
|
||||||
|
* @see [Akismet.dateToGmt]
|
||||||
|
*/
|
||||||
|
fun dateGmt(dateGmt: String): Builder = apply { this.dateGmt = dateGmt }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the UTC timestamp of the publication time for the post, page or thread on which the comment was posted.
|
||||||
|
*
|
||||||
|
* @see [Akismet.dateToGmt]
|
||||||
|
*/
|
||||||
|
fun postModifiedGmt(postModifiedGmt: String) = apply { this.postModifiedGmt = postModifiedGmt }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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`
|
||||||
|
*/
|
||||||
|
fun blogLang(blogLang: String): Builder = apply { this.blogLang = blogLang }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the character encoding for the form values included in comment parameters, such as UTF-8 or ISO-8859-1
|
||||||
|
*/
|
||||||
|
fun blogCharset(blogCharset: String): Builder = apply { this.blogCharset = blogCharset }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
fun userRole(userRole: String): Builder = apply { this.userRole = userRole }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is optional. You can set it when submitting test queries to Akismet.
|
||||||
|
*/
|
||||||
|
fun isTest(isTest: Boolean): Builder = apply { this.isTest = isTest }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you are sending content to Akismet to be rechecked, such as a post that has been edited or old pending
|
||||||
|
* comments that you'd like to recheck, include this parameter with a string describing why the content is
|
||||||
|
* being rechecked.
|
||||||
|
*
|
||||||
|
* For example: `edit`
|
||||||
|
*/
|
||||||
|
fun recheckReason(checkReason: String): Builder = apply { this.recheckReason = checkReason }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In PHP, there is an array of environmental variables called `$_SERVER` that contains information about the
|
||||||
|
* Web server itself as well as a key/value for every HTTP header sent with the request. This data is highly
|
||||||
|
* useful to Akismet.
|
||||||
|
*
|
||||||
|
* How the submitted content interacts with the server can be very telling, so please include as much of it as
|
||||||
|
* possible.
|
||||||
|
*/
|
||||||
|
fun serverEnv(serverEnv: Map<String, String>): Builder = apply { this.serverEnv = serverEnv }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds a new comment configuration.
|
||||||
|
*/
|
||||||
|
fun build(): CommentConfig = CommentConfig(this)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +1,3 @@
|
||||||
/*
|
|
||||||
* GeneratedVersion.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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is automatically generated.
|
* This file is automatically generated.
|
||||||
* Do not modify! -- ALL CHANGES WILL BE ERASED!
|
* Do not modify! -- ALL CHANGES WILL BE ERASED!
|
||||||
|
|
|
@ -118,6 +118,11 @@ class AkismetTest {
|
||||||
assertThat(akismet::blog).isEqualTo(blog)
|
assertThat(akismet::blog).isEqualTo(blog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun validateConfigTest() {
|
||||||
|
assertThat(AkismetComment(config) == comment).isTrue()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun verifyKeyTest() {
|
fun verifyKeyTest() {
|
||||||
assertThat(akismet, "akismet").all {
|
assertThat(akismet, "akismet").all {
|
||||||
|
@ -367,6 +372,7 @@ class AkismetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val REFERER = "http://www.google.com"
|
||||||
private val apiKey = getKey("AKISMET_API_KEY")
|
private val apiKey = getKey("AKISMET_API_KEY")
|
||||||
private val blog = getKey("AKISMET_BLOG")
|
private val blog = getKey("AKISMET_BLOG")
|
||||||
private val akismet = Akismet(apiKey, blog)
|
private val akismet = Akismet(apiKey, blog)
|
||||||
|
@ -375,24 +381,40 @@ class AkismetTest {
|
||||||
userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
|
userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"
|
||||||
)
|
)
|
||||||
private val date = Date()
|
private val date = Date()
|
||||||
|
private val config = CommentConfig.Builder(comment.userIp, comment.userAgent)
|
||||||
|
.referrer(REFERER)
|
||||||
|
.permalink("http://yourblogdomainname.com/blog/post=1")
|
||||||
|
.type(AkismetComment.TYPE_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.")
|
||||||
|
.dateGmt(Akismet.dateToGmt(date))
|
||||||
|
.postModifiedGmt(Akismet.dateToGmt(date))
|
||||||
|
.blogLang("en")
|
||||||
|
.blogCharset("UTF-8")
|
||||||
|
.userRole(AkismetComment.ADMIN_ROLE)
|
||||||
|
.recheckReason("edit")
|
||||||
|
.isTest(true)
|
||||||
|
.build()
|
||||||
private val mockComment: AkismetComment = AkismetComment(request = getMockRequest())
|
private val mockComment: AkismetComment = AkismetComment(request = getMockRequest())
|
||||||
private const val REFERER = "http://www.google.com"
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
with(comment) {
|
with(comment) {
|
||||||
referrer = REFERER
|
referrer = config.referrer
|
||||||
permalink = "http://yourblogdomainname.com/blog/post=1"
|
permalink = config.permalink
|
||||||
type = AkismetComment.TYPE_COMMENT
|
type = config.type
|
||||||
author = "admin"
|
author = config.author
|
||||||
authorEmail = "test@test.com"
|
authorEmail = config.authorEmail
|
||||||
authorUrl = "http://www.CheckOutMyCoolSite.com"
|
authorUrl = config.authorUrl
|
||||||
content = "It means a lot that you would take the time to review our software. Thanks again."
|
content = config.content
|
||||||
dateGmt = Akismet.dateToGmt(date)
|
dateGmt = config.dateGmt
|
||||||
postModifiedGmt = dateGmt
|
postModifiedGmt = config.postModifiedGmt
|
||||||
blogLang = "en"
|
blogLang = config.blogLang
|
||||||
blogCharset = "UTF-8"
|
blogCharset = config.blogCharset
|
||||||
userRole = AkismetComment.ADMIN_ROLE
|
userRole = config.userRole
|
||||||
isTest = true
|
recheckReason = config.recheckReason
|
||||||
|
isTest = config.isTest
|
||||||
}
|
}
|
||||||
|
|
||||||
with(mockComment) {
|
with(mockComment) {
|
||||||
|
@ -407,7 +429,7 @@ class AkismetTest {
|
||||||
blogLang = comment.blogLang
|
blogLang = comment.blogLang
|
||||||
blogCharset = comment.blogCharset
|
blogCharset = comment.blogCharset
|
||||||
userRole = comment.userRole
|
userRole = comment.userRole
|
||||||
recheckReason = "edit"
|
recheckReason = comment.recheckReason
|
||||||
isTest = true
|
isTest = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue