Skip to content

Commit 194d397

Browse files
committed
feat: configure your own api server
1 parent 51b1d97 commit 194d397

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add the Maven Dependency to your `pom.xml`
1616
<dependency>
1717
<groupId>be.nicholasmeyers</groupId>
1818
<artifactId>skoda-api-client</artifactId>
19-
<version>1.2.1</version>
19+
<version>1.3.0</version>
2020
</dependency>
2121
```
2222

@@ -99,4 +99,13 @@ Make sure to replace `YOUR_CARS_VIN`, `YOUR_EMAIL`, and `YOUR_PASSWORD` with you
9999
String vin = "YOUR_CARS_VIN";
100100
CarService carService = new CarService("YOUR_EMAIL", "YOUR_PASSWORD");
101101
CarStatus status = carService.getStatus(vin);
102+
```
103+
104+
105+
## Use Your Own Server
106+
Use the `CarService` to retrieve information of your Škoda vehicle.
107+
Make sure to replace `YOUR_EMAIL`, `YOUR_PASSWORD`, and `YOUR_SERVER` with your actual server and account credentials.
108+
109+
```
110+
CarService carService = new CarService("YOUR_EMAIL", "YOUR_PASSWORD", "YOUR_SERVER");
102111
```

src/main/java/be/nicholasmeyers/skoda/api/client/CarService.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ public CarService(String email, String password) {
5656
this.ventilatorApi = new VentilatorApi(clientConfiguration.getApiClient());
5757
}
5858

59+
/**
60+
* Constructs a new CarService with the specified email and password for authentication and another server if you don't want to use the default.
61+
*
62+
* @param email The email used for authentication.
63+
* @param password The password used for authentication.
64+
* @param server The server used as api.
65+
*/
66+
public CarService(String email, String password, String server) {
67+
ClientConfiguration clientConfiguration = new ClientConfiguration(email, password, server);
68+
this.coolingApi = new CoolingApi(clientConfiguration.getApiClient());
69+
this.flashApi = new FlashApi(clientConfiguration.getApiClient());
70+
this.honkApi = new HonkApi(clientConfiguration.getApiClient());
71+
this.locationApi = new LocationApi(clientConfiguration.getApiClient());
72+
this.requestApi = new RequestApi(clientConfiguration.getApiClient());
73+
this.statusApi = new StatusApi(clientConfiguration.getApiClient());
74+
this.ventilatorApi = new VentilatorApi(clientConfiguration.getApiClient());
75+
}
76+
5977
/**
6078
* Retrieves the cooling status for the car identified by the provided VIN (Vehicle Identification Number).
6179
*

src/main/java/be/nicholasmeyers/skoda/api/client/ClientConfiguration.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package be.nicholasmeyers.skoda.api.client;
22

33
import be.nicholasmeyers.skoda.ApiClient;
4+
import be.nicholasmeyers.skoda.ServerConfiguration;
45
import okhttp3.Interceptor;
56
import okhttp3.OkHttpClient;
67
import okhttp3.Request;
78

9+
import java.util.HashMap;
10+
import java.util.List;
11+
812
public class ClientConfiguration {
913

1014
private final ApiClient apiClient;
@@ -27,6 +31,31 @@ public class ClientConfiguration {
2731
this.apiClient = new ApiClient(httpClient);
2832
}
2933

34+
ClientConfiguration(String email, String password, String server) {
35+
TokenService tokenService = new TokenService(email, password);
36+
37+
Interceptor authorizationInterceptor = chain -> {
38+
Request originalRequest = chain.request();
39+
Request requestWithAuthorization = originalRequest.newBuilder()
40+
.header("Authorization", "Bearer " + tokenService.getToken())
41+
.build();
42+
return chain.proceed(requestWithAuthorization);
43+
};
44+
45+
OkHttpClient httpClient = new OkHttpClient.Builder()
46+
.addInterceptor(authorizationInterceptor)
47+
.build();
48+
49+
ServerConfiguration serverConfiguration = new ServerConfiguration(
50+
server,
51+
"No description provided",
52+
new HashMap<>()
53+
);
54+
this.apiClient = new ApiClient(httpClient);
55+
this.apiClient.setBasePath(server);
56+
this.apiClient.setServers(List.of(serverConfiguration));
57+
}
58+
3059
ApiClient getApiClient() {
3160
return this.apiClient;
3261
}

0 commit comments

Comments
 (0)