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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue