The basics for now.
This commit is contained in:
parent
b8df369f0a
commit
47210fd592
1 changed files with 73 additions and 0 deletions
73
README.md
Normal file
73
README.md
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
[](http://opensource.org/licenses/BSD-3-Clause)
|
||||||
|
[](https://snyk.io/test/github/ethauvin/akismet-kotlin?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_akismet-kotlin) [](https://travis-ci.org/ethauvin/akismet-kotlin) [](https://circleci.com/gh/ethauvin/akismet-kotlin/tree/master)
|
||||||
|
|
||||||
|
# [Akismet](https://www.akismet.com) for Kotlin/Java
|
||||||
|
|
||||||
|
Akismet for Kotlin/Java is a pretty complete and straightforward implementation of the [Automattic's Akismet](https://www.akismet.com/) API, a free service that can be used to actively stop comments spam.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
#### Kotlin
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val akismet = Akismet("YOUR_API_KEY", "YOUR_BLOG_URL")
|
||||||
|
val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0")
|
||||||
|
|
||||||
|
comment.setReferrer("http://www.google.com");
|
||||||
|
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.setContent("It means a lot that you would take the time to review our software.");
|
||||||
|
|
||||||
|
val isSpam = akismet.checkComment(comment)
|
||||||
|
if (isSpam) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Java
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Akismet akismet = new Akismet("YOUR_API_KEY", "YOUR_BLOG_URL");
|
||||||
|
final AkismetComment comment = new AkismetComment("127.0.0.1", "curl/7.29.0");
|
||||||
|
|
||||||
|
comment.setReferrer("http://www.google.com");
|
||||||
|
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.setContent("It means a lot that you would take the time to review our software.");
|
||||||
|
|
||||||
|
final boolean isSpam = akismet.checkComment(comment);
|
||||||
|
if (isSpam) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### HttpServletRequest
|
||||||
|
|
||||||
|
The more information is sent to Akismet, the more accurate the response is. An [HttpServletRequest](https://javaee.github.io/javaee-spec/javadocs/javax/servlet/http/HttpServletRequest.html) can be used as a parameter so that all of the relevant information is automatically included.
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
AkismetComment(request = context.getRequest())
|
||||||
|
```
|
||||||
|
|
||||||
|
This will ensure that the user's IP, agent, referrer and various environment variables are automatically extracted from the request.
|
||||||
|
|
||||||
|
### JSON
|
||||||
|
|
||||||
|
Since comments mis-identified as spam or ham can be submitted to Askimet to improve the service. A comment can be saved as a JSON object to be stored in a database, etc.
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
var json = comment.toString()
|
||||||
|
```
|
||||||
|
|
||||||
|
At a latter time, the comment can the be submitted:
|
||||||
|
|
||||||
|
```
|
||||||
|
akismet.submitSpam(Akismet.jsonComment(json))
|
||||||
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue