Moved from Gradle to bld
This commit is contained in:
parent
7ef1c441e6
commit
d5e21dd3a1
194 changed files with 2185 additions and 1983 deletions
64
examples/gradle/src/main/java/com/example/AkismetSample.java
Normal file
64
examples/gradle/src/main/java/com/example/AkismetSample.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package com.example;
|
||||
|
||||
import net.thauvin.erik.akismet.Akismet;
|
||||
import net.thauvin.erik.akismet.AkismetComment;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
if (akismet.verifyKey()) {
|
||||
final boolean isSpam = akismet.checkComment(comment);
|
||||
if (isSpam) {
|
||||
System.out.println("The comment is SPAM according to Akismet.");
|
||||
|
||||
final boolean hasBeenSubmitted = akismet.submitSpam(comment);
|
||||
if (hasBeenSubmitted) {
|
||||
System.out.println("The comment has been submitted as SPAM to Akismet");
|
||||
} else {
|
||||
System.err.println(akismet.getErrorMessage());
|
||||
}
|
||||
} else {
|
||||
System.out.println("The comment is not SPAM according to Akismet.");
|
||||
|
||||
final boolean hasBeenSubmitted = akismet.submitHam(comment);
|
||||
if (hasBeenSubmitted) {
|
||||
System.out.println("The comment has been submitted as HAM to Akismet");
|
||||
} else {
|
||||
System.err.println(akismet.getErrorMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("Invalid API Key.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.err.println("Please specify an API key.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.example
|
||||
|
||||
import net.thauvin.erik.akismet.Akismet
|
||||
import net.thauvin.erik.akismet.AkismetComment
|
||||
import java.util.Date
|
||||
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) {
|
||||
isTest = true
|
||||
|
||||
referrer = "https://www.google.com"
|
||||
permalink = "${akismet.blog}post=1"
|
||||
type = AkismetComment.TYPE_COMMENT
|
||||
author = "admin"
|
||||
authorEmail = "test@test.com"
|
||||
authorUrl = "https://www.CheckOutMyCoolSite.com"
|
||||
dateGmt = Akismet.dateToGmt(Date())
|
||||
// userRole = AkismetComment.ADMIN_ROLE
|
||||
content = "It means a lot that you would take the time to review our software. Thanks again."
|
||||
}
|
||||
|
||||
// with(akismet.logger) {
|
||||
// addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
// level = Level.FINE
|
||||
// }
|
||||
|
||||
if (akismet.verifyKey()) {
|
||||
val isSpam = akismet.checkComment(comment)
|
||||
if (isSpam) {
|
||||
println("The comment is SPAM according to Akismet.")
|
||||
|
||||
val hasBeenSubmitted = akismet.submitSpam(comment)
|
||||
|
||||
if (hasBeenSubmitted) {
|
||||
println("The comment was successfully submitted as SPAM to Akismet.")
|
||||
} else {
|
||||
System.err.println(akismet.errorMessage)
|
||||
}
|
||||
} else {
|
||||
println("The comment is not SPAM according to Akismet.")
|
||||
|
||||
val hasBeenSubmitted = akismet.submitHam(comment)
|
||||
|
||||
if (hasBeenSubmitted) {
|
||||
println("The comment was successfully submitted as HAM to Akismet.")
|
||||
} else {
|
||||
System.err.println(akismet.errorMessage)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("Invalid API Key.")
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
exitProcess(0)
|
||||
} else {
|
||||
System.err.println("Please specify an API key.")
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.example
|
||||
|
||||
import jakarta.servlet.ServletException
|
||||
import jakarta.servlet.annotation.WebServlet
|
||||
import jakarta.servlet.http.HttpServlet
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import jakarta.servlet.http.HttpServletResponse
|
||||
import net.thauvin.erik.akismet.Akismet
|
||||
import net.thauvin.erik.akismet.AkismetComment
|
||||
import java.io.IOException
|
||||
import java.util.Date
|
||||
|
||||
@WebServlet(description = "Akismet Servlet", displayName = "Akismet", urlPatterns = ["/comment/*"])
|
||||
class AkismetServlet : HttpServlet() {
|
||||
private val akismet = Akismet("YOUR_API_KEY", "http://yourblogdomainname.com/blog/")
|
||||
|
||||
@Throws(ServletException::class, IOException::class)
|
||||
public override fun service(request: HttpServletRequest, response: HttpServletResponse) {
|
||||
val id = request.getParameter("id")
|
||||
|
||||
akismet.appUserAgent = request.servletContext.serverInfo
|
||||
|
||||
val comment = AkismetComment(request)
|
||||
with(comment) {
|
||||
permalink = "${akismet.blog}/comment/$id"
|
||||
type = AkismetComment.TYPE_COMMENT
|
||||
author = request.getParameter("name")
|
||||
authorEmail = request.getParameter("email")
|
||||
dateGmt = Akismet.dateToGmt(Date())
|
||||
content = request.getParameter("comment")
|
||||
}
|
||||
|
||||
val isSpam = akismet.checkComment(comment)
|
||||
|
||||
saveComment(
|
||||
id = id,
|
||||
name = comment.author,
|
||||
email = comment.authorEmail,
|
||||
date = comment.dateGmt,
|
||||
comment = comment.content,
|
||||
json = comment.toJson(),
|
||||
isSpam = isSpam
|
||||
)
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
private fun saveComment(
|
||||
id: String,
|
||||
name: String?,
|
||||
email: String?,
|
||||
date: String?,
|
||||
comment: String?,
|
||||
json: String,
|
||||
isSpam: Boolean
|
||||
) {
|
||||
// ...
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue