mirror of
https://github.com/Voronsky/unifi4j.git
synced 2025-12-12 16:16:34 -05:00
unused imports
This commit is contained in:
@@ -1,27 +1,27 @@
|
|||||||
package com.voronsky.unifi4j;
|
package com.voronsky.unifi4j;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.client.RestClient;
|
import org.springframework.web.client.RestClient;
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class Unifi {
|
public class Unifi {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Unifi.class);
|
private static final Logger log = LoggerFactory.getLogger(Unifi.class);
|
||||||
private final RestClient restClient;
|
private final RestClient restClient;
|
||||||
private String endpoint;
|
private final String endpoint;
|
||||||
private String apiKey;
|
|
||||||
|
|
||||||
public Unifi(String url, String apiKey){
|
public Unifi(String url, String apiKey){
|
||||||
this.endpoint = url;
|
this.endpoint = url;
|
||||||
this.apiKey = apiKey;
|
|
||||||
this.restClient = RestClient.builder().baseUrl(this.endpoint).defaultHeaders(
|
this.restClient = RestClient.builder().baseUrl(this.endpoint).defaultHeaders(
|
||||||
httpHeaders -> {
|
httpHeaders -> {
|
||||||
httpHeaders.set("Accept","application/json");
|
httpHeaders.set("Accept","application/json");
|
||||||
httpHeaders.set("X-API-KEY", System.getenv("UNIFI_KEY"));
|
httpHeaders.set("X-API-KEY", apiKey);
|
||||||
}
|
}
|
||||||
).build();
|
).build();
|
||||||
}
|
}
|
||||||
@@ -39,4 +39,20 @@ public class Unifi {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getHardware() throws Exception{
|
||||||
|
List<String> hardwares = new ArrayList<>();
|
||||||
|
ResponseEntity<String> p = this.restClient.get().uri("/hosts").retrieve().toEntity(String.class);
|
||||||
|
//Data p = this.restClient.get().uri("/hosts").retrieve().body(Data.class);
|
||||||
|
log.info("Response Obj: "+p);
|
||||||
|
|
||||||
|
// Map the JSON String from the response to a Json node object
|
||||||
|
JsonNode jsonObject = new ObjectMapper().readTree(p.getBody());
|
||||||
|
log.info("JSON Tree object: "+jsonObject);
|
||||||
|
log.info("Reported State: " + jsonObject.get("data").get(0).get("reportedState").get("hardware"));
|
||||||
|
ObjectMapper objMapper = new ObjectMapper();
|
||||||
|
Hardware h = objMapper.treeToValue(jsonObject.get("data").get(0).get("reportedState").asText(), Hardware.class);
|
||||||
|
hardwares.add(h.name());
|
||||||
|
return hardwares;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user