update tools for urls
This commit is contained in:
parent
617ac31ca1
commit
9a5585957f
@ -7,3 +7,17 @@ fun buildStandardUrl(
|
||||
) = "$basePart/$subpart".includeQueryParams(
|
||||
parameters
|
||||
)
|
||||
|
||||
fun buildStandardUrl(
|
||||
basePart: String,
|
||||
subpart: String,
|
||||
parameters: List<QueryParam>
|
||||
) = "$basePart/$subpart".includeQueryParams(
|
||||
parameters
|
||||
)
|
||||
|
||||
fun buildStandardUrl(
|
||||
basePart: String,
|
||||
subpart: String,
|
||||
vararg parameters: QueryParam
|
||||
) = buildStandardUrl(basePart, subpart, parameters.toList())
|
||||
|
@ -1,13 +1,22 @@
|
||||
package com.insanusmokrassar.postssystem.ktor
|
||||
|
||||
typealias QueryParam = Pair<String, String?>
|
||||
typealias QueryParams = Map<String, String?>
|
||||
|
||||
val QueryParams.asUrlQuery: String
|
||||
get() = keys.joinToString("&") { "${it}${get(it) ?.let { value -> "=$value" }}" }
|
||||
|
||||
val List<QueryParam>.asUrlQuery: String
|
||||
get() = joinToString("&") { (key, value) -> "${key}${value ?.let { _ -> "=$value" }}" }
|
||||
|
||||
fun String.includeQueryParams(
|
||||
queryParams: QueryParams
|
||||
): String = "$this${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}"
|
||||
|
||||
fun String.includeQueryParams(
|
||||
queryParams: List<QueryParam>
|
||||
): String = "$this${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}"
|
||||
|
||||
val String.parseUrlQuery: QueryParams
|
||||
get() = split("&").map {
|
||||
it.split("=").let { pair ->
|
||||
|
Loading…
Reference in New Issue
Block a user