Weather forecasts using the DarkSky public API
This project implements a REST client interface for the Dark Sky API. While keeping in mind that this client could be used in a Spring context as a bean, it may also be used independently.
To use this library, you must create an account on the Dark Sky API Developer portal, and generate a key for the API.
Both the Forecast and TimeMachine requests are supported.
The Forecast and TimeMachine calls rely on the DarkSkyClient
, which may be created accordingly :
DarkSkyClient darkSkyClient = new DarkSkyClient() ;
darkSkyClient.setApiKey( YOUR_API_KEY );
darkSkyClient.setBaseApiUrl( "https://api.darksky.net" );
darkSkyClient.setForecastPath( "/forecast/${apiKey}/${latitude},${longitude}" );
darkSkyClient.setTimeMachinePath( "/forecast/${apiKey}/${latitude},${longitude},${unixTime}" );
Firstly, you need to create an instance of DarkSkyClient
, and populate the obligatory properties. Then, build a DsForecastRequest
:
final DsForecastRequest forecastRequest = DsForecastRequest.builder()
.latitude(BigDecimal.valueOf("50.84654"))
.longitude(BigDecimal.valueOf("4.35279"))
.excludeBlocks(Arrays.asList(DsBlock.ALERTS,DsBlock.MINUTELY))
.extendHourly(Boolean.FALSE)
.lang(DsLanguage.EN)
.units(DsUnit.SI).build() ;
And call the API :
DsResponse forecast = darkSkyClient.getForecast( forecastRequest ) ;
Firstly, you need to create an instance of DarkSkyClient
, and populate the obligatory properties. Then, build a DsTimeMachineRequest
:
final DsTimeMachineRequest timeMachineRequest = DsTimeMachineRequest.builder()
.latitude(BigDecimal.valueOf("50.84654"))
.longitude(BigDecimal.valueOf("4.35279"))
.time(LocalDateTime.now().minusDays(5).atZone(ZoneId.of("Europe/Brussels")).toEpochSecond())
.excludeBlocks(Arrays.asList(DsBlock.ALERTS,DsBlock.MINUTELY,DsBlock.HOURLY))
.lang(DsLanguage.FR)
.units(DsUnit.SI).build() ;
And finally, call the API :
DsResponse timeMachine = darkSkyClient.getTimeMachine( forecastRequest ) ;