Replaced List of pairs with Map.

This commit is contained in:
Erik C. Thauvin 2021-05-23 12:30:14 -07:00
parent 5ed71cb447
commit ba4a374853
2 changed files with 13 additions and 13 deletions

View file

@ -3,7 +3,7 @@
<ManuallySuppressedIssues/> <ManuallySuppressedIssues/>
<CurrentIssues> <CurrentIssues>
<ID>LongParameterList:PinboardPoster.kt$PinboardPoster$( url: String, description: String, extended: String = "", tags: String = "", dt: String = "", replace: Boolean = true, shared: Boolean = true, toRead: Boolean = false )</ID> <ID>LongParameterList:PinboardPoster.kt$PinboardPoster$( url: String, description: String, extended: String = "", tags: String = "", dt: String = "", replace: Boolean = true, shared: Boolean = true, toRead: Boolean = false )</ID>
<ID>NestedBlockDepth:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: List&lt;Pair&lt;String, String>>): Boolean</ID> <ID>NestedBlockDepth:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: Map&lt;String, String>): Boolean</ID>
<ID>ThrowsCount:PinboardPoster.kt$PinboardPoster$@Throws(IOException::class) internal fun parseMethodResponse(method: String, response: String)</ID> <ID>ThrowsCount:PinboardPoster.kt$PinboardPoster$@Throws(IOException::class) internal fun parseMethodResponse(method: String, response: String)</ID>
</CurrentIssues> </CurrentIssues>
</SmellBaseline> </SmellBaseline>

View file

@ -167,15 +167,15 @@ open class PinboardPoster() {
} else if (description.isBlank()) { } else if (description.isBlank()) {
logger.severe("Please specify a valid description to pin: `$url`") logger.severe("Please specify a valid description to pin: `$url`")
} else { } else {
val params = listOf( val params = mapOf(
Pair("url", url), "url" to url,
Pair("description", description), "description" to description,
Pair("extended", extended), "extended" to extended,
Pair("tags", tags), "tags" to tags,
Pair("dt", dt), "dt" to dt,
Pair("replace", yesNo(replace)), "replace" to yesNo(replace),
Pair("shared", yesNo(shared)), "shared" to yesNo(shared),
Pair("toread", yesNo(toRead)) "toread" to yesNo(toRead)
) )
return executeMethod("posts/add", params) return executeMethod("posts/add", params)
} }
@ -198,7 +198,7 @@ open class PinboardPoster() {
if (!validateUrl(url)) { if (!validateUrl(url)) {
logger.severe("Please specify a valid URL to delete.") logger.severe("Please specify a valid URL to delete.")
} else { } else {
return executeMethod("posts/delete", listOf(Pair("url", url))) return executeMethod("posts/delete", mapOf("url" to url))
} }
} }
@ -244,13 +244,13 @@ open class PinboardPoster() {
} }
} }
private fun executeMethod(method: String, params: List<Pair<String, String>>): Boolean { private fun executeMethod(method: String, params: Map<String, String>): Boolean {
try { try {
val apiUrl = cleanEndPoint(method).toHttpUrlOrNull() val apiUrl = cleanEndPoint(method).toHttpUrlOrNull()
if (apiUrl != null) { if (apiUrl != null) {
val httpUrl = apiUrl.newBuilder().apply { val httpUrl = apiUrl.newBuilder().apply {
params.forEach { params.forEach {
addQueryParameter(it.first, it.second) addQueryParameter(it.key, it.value)
} }
addQueryParameter("auth_token", apiToken) addQueryParameter("auth_token", apiToken)
}.build() }.build()