Skip to content

Commit 42a3e58

Browse files
committed
feat(api): add state query param for cards (#19)
1 parent e3f6cbb commit 42a3e58

3 files changed

Lines changed: 96 additions & 1 deletion

File tree

lithic-java-core/src/main/kotlin/com/lithic/api/models/CardListParams.kt

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.lithic.api.models
22

3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.lithic.api.core.JsonField
5+
import com.lithic.api.core.JsonValue
36
import com.lithic.api.core.NoAutoDetect
47
import com.lithic.api.core.toUnmodifiable
8+
import com.lithic.api.errors.LithicInvalidDataException
59
import com.lithic.api.models.*
610
import java.time.OffsetDateTime
711
import java.util.Objects
@@ -10,6 +14,7 @@ import java.util.Optional
1014
class CardListParams
1115
constructor(
1216
private val accountToken: String?,
17+
private val state: State?,
1318
private val begin: OffsetDateTime?,
1419
private val end: OffsetDateTime?,
1520
private val page: Long?,
@@ -20,6 +25,8 @@ constructor(
2025

2126
fun accountToken(): Optional<String> = Optional.ofNullable(accountToken)
2227

28+
fun state(): Optional<State> = Optional.ofNullable(state)
29+
2330
fun begin(): Optional<OffsetDateTime> = Optional.ofNullable(begin)
2431

2532
fun end(): Optional<OffsetDateTime> = Optional.ofNullable(end)
@@ -32,6 +39,7 @@ constructor(
3239
internal fun getQueryParams(): Map<String, List<String>> {
3340
val params = mutableMapOf<String, List<String>>()
3441
this.accountToken?.let { params.put("account_token", listOf(it.toString())) }
42+
this.state?.let { params.put("state", listOf(it.toString())) }
3543
this.begin?.let { params.put("begin", listOf(it.toString())) }
3644
this.end?.let { params.put("end", listOf(it.toString())) }
3745
this.page?.let { params.put("page", listOf(it.toString())) }
@@ -53,6 +61,7 @@ constructor(
5361

5462
return other is CardListParams &&
5563
this.accountToken == other.accountToken &&
64+
this.state == other.state &&
5665
this.begin == other.begin &&
5766
this.end == other.end &&
5867
this.page == other.page &&
@@ -64,6 +73,7 @@ constructor(
6473
override fun hashCode(): Int {
6574
return Objects.hash(
6675
accountToken,
76+
state,
6777
begin,
6878
end,
6979
page,
@@ -74,7 +84,7 @@ constructor(
7484
}
7585

7686
override fun toString() =
77-
"CardListParams{accountToken=$accountToken, begin=$begin, end=$end, page=$page, pageSize=$pageSize, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}"
87+
"CardListParams{accountToken=$accountToken, state=$state, begin=$begin, end=$end, page=$page, pageSize=$pageSize, additionalQueryParams=$additionalQueryParams, additionalHeaders=$additionalHeaders}"
7888

7989
fun toBuilder() = Builder().from(this)
8090

@@ -87,6 +97,7 @@ constructor(
8797
class Builder {
8898

8999
private var accountToken: String? = null
100+
private var state: State? = null
90101
private var begin: OffsetDateTime? = null
91102
private var end: OffsetDateTime? = null
92103
private var page: Long? = null
@@ -97,6 +108,7 @@ constructor(
97108
@JvmSynthetic
98109
internal fun from(cardListParams: CardListParams) = apply {
99110
this.accountToken = cardListParams.accountToken
111+
this.state = cardListParams.state
100112
this.begin = cardListParams.begin
101113
this.end = cardListParams.end
102114
this.page = cardListParams.page
@@ -108,6 +120,9 @@ constructor(
108120
/** Returns cards associated with the specified account. */
109121
fun accountToken(accountToken: String) = apply { this.accountToken = accountToken }
110122

123+
/** Returns cards with the specified state. */
124+
fun state(state: State) = apply { this.state = state }
125+
111126
/**
112127
* Date string in RFC 3339 format. Only entries created after the specified date will be
113128
* included. UTC time zone.
@@ -169,6 +184,7 @@ constructor(
169184
fun build(): CardListParams =
170185
CardListParams(
171186
accountToken,
187+
state,
172188
begin,
173189
end,
174190
page,
@@ -177,4 +193,79 @@ constructor(
177193
additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
178194
)
179195
}
196+
197+
class State
198+
@JsonCreator
199+
private constructor(
200+
private val value: JsonField<String>,
201+
) {
202+
203+
@com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField<String> = value
204+
205+
override fun equals(other: Any?): Boolean {
206+
if (this === other) {
207+
return true
208+
}
209+
210+
return other is State && this.value == other.value
211+
}
212+
213+
override fun hashCode() = value.hashCode()
214+
215+
override fun toString() = value.toString()
216+
217+
companion object {
218+
219+
@JvmField val OPEN = State(JsonField.of("OPEN"))
220+
221+
@JvmField val PAUSED = State(JsonField.of("PAUSED"))
222+
223+
@JvmField val CLOSED = State(JsonField.of("CLOSED"))
224+
225+
@JvmField val PENDING_FULFILLMENT = State(JsonField.of("PENDING_FULFILLMENT"))
226+
227+
@JvmField val PENDING_ACTIVATION = State(JsonField.of("PENDING_ACTIVATION"))
228+
229+
@JvmStatic fun of(value: String) = State(JsonField.of(value))
230+
}
231+
232+
enum class Known {
233+
OPEN,
234+
PAUSED,
235+
CLOSED,
236+
PENDING_FULFILLMENT,
237+
PENDING_ACTIVATION,
238+
}
239+
240+
enum class Value {
241+
OPEN,
242+
PAUSED,
243+
CLOSED,
244+
PENDING_FULFILLMENT,
245+
PENDING_ACTIVATION,
246+
_UNKNOWN,
247+
}
248+
249+
fun value(): Value =
250+
when (this) {
251+
OPEN -> Value.OPEN
252+
PAUSED -> Value.PAUSED
253+
CLOSED -> Value.CLOSED
254+
PENDING_FULFILLMENT -> Value.PENDING_FULFILLMENT
255+
PENDING_ACTIVATION -> Value.PENDING_ACTIVATION
256+
else -> Value._UNKNOWN
257+
}
258+
259+
fun known(): Known =
260+
when (this) {
261+
OPEN -> Known.OPEN
262+
PAUSED -> Known.PAUSED
263+
CLOSED -> Known.CLOSED
264+
PENDING_FULFILLMENT -> Known.PENDING_FULFILLMENT
265+
PENDING_ACTIVATION -> Known.PENDING_ACTIVATION
266+
else -> throw LithicInvalidDataException("Unknown State: $value")
267+
}
268+
269+
fun asString(): String = _value().asStringOrThrow()
270+
}
180271
}

lithic-java-core/src/test/kotlin/com/lithic/api/models/CardListParamsTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CardListParamsTest {
1111
fun createCardListParams() {
1212
CardListParams.builder()
1313
.accountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
14+
.state(CardListParams.State.OPEN)
1415
.begin(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
1516
.end(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
1617
.page(123L)
@@ -23,13 +24,15 @@ class CardListParamsTest {
2324
val params =
2425
CardListParams.builder()
2526
.accountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
27+
.state(CardListParams.State.OPEN)
2628
.begin(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
2729
.end(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
2830
.page(123L)
2931
.pageSize(123L)
3032
.build()
3133
val expected = mutableMapOf<String, List<String>>()
3234
expected.put("account_token", listOf("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"))
35+
expected.put("state", listOf(CardListParams.State.OPEN.toString()))
3336
expected.put("begin", listOf("2019-12-27T18:11:19.117Z"))
3437
expected.put("end", listOf("2019-12-27T18:11:19.117Z"))
3538
expected.put("page", listOf("123"))

lithic-java-core/src/test/kotlin/com/lithic/api/services/ServiceParamsTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class ServiceParamsTest {
149149
val params =
150150
CardListParams.builder()
151151
.accountToken("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
152+
.state(CardListParams.State.OPEN)
152153
.begin(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
153154
.end(OffsetDateTime.parse("2019-12-27T18:11:19.117Z"))
154155
.page(123L)

0 commit comments

Comments
 (0)