Skip to content

Commit

Permalink
One Call API 3.0 service has been added to retrieve weather overview.
Browse files Browse the repository at this point in the history
  • Loading branch information
MBenincasa committed Nov 24, 2024
1 parent 56c0440 commit 3f6ab05
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.github.mbenincasa.javaopenweathermapclient.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

public class OneCallApiOverviewDTO {

private Double lat;
private Double lon;
private String tz;
private String date;
private String units;
@JsonProperty("weather_overview")
private String weatherOverview;

public OneCallApiOverviewDTO() {
}

public OneCallApiOverviewDTO(Double lat, Double lon, String tz, String date, String units, String weatherOverview) {
this.lat = lat;
this.lon = lon;
this.tz = tz;
this.date = date;
this.units = units;
this.weatherOverview = weatherOverview;
}

public Double getLat() {
return lat;
}

public Double getLon() {
return lon;
}

public String getTz() {
return tz;
}

public String getDate() {
return date;
}

public String getUnits() {
return units;
}

public String getWeatherOverview() {
return weatherOverview;
}

@Override
public String toString() {
return "OneCallApiOverviewDTO{" +
"lat=" + lat +
", lon=" + lon +
", tz='" + tz + '\'' +
", date='" + date + '\'' +
", units='" + units + '\'' +
", weatherOverview='" + weatherOverview + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.mbenincasa.javaopenweathermapclient.dto.OneCallApiCurrentAndForecastsDataDTO;
import io.github.mbenincasa.javaopenweathermapclient.dto.OneCallApiDaySummaryDTO;
import io.github.mbenincasa.javaopenweathermapclient.dto.OneCallApiOverviewDTO;
import io.github.mbenincasa.javaopenweathermapclient.dto.OneCallApiTimemachineDTO;
import io.github.mbenincasa.javaopenweathermapclient.request.common.Lang;
import io.github.mbenincasa.javaopenweathermapclient.request.common.Unit;
Expand Down Expand Up @@ -33,6 +34,10 @@ public BuilderDailyAggregation daySummary(Double lat, Double lon, Integer dt) {
return new BuilderDailyAggregation(lat, lon, dt, this.apiKey);
}

public BuilderOverview overview(Double lat, Double lon) {
return new BuilderOverview(lat, lon, this.apiKey);
}

public static class BuilderCurrentAndForecast {

private final Map<String, Object> query;
Expand Down Expand Up @@ -131,10 +136,40 @@ public BuilderDailyAggregation tz(String tz) {

public OneCallApiDaySummaryDTO response() throws RestClientException {
return HttpRequestExecutor.execute(
/*"https://api.openweathermap.org/data/3.0/onecall/day_summary"*/ "https://run.mocky.io/v3/c665a1ff-f218-40e2-81b1-53078d63066c",
"https://api.openweathermap.org/data/3.0/onecall/day_summary",
this.query,
OneCallApiDaySummaryDTO.class
);
}
}

public static class BuilderOverview {

private final Map<String, Object> query;

private BuilderOverview(Double lat, Double lon, String apiKey) {
this.query = new HashMap<>();
this.query.put("appid", apiKey);
this.query.put("lat", lat);
this.query.put("lon", lon);
}

public BuilderOverview units(Unit unit) {
this.query.put("units", unit.getValue());
return this;
}

public BuilderOverview date(String date) {
this.query.put("date", date);
return this;
}

public OneCallApiOverviewDTO response() throws RestClientException {
return HttpRequestExecutor.execute(
"https://api.openweathermap.org/data/3.0/onecall/overview",
this.query,
OneCallApiOverviewDTO.class
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,18 @@ public void testOneCallApiDaySummary() throws RestClientException {
assertNotNull(response.getTemperature());
}

@Test
public void testOneCallApiOverview() throws RestClientException {
var response = openWeatherMapClient.oneCallApi()
.overview(39.099724, -94.578331)
.date("2024-11-22")
.units(Unit.IMPERIAL)
.response();

assertNotNull(response);
assertNotNull(response.getWeatherOverview());
}

@Test
public void testRequestUnauthorized() {
var requestBuilder = openWeatherMapClientUnauthorized.currentWeather()
Expand Down

0 comments on commit 3f6ab05

Please sign in to comment.