Fixed detekt warnings.
This commit is contained in:
parent
969768ff73
commit
fd7d31775a
1 changed files with 17 additions and 17 deletions
|
@ -37,6 +37,7 @@ import okhttp3.Request
|
||||||
import org.xml.sax.InputSource
|
import org.xml.sax.InputSource
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
|
import java.net.MalformedURLException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
@ -110,7 +111,7 @@ open class PinboardPoster() {
|
||||||
constructor(propertiesFile: File, key: String = Constants.ENV_API_TOKEN) : this(propertiesFile.toPath(), key)
|
constructor(propertiesFile: File, key: String = Constants.ENV_API_TOKEN) : this(propertiesFile.toPath(), key)
|
||||||
|
|
||||||
/** The API token. **/
|
/** The API token. **/
|
||||||
var apiToken: String = if (System.getenv(Constants.ENV_API_TOKEN).isNullOrBlank()) "" else System.getenv(Constants.ENV_API_TOKEN)
|
var apiToken: String = System.getenv(Constants.ENV_API_TOKEN) ?: ""
|
||||||
|
|
||||||
/** The API end point. **/
|
/** The API end point. **/
|
||||||
var apiEndPoint: String = Constants.API_ENDPOINT
|
var apiEndPoint: String = Constants.API_ENDPOINT
|
||||||
|
@ -258,29 +259,28 @@ open class PinboardPoster() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validate(): Boolean {
|
private fun validate(): Boolean {
|
||||||
if (apiToken.isBlank() || !apiToken.contains(':')) {
|
var isValid = true
|
||||||
|
if (!apiToken.contains(':')) {
|
||||||
logger.severe("Please specify a valid API token. (eg. user:TOKEN)")
|
logger.severe("Please specify a valid API token. (eg. user:TOKEN)")
|
||||||
return false
|
isValid = false
|
||||||
} else if (!validateUrl(apiEndPoint)) {
|
} else if (!validateUrl(apiEndPoint)) {
|
||||||
logger.severe("Please specify a valid API end point. (eg. ${Constants.API_ENDPOINT})")
|
logger.severe("Please specify a valid API end point. (eg. ${Constants.API_ENDPOINT})")
|
||||||
return false
|
isValid = false
|
||||||
}
|
}
|
||||||
return true
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateUrl(url: String): Boolean {
|
private fun validateUrl(url: String): Boolean {
|
||||||
if (url.isBlank()) {
|
var isValid = url.isNotBlank()
|
||||||
return false
|
if (isValid) {
|
||||||
|
try {
|
||||||
|
URL(url)
|
||||||
|
} catch (e: MalformedURLException) {
|
||||||
|
logger.log(Level.FINE, "Invalid URL: $url", e)
|
||||||
|
isValid = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return isValid
|
||||||
try {
|
|
||||||
URL(url)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.log(Level.FINE, "Invalid URL: $url", e)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun yesNo(bool: Boolean): String {
|
private fun yesNo(bool: Boolean): String {
|
||||||
|
@ -290,4 +290,4 @@ open class PinboardPoster() {
|
||||||
"no"
|
"no"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue