refactored connection classes to be more generic and accept credentials of different apps.

This commit is contained in:
2026-04-03 02:58:34 +02:00
parent ab1d7e68f5
commit 0169cf04b6
7 changed files with 116 additions and 30 deletions
@@ -0,0 +1,42 @@
package com.vaessl.app.connection;
import java.util.Map;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import com.vaessl.app.dto.ConnectionRequest;
import com.vaessl.app.dto.ConnectionResponse;
import static com.vaessl.app.connection.Endpoints.*;
@Component
public class HomeBoxConnectionProvider implements ConnectionProvider {
private final RestClient.Builder restClientBuilder;
public HomeBoxConnectionProvider(RestClient.Builder restClientBuilder) {
this.restClientBuilder = restClientBuilder;
}
@Override
public String getServiceType() {
return "HOMEBOX";
}
@Override
public ConnectionResponse authenticate(ConnectionRequest connectionRequest) {
Map<String, Object> homeboxPayload = Map.of("username", connectionRequest.credentials().get("username"),
"password", connectionRequest.credentials().get("password"), "stayLoggedIn",
connectionRequest.stayLoggedIn());
return restClientBuilder.baseUrl(connectionRequest.appUrl())
.build()
.post()
.uri(HOMEBOX_LOGIN.getEndpoint())
.body(homeboxPayload)
.retrieve()
.body(ConnectionResponse.class);
}
}