blog is now a property.
This commit is contained in:
parent
980634c8ce
commit
69950df25e
1 changed files with 19 additions and 11 deletions
|
@ -50,15 +50,10 @@ import javax.servlet.http.HttpServletRequest
|
||||||
/**
|
/**
|
||||||
* A small Kotlin/Java library for accessing the Akismet service.
|
* A small Kotlin/Java library for accessing the Akismet service.
|
||||||
*
|
*
|
||||||
* @constructor Creates a new instance.
|
* @constructor Create new instance using the provided [Akismet](https://www.askimet.com/) API key.
|
||||||
*
|
|
||||||
* @param apiKey The [Akismet](https://www.askimet.com/) API key.
|
|
||||||
* @param blog The URL registered with Akismet.
|
|
||||||
*
|
|
||||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
|
||||||
*/
|
*/
|
||||||
@Version(properties = "version.properties", type = "kt")
|
@Version(properties = "version.properties", type = "kt")
|
||||||
open class Akismet(apiKey: String, blog: String) {
|
open class Akismet(apiKey: String) {
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
companion object {
|
companion object {
|
||||||
/** A blog comment. */
|
/** A blog comment. */
|
||||||
|
@ -75,7 +70,7 @@ open class Akismet(apiKey: String, blog: String) {
|
||||||
const val COMMENT_TYPE_SIGNUP = "signup"
|
const val COMMENT_TYPE_SIGNUP = "signup"
|
||||||
/** A message sent between just a few users. */
|
/** A message sent between just a few users. */
|
||||||
const val COMMENT_TYPE_MESSAGE = "message"
|
const val COMMENT_TYPE_MESSAGE = "message"
|
||||||
/** Administrator role */
|
/** Administrator role. If used, Akismet will always return false. */
|
||||||
const val ADMIN_ROLE = "administrator"
|
const val ADMIN_ROLE = "administrator"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,9 +78,17 @@ open class Akismet(apiKey: String, blog: String) {
|
||||||
private val libUserAgent = "${GeneratedVersion.PROJECT}/${GeneratedVersion.VERSION}"
|
private val libUserAgent = "${GeneratedVersion.PROJECT}/${GeneratedVersion.VERSION}"
|
||||||
private val verifyMethod = "verify-key"
|
private val verifyMethod = "verify-key"
|
||||||
private var apiKey: String
|
private var apiKey: String
|
||||||
private var blog: String
|
|
||||||
private var client: OkHttpClient
|
private var client: OkHttpClient
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL registered with Akismet.
|
||||||
|
*/
|
||||||
|
var blog = ""
|
||||||
|
set(value) {
|
||||||
|
require(!value.isBlank()) { "A Blog URL must be specified." }
|
||||||
|
field = value
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the API Key has been verified.
|
* Check if the API Key has been verified.
|
||||||
*/
|
*/
|
||||||
|
@ -127,10 +130,8 @@ open class Akismet(apiKey: String, blog: String) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(!apiKey.isBlank() || apiKey.length != 12) { "An Akismet API key must be specified." }
|
require(!apiKey.isBlank() || apiKey.length != 12) { "An Akismet API key must be specified." }
|
||||||
require(!blog.isBlank()) { "A Blog URL must be specified." }
|
|
||||||
|
|
||||||
this.apiKey = apiKey
|
this.apiKey = apiKey
|
||||||
this.blog = blog
|
|
||||||
|
|
||||||
val logging = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger {
|
val logging = HttpLoggingInterceptor(object : HttpLoggingInterceptor.Logger {
|
||||||
override fun log(message: String) {
|
override fun log(message: String) {
|
||||||
|
@ -143,6 +144,13 @@ open class Akismet(apiKey: String, blog: String) {
|
||||||
client = OkHttpClient.Builder().addInterceptor(logging).build()
|
client = OkHttpClient.Builder().addInterceptor(logging).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance using [Akismet](https://www.askimet.com/) API key and blog URL registered with Akismet.
|
||||||
|
*/
|
||||||
|
constructor(apiKey: String, blog: String) : this(apiKey) {
|
||||||
|
this.blog = blog
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key Verification.
|
* Key Verification.
|
||||||
* See the [Akismet API](https://akismet.com/development/api/#verify-key) for more details.
|
* See the [Akismet API](https://akismet.com/development/api/#verify-key) for more details.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue