Skip to content

Commit 28cfec9

Browse files
committed
feat(api): updates (#93)
1 parent 71b612d commit 28cfec9

25 files changed

Lines changed: 406 additions & 559 deletions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private constructor(
9797
headers.put("X-Stainless-OS-Version", getOsVersion())
9898
headers.put("X-Stainless-Package-Version", getPackageVersion())
9999
headers.put("X-Stainless-Runtime-Version", getJavaVersion())
100+
headers.put("X-Lithic-Pagination", "cursor")
100101
headers.put("Authorization", apiKey)
101102
this.headers.forEach(headers::replaceValues)
102103

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

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ private constructor(
2929

3030
fun data(): List<Account> = response().data()
3131

32-
fun page(): Long = response().page()
33-
34-
fun totalEntries(): Long = response().totalEntries()
35-
36-
fun totalPages(): Long = response().totalPages()
32+
fun hasMore(): Boolean = response().hasMore()
3733

3834
override fun equals(other: Any?): Boolean {
3935
if (this === other) {
@@ -58,21 +54,29 @@ private constructor(
5854
"AccountListPage{accountsService=$accountsService, params=$params, response=$response}"
5955

6056
fun hasNextPage(): Boolean {
61-
if (data().isEmpty()) {
62-
return false
63-
}
64-
65-
return page() < totalPages()
57+
return data().isEmpty()
6658
}
6759

6860
fun getNextPageParams(): Optional<AccountListParams> {
6961
if (!hasNextPage()) {
7062
return Optional.empty()
7163
}
7264

73-
return Optional.of(
74-
AccountListParams.builder().from(params).page(params.page().orElse(0) + 1).build()
75-
)
65+
return if (params.endingBefore().isPresent) {
66+
Optional.of(
67+
AccountListParams.builder()
68+
.from(params)
69+
.endingBefore(data().first().token())
70+
.build()
71+
)
72+
} else {
73+
Optional.of(
74+
AccountListParams.builder()
75+
.from(params)
76+
.startingAfter(data().last().token())
77+
.build()
78+
)
79+
}
7680
}
7781

7882
fun getNextPage(): Optional<AccountListPage> {
@@ -97,32 +101,21 @@ private constructor(
97101
class Response
98102
constructor(
99103
private val data: JsonField<List<Account>>,
100-
private val page: JsonField<Long>,
101-
private val totalEntries: JsonField<Long>,
102-
private val totalPages: JsonField<Long>,
104+
private val hasMore: JsonField<Boolean>,
103105
private val additionalProperties: Map<String, JsonValue>,
104106
) {
105107

106108
private var validated: Boolean = false
107109

108110
fun data(): List<Account> = data.getNullable("data") ?: listOf()
109111

110-
fun page(): Long = page.getRequired("page")
111-
112-
fun totalEntries(): Long = totalEntries.getRequired("total_entries")
113-
114-
fun totalPages(): Long = totalPages.getRequired("total_pages")
112+
fun hasMore(): Boolean = hasMore.getRequired("has_more")
115113

116114
@JsonProperty("data")
117115
fun _data(): Optional<JsonField<List<Account>>> = Optional.ofNullable(data)
118116

119-
@JsonProperty("page") fun _page(): Optional<JsonField<Long>> = Optional.ofNullable(page)
120-
121-
@JsonProperty("total_entries")
122-
fun _totalEntries(): Optional<JsonField<Long>> = Optional.ofNullable(totalEntries)
123-
124-
@JsonProperty("total_pages")
125-
fun _totalPages(): Optional<JsonField<Long>> = Optional.ofNullable(totalPages)
117+
@JsonProperty("has_more")
118+
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
126119

127120
@JsonAnyGetter
128121
@ExcludeMissing
@@ -131,9 +124,7 @@ private constructor(
131124
fun validate(): Response = apply {
132125
if (!validated) {
133126
data().map { it.validate() }
134-
page()
135-
totalEntries()
136-
totalPages()
127+
hasMore()
137128
validated = true
138129
}
139130
}
@@ -147,24 +138,20 @@ private constructor(
147138

148139
return other is Response &&
149140
this.data == other.data &&
150-
this.page == other.page &&
151-
this.totalEntries == other.totalEntries &&
152-
this.totalPages == other.totalPages &&
141+
this.hasMore == other.hasMore &&
153142
this.additionalProperties == other.additionalProperties
154143
}
155144

156145
override fun hashCode(): Int {
157146
return Objects.hash(
158147
data,
159-
page,
160-
totalEntries,
161-
totalPages,
148+
hasMore,
162149
additionalProperties,
163150
)
164151
}
165152

166153
override fun toString() =
167-
"AccountListPage.Response{data=$data, page=$page, totalEntries=$totalEntries, totalPages=$totalPages, additionalProperties=$additionalProperties}"
154+
"AccountListPage.Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
168155

169156
companion object {
170157

@@ -174,17 +161,13 @@ private constructor(
174161
class Builder {
175162

176163
private var data: JsonField<List<Account>> = JsonMissing.of()
177-
private var page: JsonField<Long> = JsonMissing.of()
178-
private var totalEntries: JsonField<Long> = JsonMissing.of()
179-
private var totalPages: JsonField<Long> = JsonMissing.of()
164+
private var hasMore: JsonField<Boolean> = JsonMissing.of()
180165
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
181166

182167
@JvmSynthetic
183168
internal fun from(page: Response) = apply {
184169
this.data = page.data
185-
this.page = page.page
186-
this.totalEntries = page.totalEntries
187-
this.totalPages = page.totalPages
170+
this.hasMore = page.hasMore
188171
this.additionalProperties.putAll(page.additionalProperties)
189172
}
190173

@@ -193,21 +176,10 @@ private constructor(
193176
@JsonProperty("data")
194177
fun data(data: JsonField<List<Account>>) = apply { this.data = data }
195178

196-
fun page(page: Long) = page(JsonField.of(page))
197-
198-
@JsonProperty("page") fun page(page: JsonField<Long>) = apply { this.page = page }
199-
200-
fun totalEntries(totalEntries: Long) = totalEntries(JsonField.of(totalEntries))
201-
202-
@JsonProperty("total_entries")
203-
fun totalEntries(totalEntries: JsonField<Long>) = apply {
204-
this.totalEntries = totalEntries
205-
}
206-
207-
fun totalPages(totalPages: Long) = totalPages(JsonField.of(totalPages))
179+
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
208180

209-
@JsonProperty("total_pages")
210-
fun totalPages(totalPages: JsonField<Long>) = apply { this.totalPages = totalPages }
181+
@JsonProperty("has_more")
182+
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
211183

212184
@JsonAnySetter
213185
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
@@ -217,9 +189,7 @@ private constructor(
217189
fun build() =
218190
Response(
219191
data,
220-
page,
221-
totalEntries,
222-
totalPages,
192+
hasMore,
223193
additionalProperties.toUnmodifiable(),
224194
)
225195
}

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

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ private constructor(
3030

3131
fun data(): List<Account> = response().data()
3232

33-
fun page(): Long = response().page()
34-
35-
fun totalEntries(): Long = response().totalEntries()
36-
37-
fun totalPages(): Long = response().totalPages()
33+
fun hasMore(): Boolean = response().hasMore()
3834

3935
override fun equals(other: Any?): Boolean {
4036
if (this === other) {
@@ -59,21 +55,29 @@ private constructor(
5955
"AccountListPageAsync{accountsService=$accountsService, params=$params, response=$response}"
6056

6157
fun hasNextPage(): Boolean {
62-
if (data().isEmpty()) {
63-
return false
64-
}
65-
66-
return page() < totalPages()
58+
return data().isEmpty()
6759
}
6860

6961
fun getNextPageParams(): Optional<AccountListParams> {
7062
if (!hasNextPage()) {
7163
return Optional.empty()
7264
}
7365

74-
return Optional.of(
75-
AccountListParams.builder().from(params).page(params.page().orElse(0) + 1).build()
76-
)
66+
return if (params.endingBefore().isPresent) {
67+
Optional.of(
68+
AccountListParams.builder()
69+
.from(params)
70+
.endingBefore(data().first().token())
71+
.build()
72+
)
73+
} else {
74+
Optional.of(
75+
AccountListParams.builder()
76+
.from(params)
77+
.startingAfter(data().last().token())
78+
.build()
79+
)
80+
}
7781
}
7882

7983
fun getNextPage(): CompletableFuture<Optional<AccountListPageAsync>> {
@@ -104,32 +108,21 @@ private constructor(
104108
class Response
105109
constructor(
106110
private val data: JsonField<List<Account>>,
107-
private val page: JsonField<Long>,
108-
private val totalEntries: JsonField<Long>,
109-
private val totalPages: JsonField<Long>,
111+
private val hasMore: JsonField<Boolean>,
110112
private val additionalProperties: Map<String, JsonValue>,
111113
) {
112114

113115
private var validated: Boolean = false
114116

115117
fun data(): List<Account> = data.getNullable("data") ?: listOf()
116118

117-
fun page(): Long = page.getRequired("page")
118-
119-
fun totalEntries(): Long = totalEntries.getRequired("total_entries")
120-
121-
fun totalPages(): Long = totalPages.getRequired("total_pages")
119+
fun hasMore(): Boolean = hasMore.getRequired("has_more")
122120

123121
@JsonProperty("data")
124122
fun _data(): Optional<JsonField<List<Account>>> = Optional.ofNullable(data)
125123

126-
@JsonProperty("page") fun _page(): Optional<JsonField<Long>> = Optional.ofNullable(page)
127-
128-
@JsonProperty("total_entries")
129-
fun _totalEntries(): Optional<JsonField<Long>> = Optional.ofNullable(totalEntries)
130-
131-
@JsonProperty("total_pages")
132-
fun _totalPages(): Optional<JsonField<Long>> = Optional.ofNullable(totalPages)
124+
@JsonProperty("has_more")
125+
fun _hasMore(): Optional<JsonField<Boolean>> = Optional.ofNullable(hasMore)
133126

134127
@JsonAnyGetter
135128
@ExcludeMissing
@@ -138,9 +131,7 @@ private constructor(
138131
fun validate(): Response = apply {
139132
if (!validated) {
140133
data().map { it.validate() }
141-
page()
142-
totalEntries()
143-
totalPages()
134+
hasMore()
144135
validated = true
145136
}
146137
}
@@ -154,24 +145,20 @@ private constructor(
154145

155146
return other is Response &&
156147
this.data == other.data &&
157-
this.page == other.page &&
158-
this.totalEntries == other.totalEntries &&
159-
this.totalPages == other.totalPages &&
148+
this.hasMore == other.hasMore &&
160149
this.additionalProperties == other.additionalProperties
161150
}
162151

163152
override fun hashCode(): Int {
164153
return Objects.hash(
165154
data,
166-
page,
167-
totalEntries,
168-
totalPages,
155+
hasMore,
169156
additionalProperties,
170157
)
171158
}
172159

173160
override fun toString() =
174-
"AccountListPageAsync.Response{data=$data, page=$page, totalEntries=$totalEntries, totalPages=$totalPages, additionalProperties=$additionalProperties}"
161+
"AccountListPageAsync.Response{data=$data, hasMore=$hasMore, additionalProperties=$additionalProperties}"
175162

176163
companion object {
177164

@@ -181,17 +168,13 @@ private constructor(
181168
class Builder {
182169

183170
private var data: JsonField<List<Account>> = JsonMissing.of()
184-
private var page: JsonField<Long> = JsonMissing.of()
185-
private var totalEntries: JsonField<Long> = JsonMissing.of()
186-
private var totalPages: JsonField<Long> = JsonMissing.of()
171+
private var hasMore: JsonField<Boolean> = JsonMissing.of()
187172
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()
188173

189174
@JvmSynthetic
190175
internal fun from(page: Response) = apply {
191176
this.data = page.data
192-
this.page = page.page
193-
this.totalEntries = page.totalEntries
194-
this.totalPages = page.totalPages
177+
this.hasMore = page.hasMore
195178
this.additionalProperties.putAll(page.additionalProperties)
196179
}
197180

@@ -200,21 +183,10 @@ private constructor(
200183
@JsonProperty("data")
201184
fun data(data: JsonField<List<Account>>) = apply { this.data = data }
202185

203-
fun page(page: Long) = page(JsonField.of(page))
204-
205-
@JsonProperty("page") fun page(page: JsonField<Long>) = apply { this.page = page }
206-
207-
fun totalEntries(totalEntries: Long) = totalEntries(JsonField.of(totalEntries))
208-
209-
@JsonProperty("total_entries")
210-
fun totalEntries(totalEntries: JsonField<Long>) = apply {
211-
this.totalEntries = totalEntries
212-
}
213-
214-
fun totalPages(totalPages: Long) = totalPages(JsonField.of(totalPages))
186+
fun hasMore(hasMore: Boolean) = hasMore(JsonField.of(hasMore))
215187

216-
@JsonProperty("total_pages")
217-
fun totalPages(totalPages: JsonField<Long>) = apply { this.totalPages = totalPages }
188+
@JsonProperty("has_more")
189+
fun hasMore(hasMore: JsonField<Boolean>) = apply { this.hasMore = hasMore }
218190

219191
@JsonAnySetter
220192
fun putAdditionalProperty(key: String, value: JsonValue) = apply {
@@ -224,9 +196,7 @@ private constructor(
224196
fun build() =
225197
Response(
226198
data,
227-
page,
228-
totalEntries,
229-
totalPages,
199+
hasMore,
230200
additionalProperties.toUnmodifiable(),
231201
)
232202
}

0 commit comments

Comments
 (0)