requestFuelPrices
Requests current fuel prices for a specific fuel station.
The main parameter required is the FuelPriceId of the fuel station, which can be obtained from a search result or through a POI details request.
Note: This operation is synchronous and should not be executed on the main thread. Execution on the main thread will block the application and might throw an exception if it involves a network call
Usage Example:
// Initialize the FuelPriceProvider
val fuelPriceProvider = FuelPriceProviderImplementation(...)
// After obtaining the `fuelPriceId` from a search result or a POI details request,
// create options for the fuel prices request
val fuePriceOptions = searchResult.searchResultId.fuelPriceId?.let { fuelPriceId ->
FuelPriceOptions(fuelPriceId)
}
// Request fuel prices
options?.let { options ->
val result = fuelPriceProvider.requestFuelPrices(options)
if (result.isSuccess()) {
val response = result.value()
// Process the response.
Log.d(response.prices.first().prices.first().amount)
Log.d(response.prices.first().prices.first().currency)
} else {
val failure = result.failure()
// Handle failure.
Log.d(failure.message)
}
}
Important: This is a Public Preview API that may experience changes or removal in the future.
Return
The Result containing a FuelPriceResponse with the fuel price information if the call succeeds, or a SearchFailure if it fails.
Parameters
Specifies the input of the request.
Requests current fuel prices for a specific fuel station.
The main parameter required is the FuelPriceId of the fuel station, which can be obtained from a search result or through a POI details request.
This is an asynchronous call, and the result will be returned through the provided callback.
Note: The callback is executed on the main thread. Usage example:
// Initialize the FuelPriceProvider
val fuelPriceProvider = FuelPriceProviderImplementation(...)
// After obtaining the fuelPriceId from a search result or a POI details request,
// create options for the fuel prices request
val fuelPriceOptions = searchResult.searchResultId.fuelPriceId?.let { fuelPriceId ->
FuelPriceOptions(fuelPriceId)
}
// Create the callback
val callback = object : FuelPriceCallback {
override fun onSuccess(result: FuelPriceResponse) {
// Process the response.
Log.d(result.prices.first().prices.first().amount)
Log.d(result.prices.first().prices.first().currency)
}
override fun onFailure(failure: SearchFailure) {
// Handle failure.
Log.d(failure.message)
}
}
// Request fuel prices using the pre-created callback
fuelPriceOptions?.let { options ->
val cancellable = fuelPriceProvider.requestFuelPrices(options, callback)
// You can cancel the operation if needed:
cancellable.cancel()
}
Return
A Cancellable object that stops the ongoing operation if needed if it hasn't been completed yet.
Parameters
Specifies the input of the request.
The FuelPriceCallback invoked when the request has finished, either successfully or with an error. The callback is executed on the main thread.