41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
package com.goi.integration.samsara.client;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
|
import java.time.Instant;
|
|
|
|
@Component
|
|
public class SamsaraClient {
|
|
|
|
private final WebClient webClient;
|
|
|
|
public SamsaraClient(
|
|
@Value("${ext.samsara.base-url:https://api.samsara.com}") String baseUrl,
|
|
@Value("${ext.samsara.api-token}") String apiToken
|
|
) {
|
|
this.webClient = WebClient.builder()
|
|
.baseUrl(baseUrl)
|
|
.defaultHeader(HttpHeaders.AUTHORIZATION, "Bearer " + apiToken)
|
|
.build();
|
|
}
|
|
|
|
/**
|
|
* DVIR history raw JSON (string)로 받아도 되고, DTO로 매핑해도 됨.
|
|
* 일단 초기엔 String으로 받아서 JsonNode로 파싱하는게 가장 유연함.
|
|
*/
|
|
public String getDvirHistory(int limit, Instant startTime, Instant endTime) {
|
|
return webClient.get()
|
|
.uri(uriBuilder -> uriBuilder
|
|
.path("/fleet/dvirs/history")
|
|
.queryParam("limit", limit)
|
|
.queryParam("startTime", startTime.toString())
|
|
.queryParam("endTime", endTime.toString())
|
|
.build())
|
|
.retrieve()
|
|
.bodyToMono(String.class)
|
|
.block();
|
|
}
|
|
} |