Added toApiUrl() extension.
This commit is contained in:
parent
a995ae2af5
commit
bd27e0b7af
1 changed files with 9 additions and 8 deletions
|
@ -251,7 +251,7 @@ open class Akismet(apiKey: String) {
|
||||||
add("key", apiKey)
|
add("key", apiKey)
|
||||||
add("blog", blog)
|
add("blog", blog)
|
||||||
}.build()
|
}.build()
|
||||||
isVerifiedKey = executeMethod(buildApiUrl(verifyMethod), body)
|
isVerifiedKey = executeMethod(verifyMethod.toApiUrl(), body)
|
||||||
return isVerifiedKey
|
return isVerifiedKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ open class Akismet(apiKey: String) {
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun checkComment(comment: AkismetComment, trueOnError: Boolean = false): Boolean {
|
fun checkComment(comment: AkismetComment, trueOnError: Boolean = false): Boolean {
|
||||||
return executeMethod(buildApiUrl("comment-check"), buildFormBody(comment), trueOnError)
|
return executeMethod("comment-check".toApiUrl(), buildFormBody(comment), trueOnError)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -293,7 +293,7 @@ open class Akismet(apiKey: String) {
|
||||||
* @return `true` if the comment was submitted, `false` otherwise.
|
* @return `true` if the comment was submitted, `false` otherwise.
|
||||||
*/
|
*/
|
||||||
fun submitSpam(comment: AkismetComment): Boolean {
|
fun submitSpam(comment: AkismetComment): Boolean {
|
||||||
return executeMethod(buildApiUrl("submit-spam"), buildFormBody(comment))
|
return executeMethod("submit-spam".toApiUrl(), buildFormBody(comment))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -315,7 +315,7 @@ open class Akismet(apiKey: String) {
|
||||||
* @return `true` if the comment was submitted, `false` otherwise.
|
* @return `true` if the comment was submitted, `false` otherwise.
|
||||||
*/
|
*/
|
||||||
fun submitHam(comment: AkismetComment): Boolean {
|
fun submitHam(comment: AkismetComment): Boolean {
|
||||||
return executeMethod(buildApiUrl("submit-ham"), buildFormBody(comment))
|
return executeMethod("submit-ham".toApiUrl(), buildFormBody(comment))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,11 +385,12 @@ open class Akismet(apiKey: String) {
|
||||||
response = ""
|
response = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildApiUrl(method: String): HttpUrl? {
|
private fun String.toApiUrl(): HttpUrl? {
|
||||||
if (method == verifyMethod) {
|
return if (this == verifyMethod) {
|
||||||
return String.format(apiEndPoint, "", method).toHttpUrlOrNull()
|
String.format(apiEndPoint, "", this).toHttpUrlOrNull()
|
||||||
|
} else {
|
||||||
|
String.format(apiEndPoint, "$apiKey.", this).toHttpUrlOrNull()
|
||||||
}
|
}
|
||||||
return String.format(apiEndPoint, "$apiKey.", method).toHttpUrlOrNull()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildFormBody(comment: AkismetComment): FormBody {
|
private fun buildFormBody(comment: AkismetComment): FormBody {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue