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

com.ecwid.apiclient.v3.impl.CouponsApiClientImpl.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.CouponsApiClient
import com.ecwid.apiclient.v3.dto.coupon.request.*
import com.ecwid.apiclient.v3.dto.coupon.result.*
import com.ecwid.apiclient.v3.responsefields.AS_SEQUENCE_SEARCH_RESULT_REQUIRED_FIELDS

internal data class CouponsApiClientImpl(
	private val apiClientHelper: ApiClientHelper
) : CouponsApiClient {
	override fun searchCoupons(request: CouponSearchRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun searchCouponsAsSequence(request: CouponSearchRequest) = sequence {
		var offsetRequest = request.copy(
			responseFields = request.responseFields + AS_SEQUENCE_SEARCH_RESULT_REQUIRED_FIELDS
		)
		do {
			val searchResult = searchCoupons(offsetRequest)
			yieldAll(searchResult.items)
			offsetRequest = offsetRequest.copy(offset = offsetRequest.offset + searchResult.count)
		} while (searchResult.count >= searchResult.limit)
	}

	override fun getCouponDetails(request: CouponDetailsRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun createCoupon(request: CouponCreateRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun updateCoupon(request: CouponUpdateRequest) =
		apiClientHelper.makeObjectResultRequest(request)

	override fun deleteCoupon(request: CouponDeleteRequest) =
		apiClientHelper.makeObjectResultRequest(request)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy