Skip to content

Commit

Permalink
Merge pull request #314 from Ecwid/new-subscriptions-fields
Browse files Browse the repository at this point in the history
New subscriptions fields
  • Loading branch information
juvirez authored Aug 8, 2023
2 parents b584c59 + 55590dc commit 162675f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/com/ecwid/apiclient/v3/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.ecwid.apiclient.v3.dto.saleschannels.response.*
import com.ecwid.apiclient.v3.dto.storage.request.*
import com.ecwid.apiclient.v3.dto.storage.result.*
import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest
import com.ecwid.apiclient.v3.dto.subscriptions.result.FetchedSubscription
import com.ecwid.apiclient.v3.dto.subscriptions.result.SubscriptionsSearchResult
import com.ecwid.apiclient.v3.dto.variation.request.*
import com.ecwid.apiclient.v3.dto.variation.result.*
Expand Down Expand Up @@ -348,6 +349,7 @@ interface ReportsApiClient {
// https://api-docs.ecwid.com/reference/get-subscription
interface SubscriptionsApiClient {
fun searchSubscriptions(request: SubscriptionsSearchRequest): SubscriptionsSearchResult
fun searchSubscriptionsAsSequence(request: SubscriptionsSearchRequest): Sequence<FetchedSubscription>
}

interface InstantSiteRedirectsApiClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ enum class SubscriptionStatus {
CANCELLED,
LAST_CHARGE_FAILED,
REQUIRES_PAYMENT_CONFIRMATION,
PAUSED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class SubscriptionsSearchRequest(
val updatedFrom: Date? = null,
val updatedTo: Date? = null,
val customerId: Int? = null,
val status: SubscriptionStatus? = null,
val status: List<SubscriptionStatus>? = null,
val nextChargeFrom: Date? = null,
val nextChargeTo: Date? = null,
val recurringInterval: SubscriptionInterval? = null,
Expand All @@ -29,9 +29,10 @@ data class SubscriptionsSearchRequest(
val orderTotal: Double? = null,
val orderCreatedFrom: Date? = null,
val orderCreatedTo: Date? = null,
val offset: Int? = null,
val limit: Int? = null,
val offset: Int = 0,
val limit: Int = 100,
val sortBy: SortOrder = SortOrder.DATE_CREATED_DESC,
val lang: String? = null,
val responseFields: ResponseFields = ResponseFields.All,
) : ApiRequest {

Expand All @@ -53,7 +54,7 @@ data class SubscriptionsSearchRequest(
updatedFrom?.let { put("updatedFrom", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
updatedTo?.let { put("updatedTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
customerId?.let { put("customerId", it.toString()) }
status?.let { put("status", it.name) }
status?.let { put("status", it.joinToString(",")) }
nextChargeFrom?.let { put("nextChargeFrom", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
nextChargeTo?.let { put("nextChargeTo", TimeUnit.MILLISECONDS.toSeconds(it.time).toString()) }
recurringInterval?.let { put("recurringInterval", it.name) }
Expand All @@ -67,6 +68,7 @@ data class SubscriptionsSearchRequest(
offset?.let { put("offset", it.toString()) }
limit?.let { put("limit", it.toString()) }
put("sortBy", sortBy.name)
lang?.let { put("lang", it) }
}.toMap()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ecwid.apiclient.v3.dto.subscriptions.result

import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO
import com.ecwid.apiclient.v3.dto.common.ApiFetchedDTO.ModifyKind
import com.ecwid.apiclient.v3.dto.common.LocalizedValueMap
import com.ecwid.apiclient.v3.dto.subscriptions.enums.PriceModifierType
import com.ecwid.apiclient.v3.dto.subscriptions.enums.ProductOptionType
import com.ecwid.apiclient.v3.dto.subscriptions.enums.SubscriptionInterval
Expand All @@ -17,6 +18,7 @@ data class FetchedSubscription(
val created: Date = Date(),
val cancelled: Date? = null,
val nextCharge: Date = Date(),
val nextChargeFormatted: String = "",
val createTimestamp: Long? = null,
val updateTimestamp: Long? = null,
val chargeSettings: ChargeSettings = ChargeSettings(),
Expand Down Expand Up @@ -110,6 +112,7 @@ data class FetchedSubscription(

val sku: String? = null,
val name: String? = null,
val nameTranslated: LocalizedValueMap? = null,
val shortDescription: String? = null,
val quantity: Int? = null,
val quantityInStock: Int? = null,
Expand All @@ -120,7 +123,10 @@ data class FetchedSubscription(

val digital: Boolean? = null,
val productAvailable: Boolean? = null,

val imageUrl: String? = null,
val smallThumbnailUrl: String? = null,
val hdThumbnailUrl: String? = null,

val recurringChargeSettings: RecurringChargeSettings? = null,
val selectedOptions: List<SelectedOptions>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ecwid.apiclient.v3.ApiClientHelper
import com.ecwid.apiclient.v3.SubscriptionsApiClient
import com.ecwid.apiclient.v3.dto.subscriptions.request.SubscriptionsSearchRequest
import com.ecwid.apiclient.v3.dto.subscriptions.result.SubscriptionsSearchResult
import com.ecwid.apiclient.v3.responsefields.AS_SEQUENCE_SEARCH_RESULT_REQUIRED_FIELDS

class SubscriptionsApiClientImpl(
private val apiClientHelper: ApiClientHelper
Expand All @@ -12,4 +13,15 @@ class SubscriptionsApiClientImpl(
override fun searchSubscriptions(request: SubscriptionsSearchRequest) =
apiClientHelper.makeObjectResultRequest<SubscriptionsSearchResult>(request)

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ val fetchedSubscriptionsNullablePropertyRules: List<NullablePropertyRule<*, *>>
AllowNullable(FetchedSubscription.OrderItem::fixedShippingRate),
AllowNullable(FetchedSubscription.OrderItem::sku),
AllowNullable(FetchedSubscription.OrderItem::name),
AllowNullable(FetchedSubscription.OrderItem::nameTranslated),
AllowNullable(FetchedSubscription.OrderItem::shortDescription),
AllowNullable(FetchedSubscription.OrderItem::quantity),
AllowNullable(FetchedSubscription.OrderItem::quantityInStock),
Expand All @@ -65,6 +66,8 @@ val fetchedSubscriptionsNullablePropertyRules: List<NullablePropertyRule<*, *>>
AllowNullable(FetchedSubscription.OrderItem::digital),
AllowNullable(FetchedSubscription.OrderItem::productAvailable),
AllowNullable(FetchedSubscription.OrderItem::imageUrl),
AllowNullable(FetchedSubscription.OrderItem::smallThumbnailUrl),
AllowNullable(FetchedSubscription.OrderItem::hdThumbnailUrl),
AllowNullable(FetchedSubscription.OrderItem::recurringChargeSettings),
AllowNullable(FetchedSubscription.OrderItem::selectedOptions),
AllowNullable(FetchedSubscription.OrderItem::taxes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ val subscriptionsSearchRequestNullablePropertyRules: List<NullablePropertyRule<*
AllowNullable(SubscriptionsSearchRequest::orderTotal),
AllowNullable(SubscriptionsSearchRequest::orderCreatedFrom),
AllowNullable(SubscriptionsSearchRequest::orderCreatedTo),
AllowNullable(SubscriptionsSearchRequest::offset),
AllowNullable(SubscriptionsSearchRequest::limit),
AllowNullable(SubscriptionsSearchRequest::lang),
)

0 comments on commit 162675f

Please sign in to comment.