diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-03-24 00:47:57 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-03-24 00:47:57 +0100 |
commit | 168c96733d8fa9ccb78f0b84376b053e8d7ee03e (patch) | |
tree | b0c2aa09851492a2382fa01f0f91c47c65417a81 /kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision | |
parent | 38d8447b7024112f54a4d2a4404840cae5e4d849 (diff) | |
download | kvision-168c96733d8fa9ccb78f0b84376b053e8d7ee03e.tar.gz kvision-168c96733d8fa9ccb78f0b84376b053e8d7ee03e.tar.bz2 kvision-168c96733d8fa9ccb78f0b84376b053e8d7ee03e.zip |
New RestClient class in the core module.
Diffstat (limited to 'kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision')
-rw-r--r-- | kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt | 236 |
1 files changed, 0 insertions, 236 deletions
diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt index 924a84c1..64c257cd 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/CallAgent.kt @@ -21,18 +21,12 @@ */ package pl.treksoft.kvision.remote -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.DynamicObjectParser import kotlinx.serialization.ImplicitReflectionSerializer -import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.serializer import kotlinx.serialization.stringify import pl.treksoft.jquery.JQueryAjaxSettings import pl.treksoft.jquery.JQueryXHR import pl.treksoft.jquery.jQuery -import pl.treksoft.kvision.remote.JSON.toObj import kotlin.js.Promise -import kotlin.js.then import kotlin.js.undefined import kotlin.js.JSON as NativeJSON @@ -147,234 +141,4 @@ open class CallAgent { }) } } - - /** - * Makes a remote call to the remote server. - * @param url an URL address - * @param data data to be sent - * @param deserializer a deserializer for the result value - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @param transform a function to transform the result of the call - * @return a promise of the result - */ - fun <T : Any> remoteCall( - url: String, - data: dynamic = null, - deserializer: DeserializationStrategy<T>, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, - transform: ((dynamic) -> dynamic)? = null - ): Promise<T> { - return remoteCall(url, data, method, contentType, beforeSend).then { result: dynamic -> - val transformed = if (transform != null) { - transform(result) - } else { - result - } - DynamicObjectParser().parse(transformed, deserializer) - } - } - - /** - * Makes a remote call to the remote server. - * @param url an URL address - * @param serializer for the data - * @param data data to be sent - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @return a promise of the result - */ - fun <V : Any> remoteCall( - url: String, - serializer: SerializationStrategy<V>, - data: V, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null - ): Promise<dynamic> { - return remoteCall(url, data.toObj(serializer), method, contentType, beforeSend) - } - - - /** - * Makes a remote call to the remote server. - * @param url an URL address - * @param serializer for the data - * @param data data to be sent - * @param deserializer a deserializer for the result value - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @param transform a function to transform the result of the call - * @return a promise of the result - */ - fun <T : Any, V : Any> remoteCall( - url: String, - serializer: SerializationStrategy<V>, - data: V, - deserializer: DeserializationStrategy<T>, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, - transform: ((dynamic) -> dynamic)? = null - ): Promise<T> { - return remoteCall(url, data.toObj(serializer), method, contentType, beforeSend).then { result: dynamic -> - val transformed = if (transform != null) { - transform(result) - } else { - result - } - DynamicObjectParser().parse(transformed, deserializer) - } - } - - /** - * Helper inline function to automatically get deserializer for the result value with dynamic data. - * @param url an URL address - * @param data data to be sent - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @param transform a function to transform the result of the call - * @return a promise of the result - */ - @UseExperimental(ImplicitReflectionSerializer::class) - inline fun <reified T : Any> call( - url: String, - data: dynamic = null, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - noinline beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, - noinline transform: ((dynamic) -> dynamic)? = null - ): Promise<T> { - return remoteCall(url, data, T::class.serializer(), method, contentType, beforeSend, transform) - } - - /** - * Helper inline function to automatically get serializer for the data. - * @param url an URL address - * @param data data to be sent - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @return a promise of the result - */ - @UseExperimental(ImplicitReflectionSerializer::class) - inline fun <reified V : Any> call( - url: String, - data: V, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - noinline beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null - ): Promise<dynamic> { - return remoteCall( - url, - V::class.serializer(), - data, - method, - contentType, - beforeSend - ) - } - - /** - * Helper inline function to automatically get serializer for the data. - * @param url an URL address - * @param data data to be sent - * @param deserializer a deserializer for the result value - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @param transform a function to transform the result of the call - * @return a promise of the result - */ - @UseExperimental(ImplicitReflectionSerializer::class) - inline fun <T : Any, reified V : Any> call( - url: String, - data: V, - deserializer: DeserializationStrategy<T>, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - noinline beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, - noinline transform: ((dynamic) -> dynamic)? = null - ): Promise<T> { - return remoteCall( - url, - V::class.serializer(), - data, - deserializer, - method, - contentType, - beforeSend, - transform - ) - } - - /** - * Helper inline function to automatically deserializer for the result value with typed data. - * @param url an URL address - * @param serializer for the data - * @param data data to be sent - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @param transform a function to transform the result of the call - * @return a promise of the result - */ - @UseExperimental(ImplicitReflectionSerializer::class) - inline fun <reified T : Any, V : Any> call( - url: String, - serializer: SerializationStrategy<V>, - data: V, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - noinline beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, - noinline transform: ((dynamic) -> dynamic)? = null - ): Promise<T> { - return remoteCall( - url, - serializer, - data, - T::class.serializer(), - method, - contentType, - beforeSend, - transform - ) - } - - /** - * Helper inline function to automatically get serializer for the data and deserializer for the result value. - * @param url an URL address - * @param data data to be sent - * @param method a HTTP method - * @param contentType a content type of the request - * @param beforeSend a content type of the request - * @param transform a function to transform the result of the call - * @return a promise of the result - */ - @UseExperimental(ImplicitReflectionSerializer::class) - inline fun <reified T : Any, reified V : Any> call( - url: String, - data: V, - method: HttpMethod = HttpMethod.GET, - contentType: String = "application/json", - noinline beforeSend: ((JQueryXHR, JQueryAjaxSettings) -> Boolean)? = null, - noinline transform: ((dynamic) -> dynamic)? = null - ): Promise<T> { - return remoteCall( - url, - V::class.serializer(), - data, - T::class.serializer(), - method, - contentType, - beforeSend, - transform - ) - } } |