项目作者: ethauvin

项目描述 :
Akismet for Kotlin/Java/Android, a client library for accessing the Automattic Kismet (Akismet) spam comments filtering service.
高级语言: Kotlin
项目地址: git://github.com/ethauvin/akismet-kotlin.git
创建时间: 2019-09-20T02:49:22Z
项目社区:https://github.com/ethauvin/akismet-kotlin

开源协议:BSD 3-Clause "New" or "Revised" License

下载


License (3-Clause BSD)
Kotlin
bld
Release
Nexus Snapshot
Maven Central

Quality Gate Status
GitHub CI
CircleCI

Akismet for Kotlin, Java and Android

A pretty complete and straightforward implementation of the Automattic’s Akismet API, a free service which can be used to actively stop comments spam.

Examples (TL;DR)

Kotlin

  1. val akismet = Akismet(apiKey = "YOUR_API_KEY", blog = "YOUR_BLOG_URL")
  2. val comment = AkismetComment(userIp = "127.0.0.1", userAgent = "curl/7.29.0").apply {
  3. referrer = "https://www.google.com"
  4. type = CommentType.COMMENT
  5. author = "admin"
  6. authorEmail = "test@test.com"
  7. authorUrl = "https://www.CheckOutMyCoolSite.com"
  8. dateGmt = Akismet.dateToGmt(Date())
  9. content = "Thanks for reviewing our software."
  10. }
  11. // ...
  12. val isSpam = akismet.checkComment(comment)
  13. if (isSpam) {
  14. // ...
  15. }

View Full Examples

Java

  1. final Akismet akismet = new Akismet("YOUR_API_KEY", "YOUR_BLOG_URL");
  2. final AkismetComment comment = new AkismetComment(
  3. new CommentConfig.Builder("127.0.0.1", "curl/7.29.0")
  4. .referrer("https://www.google.com")
  5. .type(CommentType.COMMENT)
  6. .author("admin")
  7. .authorEmail("test@test.com")
  8. .authorUrl("https://www.CheckOutMyCoolSite.com")
  9. .dateGmt(Akismet.dateToGmt(new Date()))
  10. .content("Thanks for reviewing our software.")
  11. .build
  12. );
  13. //...
  14. final boolean isSpam = akismet.checkComment(comment);
  15. if (isSpam) {
  16. // ...
  17. }

View Full Examples

bld

To use with bld, include the following dependency in your build file:

  1. repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY);
  2. scope(compile)
  3. .include(dependency("net.thauvin.erik:akismet-kotlin:1.1.0-SNAPSHOT"));

Gradle

To use with Gradle, include the following dependency in your build file:

  1. repositories {
  2. mavenCentral()
  3. }
  4. dependencies {
  5. implementation("net.thauvin.erik:akismet-kotlin:1.1.0-SNAPSHOT")
  6. }

Instructions for using with Maven, Ivy, etc. can be found on Maven Central.

HttpServletRequest

The more information is sent to Akismet, the more accurate the response is. An HttpServletRequest can be used as a parameter so that all the relevant information is automatically included.

  1. AkismetComment(request = context.getRequest())

This will ensure that the user’s IP, agent, referrer and various environment variables are automatically extracted from the request.

View Full Example

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.

  1. var json = comment.toJson()

At a latter time, the comment can then be submitted:

  1. akismet.submitSpam(Akismet.jsonComment(json))

Contributing

If you want to contribute to this project, all you have to do is clone the GitHub
repository:

  1. git clone git@github.com:ethauvin/akismet-kotlin.git

Then use bld to build:

  1. cd akismet-kotlin
  2. ./bld compile

The project has an IntelliJ IDEA project structure. You can just open it after all the dependencies were downloaded and peruse the code.

More…

If all else fails, there’s always more Documentation.