-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from andacata/feat/86_use_link_header_for_pagi…
…nation feat(common) #86: Add the ability to use the Link header for getting next pages from paginated responses
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiClientUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.izivia.ocpi.toolkit.common | ||
|
||
import com.izivia.ocpi.toolkit.modules.credentials.repositories.PartnerRepository | ||
import com.izivia.ocpi.toolkit.transport.TransportClientBuilder | ||
import com.izivia.ocpi.toolkit.transport.domain.HttpMethod | ||
import com.izivia.ocpi.toolkit.transport.domain.HttpRequest | ||
|
||
suspend inline fun <reified T> getNextPage( | ||
transportClientBuilder: TransportClientBuilder, | ||
serverVersionsEndpointUrl: String, | ||
partnerRepository: PartnerRepository, | ||
previousResponse: OcpiResponseBody<SearchResult<T>> | ||
): OcpiResponseBody<SearchResult<T>>? = | ||
previousResponse.data?.nextPageUrl?.let { nextPageUrl -> | ||
with(transportClientBuilder.build(nextPageUrl)) { | ||
send( | ||
HttpRequest( | ||
method = HttpMethod.GET | ||
) | ||
.withRequiredHeaders( | ||
requestId = generateRequestId(), | ||
correlationId = generateCorrelationId() | ||
) | ||
.authenticate(partnerRepository = partnerRepository, partnerUrl = serverVersionsEndpointUrl) | ||
) | ||
.parsePaginatedBody(previousResponse.data.offset) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters