diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiClientUtils.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiClientUtils.kt new file mode 100644 index 00000000..3752e3cb --- /dev/null +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/common/OcpiClientUtils.kt @@ -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 getNextPage( + transportClientBuilder: TransportClientBuilder, + serverVersionsEndpointUrl: String, + partnerRepository: PartnerRepository, + previousResponse: OcpiResponseBody> +): OcpiResponseBody>? = + 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) + } + } diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt index a017710e..26813868 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/locations/LocationsEmspClient.kt @@ -56,6 +56,15 @@ class LocationsEmspClient( .parsePaginatedBody(offset) } + suspend fun getLocationsNextPage( + previousResponse: OcpiResponseBody> + ): OcpiResponseBody>? = getNextPage( + transportClientBuilder = transportClientBuilder, + serverVersionsEndpointUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository, + previousResponse = previousResponse + ) + override suspend fun getLocation(locationId: CiString): OcpiResponseBody = with(buildTransport()) { send( HttpRequest( diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt index 8a194ee1..a5d1d038 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/sessions/SessionsEmspClient.kt @@ -55,6 +55,15 @@ class SessionsEmspClient( .parsePaginatedBody(offset) } + suspend fun getSessionsNextPage( + previousResponse: OcpiResponseBody> + ): OcpiResponseBody>? = getNextPage( + transportClientBuilder = transportClientBuilder, + serverVersionsEndpointUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository, + previousResponse = previousResponse + ) + override suspend fun putChargingPreferences( sessionId: CiString, chargingPreferences: ChargingPreferences diff --git a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt index 5a28734b..b5f2fae4 100644 --- a/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt +++ b/ocpi-toolkit-2.2.1/src/main/kotlin/com/izivia/ocpi/toolkit/modules/tokens/TokensCpoClient.kt @@ -57,6 +57,15 @@ class TokensCpoClient( .parsePaginatedBody(offset) } + suspend fun getTokensNextPage( + previousResponse: OcpiResponseBody> + ): OcpiResponseBody>? = getNextPage( + transportClientBuilder = transportClientBuilder, + serverVersionsEndpointUrl = serverVersionsEndpointUrl, + partnerRepository = partnerRepository, + previousResponse = previousResponse + ) + override suspend fun postToken( tokenUid: CiString, type: TokenType?,