Updated examples.

This commit is contained in:
Erik C. Thauvin 2019-09-20 07:02:44 -07:00
parent 2549b97aa9
commit 7e3cd3b19f
2 changed files with 32 additions and 68 deletions

View file

@ -1,19 +1,25 @@
package com.example; package com.example;
import net.thauvin.erik.akismet.Akismet; import net.thauvin.erik.akismet.Akismet;
import net.thauvin.erik.akismet.AkismetComment;
public class AkismetSample { public class AkismetSample {
public static void main(String[] args) { public static void main(String[] args) {
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();
final String userIp = "127.0.0.1"; comment.setTest(true);
final String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6";
final String author = "admin";
final String authorEmail = "test@test.com";
final String authorUrl = "http://www.CheckOutMyCoolSite.com";
final String content = "It means a lot that you would take the time to review our software. Thanks again.";
akismet.setTest(true); comment.setUserIp("127.0.0.1");
comment.setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6");
comment.setReferrer("http://www.google.com");
comment.setPermalink("http://yourblogdomainname.com/blog/post=1");
comment.setType(AkismetComment.TYPE_COMMENT);
comment.setAuthor("admin");
comment.setAuthorEmail("test@test.com");
comment.setAuthorUrl("http://www.CheckOutMyCoolSite.com");
// 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(); // final ConsoleHandler consoleHandler = new ConsoleHandler();
// consoleHandler.setLevel(Level.FINE); // consoleHandler.setLevel(Level.FINE);
@ -22,42 +28,18 @@ public class AkismetSample {
// logger.setLevel(Level.FINE); // logger.setLevel(Level.FINE);
if (akismet.verifyKey()) { if (akismet.verifyKey()) {
final boolean isSpam = akismet.checkComment(userIp, final boolean isSpam = akismet.checkComment(comment);
userAgent,
"",
"",
Akismet.COMMENT_TYPE_COMMENT,
author,
authorEmail,
authorUrl,
content);
if (isSpam) { if (isSpam) {
System.out.println("The comment is SPAM according to Akismet."); System.out.println("The comment is SPAM according to Akismet.");
final boolean hasBenSubmitted = akismet.submitSpam(userIp, final boolean hasBenSubmitted = akismet.submitSpam(comment);
userAgent,
"",
"",
Akismet.COMMENT_TYPE_COMMENT,
author,
authorEmail,
authorUrl,
content);
if (hasBenSubmitted) { if (hasBenSubmitted) {
System.out.println("The comment has been submitted as SPAM to Akismet"); System.out.println("The comment has been submitted as SPAM to Akismet");
} }
} else { } else {
System.out.println("The comment is not SPAM (HAM) according to Akismet."); System.out.println("The comment is not SPAM (HAM) according to Akismet.");
final boolean hasBeenSubmitted = akismet.submitHam(userIp, final boolean hasBeenSubmitted = akismet.submitHam(comment);
userAgent,
"",
"",
Akismet.COMMENT_TYPE_COMMENT,
author,
authorEmail,
authorUrl,
content);
if (hasBeenSubmitted) { if (hasBeenSubmitted) {
System.out.println("The comment has been submitted as HAM to Akismet"); System.out.println("The comment has been submitted as HAM to Akismet");
} }

View file

@ -1,19 +1,23 @@
package com.example package com.example
import net.thauvin.erik.akismet.Akismet import net.thauvin.erik.akismet.Akismet
import net.thauvin.erik.akismet.AkismetComment
import kotlin.system.exitProcess import kotlin.system.exitProcess
fun main() { fun main() {
val akismet = Akismet("YOUR_API_KEY", "YOUR_BLOG_URL") val akismet = Akismet("YOUR_API_KEY", "YOUR_BLOG_URL")
val comment = AkismetComment(
val userIp = "127.0.0.1" userIp = "127.0.0.1",
val 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",
val author = "admin" referrer = "http://www.google.com",
val authorEmail = "test@test.com" permalink = "http://yourblogdomainname.com/blog/post=1",
val authorUrl = "http://www.CheckOutMyCoolSite.com" type = AkismetComment.TYPE_COMMENT,
val content = "It means a lot that you would take the time to review our software. Thanks again." author = "admin",
authorEmail = "test@test.com",
akismet.isTest = true authorUrl = "http://www.CheckOutMyCoolSite.com",
// userRole = AkismetComment.ADMIN_ROLE,
content = "It means a lot that you would take the time to review our software. Thanks again.",
isTest = true)
// with(akismet.logger) { // with(akismet.logger) {
// addHandler(ConsoleHandler().apply { level = Level.FINE }) // addHandler(ConsoleHandler().apply { level = Level.FINE })
@ -21,26 +25,11 @@ fun main() {
// } // }
if (akismet.verifyKey()) { if (akismet.verifyKey()) {
val isSpam = akismet.checkComment( val isSpam = akismet.checkComment(comment)
userIp = userIp,
userAgent = userAgent,
type = Akismet.COMMENT_TYPE_COMMENT,
author = author,
authorEmail = authorEmail,
authorUrl = authorUrl,
userRole = Akismet.ADMIN_ROLE,
content = content)
if (isSpam) { if (isSpam) {
println("The comment is SPAM according to Akismet.") println("The comment is SPAM according to Akismet.")
val hasBeenSubmitted = akismet.submitSpam( val hasBeenSubmitted = akismet.submitSpam(comment)
userIp = userIp,
userAgent = userAgent,
type = Akismet.COMMENT_TYPE_COMMENT,
author = author,
authorEmail = authorEmail,
authorUrl = authorUrl,
content = content)
if (hasBeenSubmitted) { if (hasBeenSubmitted) {
println("The comment was successfully submitted as SPAM to Akismet.") println("The comment was successfully submitted as SPAM to Akismet.")
@ -48,14 +37,7 @@ fun main() {
} else { } else {
println("The comment is not SPAM (HAM) according to Akismet.") println("The comment is not SPAM (HAM) according to Akismet.")
val hasBeenSubmitted = akismet.submitHam( val hasBeenSubmitted = akismet.submitHam(comment)
userIp = userIp,
userAgent = userAgent,
type = Akismet.COMMENT_TYPE_COMMENT,
author = author,
authorEmail = authorEmail,
authorUrl = authorUrl,
content = content)
if (hasBeenSubmitted) { if (hasBeenSubmitted) {
println("The comment was successfully submitted as HAM to Akismet.") println("The comment was successfully submitted as HAM to Akismet.")