-
Notifications
You must be signed in to change notification settings - Fork 2
Usage
In order to use the API, you first have to obtain an API Key from here, which can be skipped if you want to use the demo API which will not provide any realtime data.
Second, you have to create an API instance.
Build API with Demo API-Key
Api api = new Tankerkoenig.ApiBuilder()
.withDemoApiKey()
.build();
Build API with Personal API-Key
Api api = new Tankerkoenig.ApiBuilder()
.withApiKey("INSERT_KEY_HERE")
.build();
Build API using a custom ClientExecutor
Internally, OkHttp Client is used for request execution. It will use the default configuration. If you wish to use another client or need some special configuration, all you have is to implement the ClientExecutor
interface yourself and implement the required methods or use the existing OkHttp3ClientExecutor
and pass your own OkHttpClient
instance into it. Then you have to pass your instance to the builder:
OkHttpClient client = new OkHttpClient.Builder()
//additional configuration
.build();
ClientExecutor clientExecutor = new OkHttp3ClientExecutor(client);
final Tankerkoenig.Api api = new Tankerkoenig.ApiBuilder()
.withApiKey("INSERT_KEY_HERE")
.withClientExecutor(clientExecutor)
.build();
List of Gas Stations
final StationListResult result = api.list(53.0, 13.0)
.setSorting(StationListRequest.SortingRequestType.PRICE)
.setGasRequestType(GasRequestType.E5)
.setSearchRadius(25)
.execute();
Detail Information of a Gas Station
final StationDetailResult result = api.detail("e1a15081-25a3-9107-e040-0b0a3dfe563c")
.execute();
Fetch prices for the given Station IDs
final PricesResult result = api.prices()
.addId("e1a15081-25a3-9107-e040-0b0a3dfe563c") //using a single ID
.addIds("51d4b660-a095-1aa0-e100-80009459e03a", "51d4b6a9-a095-1aa0-e100-80009459e03a") //using IDs as args
.addIds(Arrays.asList("278130b1-e062-4a0f-80cc-19e486b4c024", "934fc007-1f0a-418f-9169-84cd1c6104da")) //using a collection
.execute();
Invoke a data correction request
final CorrectionResult result = api.correction("e1a15081-25a3-9107-e040-0b0a3dfe563c", CorrectionRequest.Type.WRONG_PRICE_E5)
.setCorrectionValue("1.29")
.execute();
For further information, please consult the javadoc.