All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecwid.apiclient.v3.impl.BatchApiClientImpl.kt Maven / Gradle / Ivy

There is a newer version: 0.347.0
Show newest version
package com.ecwid.apiclient.v3.impl

import com.ecwid.apiclient.v3.ApiClientHelper
import com.ecwid.apiclient.v3.BatchApiClient
import com.ecwid.apiclient.v3.dto.batch.request.CancelBatchGroupRequest
import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequest
import com.ecwid.apiclient.v3.dto.batch.request.CreateBatchRequestWithIds
import com.ecwid.apiclient.v3.dto.batch.request.GetEscapedBatchRequest
import com.ecwid.apiclient.v3.dto.batch.result.CancelBatchGroupResult
import com.ecwid.apiclient.v3.dto.batch.result.CreateBatchResult
import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult
import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult
import com.ecwid.apiclient.v3.dto.common.EcwidApiError
import com.ecwid.apiclient.v3.exception.JsonDeserializationException

internal class BatchApiClientImpl(
	private val apiClientHelper: ApiClientHelper
) : BatchApiClient {
	override fun createBatch(request: CreateBatchRequestWithIds) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun createBatch(request: CreateBatchRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun cancelBatchGroup(request: CancelBatchGroupRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun getEscapedBatch(request: GetEscapedBatchRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun getTypedBatch(request: GetEscapedBatchRequest) =
		GetTypedBatchResult(getEscapedBatch(request), apiClientHelper.jsonTransformer)
}

sealed class TypedBatchResponse {
	data class Ok(val value: T) : TypedBatchResponse()

	data class ApiError(
		val httpStatusCode: Int,
		val httpStatusText: String,
		val ecwidApiError: EcwidApiError?,
	) : TypedBatchResponse()

	data class ParseError(val jsonDeserializationException: JsonDeserializationException) : TypedBatchResponse()
	class NotExecuted : TypedBatchResponse()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy