Added comment config and builder
This commit is contained in:
parent
539bb6fbc0
commit
c5810c1986
18 changed files with 366 additions and 130 deletions
|
@ -8,7 +8,6 @@ To compile & run the Kotlin example:
|
|||
```
|
||||
|
||||
## Java Example
|
||||
cd
|
||||
To compile & run the Java example:
|
||||
|
||||
```console
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.example;
|
|||
|
||||
import net.thauvin.erik.akismet.Akismet;
|
||||
import net.thauvin.erik.akismet.AkismetComment;
|
||||
import net.thauvin.erik.akismet.CommentConfig;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -9,25 +10,26 @@ public class AkismetSample {
|
|||
public static void main(String... args) {
|
||||
if (args.length == 1 && !args[0].isBlank()) {
|
||||
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);
|
||||
|
||||
comment.setReferrer("https://www.google.com");
|
||||
comment.setPermalink(akismet.getBlog() + "post=1");
|
||||
comment.setType(AkismetComment.TYPE_COMMENT);
|
||||
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);
|
||||
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||
// consoleHandler.setLevel(Level.FINE);
|
||||
// final Logger logger = akismet.getLogger();
|
||||
// logger.addHandler(consoleHandler);
|
||||
// logger.setLevel(Level.FINE);
|
||||
|
||||
if (akismet.verifyKey()) {
|
||||
final boolean isSpam = akismet.checkComment(comment);
|
||||
|
|
|
@ -2,18 +2,14 @@ package com.example
|
|||
|
||||
import net.thauvin.erik.akismet.Akismet
|
||||
import net.thauvin.erik.akismet.AkismetComment
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
if (args.size == 1 && args[0].isNotEmpty()) {
|
||||
val akismet = Akismet(apiKey = args[0], blog = "https://yourblogdomainname.com/blog/")
|
||||
val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0")
|
||||
|
||||
with(comment) {
|
||||
val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0").apply {
|
||||
isTest = true
|
||||
|
||||
referrer = "https://www.google.com"
|
||||
permalink = "${akismet.blog}post=1"
|
||||
type = AkismetComment.TYPE_COMMENT
|
||||
|
@ -21,7 +17,7 @@ fun main(args: Array<String>) {
|
|||
authorEmail = "test@test.com"
|
||||
authorUrl = "https://www.CheckOutMyCoolSite.com"
|
||||
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."
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ class AkismetServlet : HttpServlet() {
|
|||
|
||||
akismet.appUserAgent = request.servletContext.serverInfo
|
||||
|
||||
val comment = AkismetComment(request)
|
||||
with(comment) {
|
||||
val comment = AkismetComment(request).apply {
|
||||
permalink = "${akismet.blog}/comment/$id"
|
||||
type = AkismetComment.TYPE_COMMENT
|
||||
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"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.20" />
|
||||
<option name="version" value="2.0.0" />
|
||||
</component>
|
||||
</project>
|
7
examples/gradle/.idea/misc.xml
generated
7
examples/gradle/.idea/misc.xml
generated
|
@ -6,11 +6,8 @@
|
|||
<list size="0" />
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="PDMPlugin">
|
||||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="20" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
<component name="SuppressionsComponent">
|
||||
<option name="suppComments" value="[]" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id("application")
|
||||
id("com.github.ben-manes.versions") version "0.51.0"
|
||||
|
@ -15,7 +13,7 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
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 {
|
||||
|
@ -27,11 +25,11 @@ application {
|
|||
mainClass.set("com.example.AkismetExampleKt")
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions.jvmTarget = java.targetCompatibility.toString()
|
||||
}
|
||||
kotlin {
|
||||
compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
|
||||
}
|
||||
|
||||
tasks {
|
||||
register("runJava", JavaExec::class) {
|
||||
group = "application"
|
||||
mainClass.set("com.example.AkismetSample")
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.example;
|
|||
|
||||
import net.thauvin.erik.akismet.Akismet;
|
||||
import net.thauvin.erik.akismet.AkismetComment;
|
||||
import net.thauvin.erik.akismet.CommentConfig;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -9,25 +10,26 @@ public class AkismetSample {
|
|||
public static void main(String... args) {
|
||||
if (args.length == 1 && !args[0].isBlank()) {
|
||||
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);
|
||||
|
||||
comment.setReferrer("https://www.google.com");
|
||||
comment.setPermalink(akismet.getBlog() + "post=1");
|
||||
comment.setType(AkismetComment.TYPE_COMMENT);
|
||||
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);
|
||||
// final ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||
// consoleHandler.setLevel(Level.FINE);
|
||||
// final Logger logger = akismet.getLogger();
|
||||
// logger.addHandler(consoleHandler);
|
||||
// logger.setLevel(Level.FINE);
|
||||
|
||||
if (akismet.verifyKey()) {
|
||||
final boolean isSpam = akismet.checkComment(comment);
|
||||
|
|
|
@ -2,18 +2,14 @@ package com.example
|
|||
|
||||
import net.thauvin.erik.akismet.Akismet
|
||||
import net.thauvin.erik.akismet.AkismetComment
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
if (args.size == 1 && args[0].isNotEmpty()) {
|
||||
val akismet = Akismet(apiKey = args[0], blog = "https://yourblogdomainname.com/blog/")
|
||||
val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0")
|
||||
|
||||
with(comment) {
|
||||
val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0").apply {
|
||||
isTest = true
|
||||
|
||||
referrer = "https://www.google.com"
|
||||
permalink = "${akismet.blog}post=1"
|
||||
type = AkismetComment.TYPE_COMMENT
|
||||
|
@ -21,7 +17,7 @@ fun main(args: Array<String>) {
|
|||
authorEmail = "test@test.com"
|
||||
authorUrl = "https://www.CheckOutMyCoolSite.com"
|
||||
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."
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ class AkismetServlet : HttpServlet() {
|
|||
|
||||
akismet.appUserAgent = request.servletContext.serverInfo
|
||||
|
||||
val comment = AkismetComment(request)
|
||||
with(comment) {
|
||||
val comment = AkismetComment(request).apply {
|
||||
permalink = "${akismet.blog}/comment/$id"
|
||||
type = AkismetComment.TYPE_COMMENT
|
||||
author = request.getParameter("name")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue