Added buildUserAgent() function.
This commit is contained in:
parent
ef74c7e5d8
commit
09fad07dc0
1 changed files with 25 additions and 0 deletions
|
@ -70,6 +70,22 @@ open class Akismet(apiKey: String) {
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application name to be used in the user agent string.
|
||||||
|
*
|
||||||
|
* See the [Akismet API](https://akismet.com/development/api/#detailed-docs) for more details.
|
||||||
|
*/
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
|
var applicationName = ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application version to be used in the user agent string.
|
||||||
|
*
|
||||||
|
* See the [Akismet API](https://akismet.com/development/api/#detailed-docs) for more details.
|
||||||
|
*/
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
|
var applicationVersion = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the API Key has been verified.
|
* Check if the API Key has been verified.
|
||||||
*/
|
*/
|
||||||
|
@ -213,6 +229,7 @@ open class Akismet(apiKey: String) {
|
||||||
protected fun executeMethod(apiUrl: HttpUrl?, formBody: FormBody): Boolean {
|
protected fun executeMethod(apiUrl: HttpUrl?, formBody: FormBody): Boolean {
|
||||||
if (apiUrl != null) {
|
if (apiUrl != null) {
|
||||||
val request = Request.Builder().url(apiUrl).post(formBody).header("User-Agent", libUserAgent).build()
|
val request = Request.Builder().url(apiUrl).post(formBody).header("User-Agent", libUserAgent).build()
|
||||||
|
val request = Request.Builder().url(apiUrl).post(formBody).header("User-Agent", buildUserAgent()).build()
|
||||||
try {
|
try {
|
||||||
val result = client.newCall(request).execute()
|
val result = client.newCall(request).execute()
|
||||||
httpStatusCode = result.code
|
httpStatusCode = result.code
|
||||||
|
@ -298,4 +315,12 @@ open class Akismet(apiKey: String) {
|
||||||
comment.serverEnv.forEach { (k, v) -> add(k, v) }
|
comment.serverEnv.forEach { (k, v) -> add(k, v) }
|
||||||
}.build()
|
}.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildUserAgent(): String {
|
||||||
|
return if (applicationName.isNotBlank() && applicationVersion.isBlank()) {
|
||||||
|
"$applicationName/$applicationVersion | $libUserAgent"
|
||||||
|
} else {
|
||||||
|
libUserAgent
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue