fixes in UnifiedRequester

This commit is contained in:
InsanusMokrassar 2021-05-21 18:04:04 +06:00
parent b80f1a0773
commit 13ca419473
2 changed files with 30 additions and 19 deletions

View File

@ -2,6 +2,10 @@
## 0.5.2 ## 0.5.2
* `Ktor`:
* `Client`:
* Fixes in `UnifiedRequester`
## 0.5.1 ## 0.5.1
* `Versions`: * `Versions`:

View File

@ -15,30 +15,21 @@ class UnifiedRequester(
suspend fun <ResultType> uniget( suspend fun <ResultType> uniget(
url: String, url: String,
resultDeserializer: DeserializationStrategy<ResultType> resultDeserializer: DeserializationStrategy<ResultType>
): ResultType = client.get<StandardKtorSerialInputData>( ): ResultType = client.uniget(url, resultDeserializer, serialFormat)
url
).let {
serialFormat.decodeDefault(resultDeserializer, it)
}
fun <T> encodeUrlQueryValue( fun <T> encodeUrlQueryValue(
serializationStrategy: SerializationStrategy<T>, serializationStrategy: SerializationStrategy<T>,
value: T value: T
) = serialFormat.encodeHex( ) = serializationStrategy.encodeUrlQueryValue(
serializationStrategy, value,
value serialFormat
) )
suspend fun <BodyType, ResultType> unipost( suspend fun <BodyType, ResultType> unipost(
url: String, url: String,
bodyInfo: BodyPair<BodyType>, bodyInfo: BodyPair<BodyType>,
resultDeserializer: DeserializationStrategy<ResultType> resultDeserializer: DeserializationStrategy<ResultType>
) = client.post<StandardKtorSerialInputData>(url) { ) = client.unipost(url, bodyInfo, resultDeserializer, serialFormat)
body = serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second)
}.let {
serialFormat.decodeDefault(resultDeserializer, it)
}
fun <T> createStandardWebsocketFlow( fun <T> createStandardWebsocketFlow(
url: String, url: String,
@ -51,14 +42,30 @@ val defaultRequester = UnifiedRequester()
suspend fun <ResultType> HttpClient.uniget( suspend fun <ResultType> HttpClient.uniget(
url: String, url: String,
resultDeserializer: DeserializationStrategy<ResultType> resultDeserializer: DeserializationStrategy<ResultType>,
) = defaultRequester.uniget(url, resultDeserializer) serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat
) = get<StandardKtorSerialInputData>(
url
).let {
serialFormat.decodeDefault(resultDeserializer, it)
}
fun <T> SerializationStrategy<T>.encodeUrlQueryValue(value: T) = defaultRequester.encodeUrlQueryValue(this, value) fun <T> SerializationStrategy<T>.encodeUrlQueryValue(
value: T,
serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat
) = serialFormat.encodeHex(
this,
value
)
suspend fun <BodyType, ResultType> HttpClient.unipost( suspend fun <BodyType, ResultType> HttpClient.unipost(
url: String, url: String,
bodyInfo: BodyPair<BodyType>, bodyInfo: BodyPair<BodyType>,
resultDeserializer: DeserializationStrategy<ResultType> resultDeserializer: DeserializationStrategy<ResultType>,
) = defaultRequester.unipost(url, bodyInfo, resultDeserializer) serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat
) = post<StandardKtorSerialInputData>(url) {
body = serialFormat.encodeDefault(bodyInfo.first, bodyInfo.second)
}.let {
serialFormat.decodeDefault(resultDeserializer, it)
}