All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequest.kt Maven / Gradle / Ivy
package com.ecwid.apiclient.v3.dto.batch.request
import com.ecwid.apiclient.v3.dto.ApiRequest
import com.ecwid.apiclient.v3.dto.common.ApiRequestDTO
import com.ecwid.apiclient.v3.httptransport.HttpBody
import com.ecwid.apiclient.v3.impl.RequestInfo
import com.ecwid.apiclient.v3.util.buildEndpointPath
import com.ecwid.apiclient.v3.util.buildQueryString
import java.util.UUID
data class CreateBatchRequestWithIds(
val requests: Map = emptyMap(),
val stopOnFirstFailure: Boolean = true,
val allowParallelMode: Boolean = false,
val groupId: String? = null,
val deduplicationKey: UUID = UUID.randomUUID(),
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPostRequest(
pathSegments = listOf(
"batch"
),
params = buildMap {
put("stopOnFirstFailure", stopOnFirstFailure.toString())
put("allowParallelMode", allowParallelMode.toString())
put("deduplicationKey", deduplicationKey.toString())
groupId?.let { put("groupId", it) }
},
httpBody = HttpBody.JsonBody(
obj = requests.map { (id, request) ->
SingleBatchRequest.create(id, request)
}
)
)
}
data class CreateBatchRequest(
val requests: List = emptyList(),
val stopOnFirstFailure: Boolean = true,
val allowParallelMode: Boolean = false,
val groupId: String? = null,
val deduplicationKey: UUID = UUID.randomUUID(),
) : ApiRequest {
override fun toRequestInfo() = RequestInfo.createPostRequest(
pathSegments = listOf(
"batch"
),
params = buildMap {
put("stopOnFirstFailure", stopOnFirstFailure.toString())
put("allowParallelMode", allowParallelMode.toString())
put("deduplicationKey", deduplicationKey.toString())
groupId?.let { put("groupId", it) }
},
httpBody = HttpBody.JsonBody(
obj = requests.map(SingleBatchRequest.Companion::create)
)
)
}
private data class SingleBatchRequest(
val id: String? = null,
val path: String = "",
val method: String = "",
val body: Any? = null
) : ApiRequestDTO {
companion object {
internal fun create(apiRequest: ApiRequest): SingleBatchRequest {
return create(null, apiRequest)
}
internal fun create(id: String?, apiRequest: ApiRequest): SingleBatchRequest {
val requestInfo = apiRequest.toRequestInfo()
val path = buildEndpointPath(requestInfo.pathSegments)
val queryString = buildQueryString(requestInfo.params)
return SingleBatchRequest(
id = id,
method = requestInfo.method.name,
path = path + queryString,
body = when (requestInfo.httpBody) {
is HttpBody.EmptyBody -> {
null
}
is HttpBody.JsonBody -> {
requestInfo.httpBody.obj
}
is HttpBody.ByteArrayBody,
is HttpBody.InputStreamBody,
is HttpBody.LocalFileBody -> {
error("Request type ${requestInfo.httpBody.javaClass.simpleName} is not allowed in batch requests")
}
}
)
}
}
}