diff --git a/CHANGELOG.md b/CHANGELOG.md index 2709c68..1c16feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All significant changes to this project will be documented in this file. +## [0.5.0] - 2024-11-24 + +### Added +- **One Call API 3.0**: Get essential weather data, short-term and long-term forecasts and aggregated weather data. + ## [0.4.0] - 2024-10-29 ### Added diff --git a/README.md b/README.md index 34a59a7..acecc9c 100644 --- a/README.md +++ b/README.md @@ -18,16 +18,24 @@ The OpenWeatherMap Java Client Library is a robust and easy-to-use Java library - [Donations](#donations) ## Features -- Current Weather -- 3-hour Forecast 5 days -- Hourly Forecast 4 days -- Daily Forecast 16 days -- Climatic Forecast 30 days -- Basic weather maps -- Advanced weather maps -- Historical maps -- Air Pollution API -- Geocoding API +- **One Call API 3.0** + - Current and forecasts weather data + - Weather data for timestamp + - Daily Aggregation + - Weather overview +- **Current & Forecast weather data collection** + - Current Weather + - 3-hour Forecast 5 days + - Hourly Forecast 4 days + - Daily Forecast 16 days + - Climatic Forecast 30 days +- **Maps collection** + - Basic weather maps + - Advanced weather maps + - Historical maps +- **Other weather API's collection** + - Air Pollution API + - Geocoding API ## Minimum Requirements Java 17 or above. @@ -44,7 +52,7 @@ To include this library in your Maven project, add the following dependency to y io.github.mbenincasa java-open-weather-map-client - 0.4.0 + 0.5.0 ``` diff --git a/docs/RELEASE_0.5.0.md b/docs/RELEASE_0.5.0.md new file mode 100644 index 0000000..e53561e --- /dev/null +++ b/docs/RELEASE_0.5.0.md @@ -0,0 +1,718 @@ +# Release 0.5.0 + +## Table of Contents +1. [Overview](#overview) +2. [Features](#features) +3. [OpenWeatherMapClient](#openweathermapclient) +4. [Usage](#usage) + 1. [Setting Up the Client](#setting-up-the-client) + 2. [One Call API 3.0](#one-call-api-30) + 3. [Current Weather](#current-weather) + 4. [3-Hour 5-Day Weather Forecast](#3-hour-5-day-weather-forecast) + 5. [Hourly 4-Day Forecast](#hourly-4-day-weather-forecast) + 6. [Daily 16-Day Weather Forecast](#daily-16-day-weather-forecast) + 7. [Climatic 30-Day Weather Forecast](#climatic-30-day-weather-forecast) + 8. [Air Pollution](#air-pollution) + 9. [Geocoding](#geocoding) + 10. [Basic weather maps](#basic-weather-maps) + 11. [Advanced weather maps](#advanced-weather-maps) + +## 1. Overview +Version `0.5.0` introduces **One Call API 3.0**, a comprehensive solution for retrieving essential weather data. This update allows users to access both **short-term** and **long-term forecasts**, along with **aggregated weather data**. With this new addition, the library expands its capabilities to provide a more complete weather data experience. + +## 2. Features +- **One Call API 3.0** + - Current and forecasts weather data + - Weather data for timestamp + - Daily Aggregation + - Weather overview +- **Current & Forecast weather data collection** + - Current Weather + - 3-hour Forecast (5 days) + - Hourly Forecast (4 days) + - Daily Forecast (16 days) + - Climatic Forecast (30 days) +- **Maps collection** + - Basic weather maps + - Advanced weather maps + - Historical maps +- **Other weather API's collection** + - Air Pollution API + - Geocoding API + +## 3. OpenWeatherMapClient +The `OpenWeatherMapClient` interface provides methods to access various weather-related services through the OpenWeatherMap API. Each method returns a request builder for different types of data, such as current weather, forecasts, air pollution, and geocoding. + +### 3.1. Methods +- **`currentWeather()`**: Returns an instance of `CurrentWeatherRequest` for retrieving real-time weather data for any location. +- **`fiveDaysWeatherForecast()`**: Returns an instance of `FiveDaysWeatherForecastRequest` for getting 3-hourly weather forecasts for the next 5 days. +- **`dailyWeatherForecast()`**: Returns an instance of `DailyWeatherForecastRequest` for retrieving daily weather forecasts for up to 16 days. +- **`hourlyWeatherForecast()`**: Returns an instance of `HourlyWeatherForecastRequest` for obtaining hourly weather forecasts. +- **`climaticWeatherForecast()`**: Returns an instance of `ClimaticWeatherForecastRequest` for accessing broader climatic forecasts. +- **`airPollution()`**: Returns an instance of `AirPollutionRequest` for obtaining current air quality data. +- **`geocoding()`**: Returns an instance of `GeocodingRequest` for converting location names or zip codes into geographic coordinates. +- **`basicWeatherMap()`**: Returns an instance of `BasicWeatherMapRequest` for accessing basic weather map data. +- **`advancedWeatherMap()`**: Returns an instance of `AdvancedWeatherMapRequest` for accessing advanced weather map data. + +## 4. Usage +This section will guide you on how to use the `OpenWeatherMapClient` to access various services provided by the API. We will cover how to retrieve current weather, forecasts, air pollution data, and geocoding using coordinates, city names, and postal codes + +### 4.1. Setting Up the Client +First, create an instance of `OpenWeatherMapClient` by passing your API key: + +```java +var apiKey = "YOUR_API_KEY"; +OpenWeatherMapClient openWeatherMapClient = new DefaultOpenWeatherMapClient(apiKey); +``` + +### 4.2. One Call API 3.0 +Get essential weather data, short-term and long-term forecasts and aggregated weather data. + +#### 4.2.1. Available Methods for Current and forecasts weather data +- `currentAndForecastsData(Double lat, Double lon)`: Retrieves current and forecast weather data for a given geographic location using latitude and longitude. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `exclude(OneCallApiExclude... excludes)` (optional): Specifies which parts of the weather data to exclude in the response, such as hourly or daily forecasts. + - **Parameters**: + - `excludes`: One or more `OneCallApiExclude` values indicating the data to exclude. +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature, e.g., Metric or Imperial. + - **Parameters**: + - `unit`: The unit of measurement (e.g., `Unit.METRIC` or `Unit.IMPERIAL`). +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions in the response. + - **Parameters**: + - `lang`: The desired language (e.g., `Lang.ITALIAN` or `Lang.ENGLISH`). +- `response()`: Executes the HTTP request and retrieves current weather data along with forecasts. Returns a `OneCallApiCurrentAndForecastsDataDTO` object containing weather details. + +#### 4.2.2. Available Methods for Weather data for timestamp +- `timemachine(Double lat, Double lon, Integer dt)`: Retrieves historical weather data for a specific date and time (UNIX timestamp) at the given geographic location. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. + - `dt`: The UNIX timestamp for the date and time you want to retrieve weather data for. +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature, e.g., Metric or Imperial. + - **Parameters**: + - `unit`: The unit of measurement (e.g., `Unit.METRIC` or `Unit.IMPERIAL`). +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions in the response. + - **Parameters**: + - `lang`: The desired language (e.g., `Lang.ITALIAN` or `Lang.ENGLISH`). +- `response()`: Executes the HTTP request and retrieves historical weather data for the specified date and time. Returns a `OneCallApiTimemachineDTO` object containing the historical weather data. + +#### 4.2.3. Available Methods for Daily Aggregation +- `daySummary(Double lat, Double lon, Integer dt)`: Retrieves daily aggregated weather summary data for a specific date and time (UNIX timestamp) at the given geographic location. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. + - `dt`: The UNIX timestamp for the date and time of the weather data. +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature, e.g., Metric or Imperial. + - **Parameters**: + - `unit`: The unit of measurement (e.g., `Unit.METRIC` or `Unit.IMPERIAL`). +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions in the response. + - **Parameters**: + - `lang`: The desired language (e.g., `Lang.ITALIAN` or `Lang.ENGLISH`). +- `tz(String tz)` (optional): Specifies the timezone in which the returned time will be expressed. + - **Parameters**: + - `tz`: The timezone (e.g., "Europe/Rome" or "America/New_York"). +- `response()`: Executes the HTTP request and retrieves daily aggregated weather summary data for the specified date and time. Returns a `OneCallApiDaySummaryDTO` object containing the summary weather data. + +#### 4.2.4. Available Methods for Weather overview +- `overview(Double lat, Double lon)`: Retrieves an overview of the weather for a specific geographic location using latitude and longitude. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature, e.g., Metric or Imperial. + - **Parameters**: + - `unit`: The unit of measurement (e.g., `Unit.METRIC` or `Unit.IMPERIAL`). +- `date(String date)` (optional): Specifies a particular date to retrieve weather overview information for. + - **Parameters**: + - `date`: The desired date (e.g., "2024-11-25"). +- `response()`: Executes the HTTP request and retrieves a weather overview for the specified geographic location. Returns a `OneCallApiOverviewDTO` object containing the overview weather data. + +#### 4.2.5. Current and forecasts weather data +Get access to current weather, minute forecast for 1 hour, hourly forecast for 48 hours, daily forecast for 8 days and government weather alerts + +```java +var response = openWeatherMapClient.oneCallApi() + .currentAndForecastsData(45.5101617, 9.0894415) + .exclude(OneCallApiExclude.CURRENT, OneCallApiExclude.MINUTELY) + .lang(Lang.ITALIAN) + .units(Unit.IMPERIAL) + .response(); + +System.out.println("Current temperature: " + response.getCurrent().getTemp()); +``` + +#### 4.2.6. Weather data for timestamp +Get access to weather data for any timestamp from 1st January 1979 till 4 days ahead forecast + +```java +var response = openWeatherMapClient.oneCallApi() + .timemachine(39.099724, -94.578331, 1643803200) + .lang(Lang.ITALIAN) + .units(Unit.IMPERIAL) + .response(); + +System.out.println("Temperature: " + response.getData().get(0).getTemp()); +``` + +#### 4.2.7. Daily Aggregation +Get access to aggregated weather data for a particular date from 2nd January 1979 till long-term forecast for 1,5 years ahead + +```java +var response = openWeatherMapClient.oneCallApi() + .daySummary(39.099724, -94.578331, 1643803200) + .tz("+01:00") + .lang(Lang.ITALIAN) + .units(Unit.IMPERIAL) + .response(); + +System.out.println("Morning temperature: " + response.getTemperature().getMorning()); +``` + +#### 4.2.8. Weather overview +Weather overview with a human-readable weather summary for today and tomorrow's forecast, utilizing OpenWeather AI technologies + +```java +var response = openWeatherMapClient.oneCallApi() + .overview(39.099724, -94.578331) + .date("2024-11-22") + .units(Unit.IMPERIAL) + .response(); + +System.out.println("Overview: " + response.getWeatherOverview()); +``` + +### 4.3. Current Weather +Retrieve real-time weather data for any location using coordinates, city name, city ID, or zip code. + +#### 4.3.1. Available Methods for Current Weather +- `coordinates(Double lat, Double lon)`: Retrieves current weather data using geographic coordinates (latitude and longitude). + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `cityName(String cityName, String stateCode, String countryCode)`: Retrieves weather data for a specific city by its name. Optionally, a state code and country code can be provided for higher accuracy. + - **Parameters**: + - `cityName`: The name of the desired city. + - `stateCode` (optional): The state code, useful in countries with cities sharing the same name. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `cityId(Integer cityId)`: Fetches weather data using the unique city ID. Each city in the OpenWeather database has a unique ID. + - **Parameters**: + - `cityId`: The unique city ID. +- `zipCode(String zipCode, String countryCode)`: Retrieves weather data using a zip code. Optionally, a country code can be provided for higher accuracy. + - **Parameters**: + - `zipCode`: The zip code of the location. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature. +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions. +- `response()`: Executes the HTTP request and retrieves the current weather data. Returns a `CurrentWeatherDTO` object containing weather details. + +#### 4.3.2. By Coordinates +Fetch current weather data using geographic coordinates (latitude and longitude). + +```java +var response = openWeatherMapClient.currentWeather() + .coordinates(45.5101617, 9.0894415) + .units(Unit.METRIC) + .lang(Lang.ITALIAN) + .response(); + +System.out.println("Temperature: " + response.getMain().getTemp()); +System.out.println("Weather: " + response.getWeather().get(0).getDescription()); +``` + +#### 4.3.3. By City Name +Retrieve current weather data using a city name. + +```java +var response = openWeatherMapClient.currentWeather() + .cityName("London", null, "uk") + .response(); + +System.out.println("Temperature: " + response.getMain().getTemp()); +System.out.println("Weather: " + response.getWeather().get(0).getDescription()); +``` + +#### 4.3.4. By City ID +Fetch current weather data using a city ID. City IDs are unique identifiers for cities. + +```java +var response = openWeatherMapClient.currentWeather() + .cityId(2643743) + .response(); + +System.out.println("Temperature: " + response.getMain().getTemp()); +System.out.println("Weather: " + response.getWeather().get(0).getDescription()); +``` + +#### 4.3.5. By Zip Code +Retrieve current weather data using a zip code. + +```java +var response = openWeatherMapClient.currentWeather() + .zipCode("20016", "it") + .response(); + +System.out.println("Temperature: " + response.getMain().getTemp()); +System.out.println("Weather: " + response.getWeather().get(0).getDescription()); +``` + +### 4.4. 3-Hour 5-Day Weather Forecast +Get detailed weather forecasts in 3-hour intervals for the next 5 days. + +#### 4.4.1. Available Methods for 3-Hour 5-Day Weather Forecast +- `coordinates(Double lat, Double lon)`: Fetches the weather forecast using geographic coordinates (latitude and longitude). + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `cityName(String cityName, String stateCode, String countryCode)`: Retrieves the weather forecast for a specific city by its name. Optionally, a state code and country code can be provided for higher accuracy. + - **Parameters**: + - `cityName`: The name of the desired city. + - `stateCode` (optional): The state code, useful in countries with cities sharing the same name. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `cityId(Integer cityId)`: Fetches the weather forecast using the unique city ID. Each city in the OpenWeather database has a unique ID. + - **Parameters**: + - `cityId`: The unique city ID. +- `zipCode(String zipCode, String countryCode)`: Retrieves the weather forecast using a zip code. Optionally, a country code can be provided for higher accuracy. + - **Parameters**: + - `zipCode`: The zip code of the location. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature. +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions. +- `cnt(Integer cnt)` (optional): Limits the number of forecast entries returned. +- `response()`: Executes the HTTP request and retrieves the weather forecast data. Returns a `FiveDaysWeatherForecastDTO` object containing the forecast details. + +#### 4.4.2. By Coordinates +Fetch a 5-day weather forecast using geographic coordinates. + +```java +var response = openWeatherMapClient.fiveDaysWeatherForecast() + .coordinates(45.5101617, 9.0894415) + .cnt(4) + .units(Unit.METRIC) + .lang(Lang.ITALIAN) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +#### 4.4.3. By City Name +Retrieve a 5-day weather forecast using a city name. + +```java +var response = openWeatherMapClient.fiveDaysWeatherForecast() + .cityName("London", null, "uk") + .cnt(4) + .units(Unit.METRIC) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +#### 4.4.4. By City ID +Fetch a 5-day weather forecast using a city ID. + +```java +var response = openWeatherMapClient.fiveDaysWeatherForecast() + .cityId(2643743) + .cnt(2) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +#### 4.4.5. By Zip Code +Retrieve a 5-day weather forecast using a zip code. + +```java +var response = openWeatherMapClient.fiveDaysWeatherForecast() + .zipCode("20016", "it") + .cnt(2) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +### 4.5. Hourly 4-Day Weather Forecast +Get detailed weather forecasts at hourly intervals for the next 4 days. + +#### 4.5.1. Available Methods for Hourly Weather Forecast +- `coordinates(Double lat, Double lon)`: Fetches the hourly weather forecast using geographic coordinates (latitude and longitude). + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `cityName(String cityName, String stateCode, String countryCode)`: Retrieves the hourly weather forecast for a specific city by its name. Optionally, a state code and country code can be provided for higher accuracy. + - **Parameters**: + - `cityName`: The name of the desired city. + - `stateCode` (optional): The state code, useful in countries with cities sharing the same name. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `cityId(Integer cityId)`: Fetches the hourly weather forecast using the unique city ID. Each city in the OpenWeather database has a unique ID. + - **Parameters**: + - `cityId`: The unique city ID. +- `zipCode(String zipCode, String countryCode)`: Retrieves the hourly weather forecast using a zip code. Optionally, a country code can be provided for higher accuracy. + - **Parameters**: + - `zipCode`: The zip code of the location. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature. +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions. +- `response()`: Executes the HTTP request and retrieves the hourly weather forecast data. Returns a `HourlyWeatherForecastDTO` object containing the forecast details. + +#### 4.5.2. By Coordinates +Fetch a 4-day hourly weather forecast using geographic coordinates. + +```java +var response = openWeatherMapClient.hourlyWeatherForecast() + .coordinates(45.5101617, 9.0894415) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getList().size()); +``` + +#### 4.5.3. By City Name +Retrieve a 4-day hourly weather forecast using a city name. + +```java +var response = openWeatherMapClient.hourlyWeatherForecast() + .cityName("London", null, "uk") + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getList().size()); +``` + +#### 4.5.4. By City ID +Fetch a 4-day hourly weather forecast using a city ID. + +```java +var response = openWeatherMapClient.hourlyWeatherForecast() + .cityId(2643743) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getList().size()); +``` + +#### 4.5.5. By Zip Code +Retrieve a 4-day hourly weather forecast using a zip code. + +```java +var response = openWeatherMapClient.hourlyWeatherForecast() + .zipCode("20016", "it") + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getList().size()); +``` + +### 4.6. Daily 16-Day Weather Forecast +Get detailed weather forecasts at daily intervals for the next 16 days. + +#### 4.6.1. Available Methods for Daily 16-Day Weather Forecast +- `coordinates(Double lat, Double lon)`: Fetches the daily weather forecast using geographic coordinates (latitude and longitude). + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `cityName(String cityName, String stateCode, String countryCode)`: Retrieves the daily weather forecast for a specific city by its name. Optionally, a state code and country code can be provided for higher accuracy. + - **Parameters**: + - `cityName`: The name of the desired city. + - `stateCode` (optional): The state code, useful in countries with cities sharing the same name. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `cityId(Integer cityId)`: Fetches the daily weather forecast using the unique city ID. Each city in the OpenWeather database has a unique ID. + - **Parameters**: + - `cityId`: The unique city ID. +- `zipCode(String zipCode, String countryCode)`: Retrieves the daily weather forecast using a zip code. Optionally, a country code can be provided for higher accuracy. + - **Parameters**: + - `zipCode`: The zip code of the location. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature. +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions. +- `cnt(Integer cnt)` (optional): Limits the number of forecast entries returned. +- `response()`: Executes the HTTP request and retrieves the daily weather forecast data. Returns a `DailyWeatherForecastDTO` object containing the forecast details. + +#### 4.6.2. By Coordinates +Fetch a 16-day weather forecast using geographic coordinates. + +```java +var response = openWeatherMapClient.dailyWeatherForecast() + .coordinates(45.5101617, 9.0894415) + .cnt(4) + .units(Unit.METRIC) + .lang(Lang.ITALIAN) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +#### 4.6.3. By City Name +Retrieve a 16-day weather forecast using a city name. + +```java +var response = openWeatherMapClient.dailyWeatherForecast() + .cityName("London", null, "uk") + .cnt(4) + .units(Unit.METRIC) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +#### 4.6.4. By City ID +Fetch a 16-day weather forecast using a city ID. + +```java +var response = openWeatherMapClient.dailyWeatherForecast() + .cityId(2643743) + .cnt(2) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +#### 4.6.5. By Zip Code +Retrieve a 16-day weather forecast using a zip code. + +```java +var response = openWeatherMapClient.dailyWeatherForecast() + .zipCode("20016", "it") + .cnt(2) + .response(); + +System.out.println("City: " + response.getCity().getName()); +System.out.println("Number of forecast entries: " + response.getCnt()); +``` + +### 4.7. Climatic 30-Day Weather Forecast +Get detailed climatic forecasts, providing long-term weather predictions. + +#### 4.7.1. Available Methods for Climatic Weather Forecast +- `coordinates(Double lat, Double lon)`: Fetches the climatic weather forecast using geographic coordinates (latitude and longitude). + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `cityName(String cityName, String stateCode, String countryCode)`: Retrieves the climatic weather forecast for a specific city by its name. Optionally, a state code and country code can be provided for higher accuracy. + - **Parameters**: + - `cityName`: The name of the desired city. + - `stateCode` (optional): The state code, useful in countries with cities sharing the same name. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `cityId(Integer cityId)`: Fetches the climatic weather forecast using the unique city ID. Each city in the OpenWeather database has a unique ID. + - **Parameters**: + - `cityId`: The unique city ID. +- `zipCode(String zipCode, String countryCode)`: Retrieves the climatic weather forecast using a zip code. Optionally, a country code can be provided for higher accuracy. + - **Parameters**: + - `zipCode`: The zip code of the location. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "uk" for the United Kingdom). +- `units(Unit unit)` (optional): Specifies the unit of measurement for the temperature. +- `lang(Lang lang)` (optional): Specifies the language for weather descriptions. +- `response()`: Executes the HTTP request and retrieves the climatic weather forecast data. Returns a `ClimaticWeatherForecastDTO` object containing the forecast details. + +#### 4.7.2. By Coordinates +Fetch a climatic weather forecast using geographic coordinates. + +```java +var response = openWeatherMapClient.climaticWeatherForecast() + .coordinates(45.5101617, 9.0894415) + .response(); + +System.out.println("City: " + response.getCity().getName()); +``` + +#### 4.7.3. By City Name +Retrieve a climatic weather forecast using a city name. + +```java +var response = openWeatherMapClient.climaticWeatherForecast() + .cityName("London", null, "uk") + .response(); + +System.out.println("City: " + response.getCity().getName()); +``` + +#### 4.7.4. By City ID +Fetch a climatic weather forecast using a city ID. + +```java +var response = openWeatherMapClient.climaticWeatherForecast() + .cityId(2643743) + .response(); + +System.out.println("City: " + response.getCity().getName()); +``` + +#### 4.7.5. By Zip Code +Retrieve a climatic weather forecast using a zip code. + +```java +var response = openWeatherMapClient.climaticWeatherForecast() + .zipCode("20016", "it") + .response(); + +System.out.println("City: " + response.getCity().getName()); +``` + +### 4.8. Air Pollution +Obtain air quality data, including pollutant levels. + +#### 4.8.1. Available Methods for Current Air Pollution +- `current()`: Initiates a request for current air pollution data. +- `coordinates(Double lat, Double lon)`: Sets the geographic coordinates (latitude and longitude) for the request. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `response()`: Executes the HTTP request and retrieves the current air pollution data. Returns an `AirPollutionDTO` object containing air quality information. + +#### 4.8.2. Available Methods for Forecast Air Pollution +- `forecast()`: Initiates a request for forecasted air pollution data. +- `coordinates(Double lat, Double lon)`: Sets the geographic coordinates (latitude and longitude) for the forecast request. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. +- `response()`: Executes the HTTP request and retrieves the forecast air pollution data. Returns an `AirPollutionDTO` object containing predicted air quality information. + +#### 4.8.3. Available Methods for Historical Air Pollution +- `historical()`: Initiates a request for historical air pollution data. +- `coordinatesAndTime(Double lat, Double lon, Integer start, Integer end)`: Sets the geographic coordinates and time range (in UNIX timestamps) for the historical data request. + - **Parameters**: + - `lat`: The latitude of the desired location. + - `lon`: The longitude of the desired location. + - `start`: The start time in UNIX timestamp format. + - `end`: The end time in UNIX timestamp format. +- `response()`: Executes the HTTP request and retrieves the historical air pollution data. Returns an `AirPollutionDTO` object containing air quality information for the given time range. + +#### 4.8.4. Current Air Pollution +Fetch current air pollution data using coordinates. + +```java +var response = openWeatherMapClient.airPollution() + .current() + .coordinates(45.5101617, 9.0894415) + .response(); + +System.out.println("Air Quality Index: " + response.getList().get(0).getMain().getAqi()); +``` + +#### 4.8.5. Forecast Air Pollution +Get forecasted air pollution data using coordinates. + +```java +var response = openWeatherMapClient.airPollution() + .forecast() + .coordinates(45.5101617, 9.0894415) + .response(); + +System.out.println("Air Quality Index: " + response.getList().get(0).getMain().getAqi()); +``` + +#### 4.8.6. Historical Air Pollution +Retrieve historical air pollution data using coordinates and a time range. + +```java +var response = openWeatherMapClient.airPollution() + .historical() + .coordinatesAndTime(45.5101617, 9.0894415, 1606223802, 1606482999) + .response(); + +System.out.println("Air Quality Index: " + response.getList().get(0).getMain().getAqi()); +``` + +### 4.9. Geocoding +Convert location names or zip codes into precise geographic data. + +#### 4.9.1. Available Methods for Geocoding +- **By Location Name** + - `locationName(String cityName, String stateCode, String countryCode)`: Converts a location name to geographic coordinates. Optionally, you can specify a state code and a country code for more accurate results. + - **Parameters**: + - `cityName`: The name of the city or location. + - `stateCode` (optional): The state code for locations with common city names. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "us" for the United States). + - `limit(Integer limit)` (optional): Limits the number of results returned. + - `response()`: Returns a list of `GeocodingLocationDTO` objects containing details like geographic coordinates and location names. +- **By Zip Code** + - `zipCode(String zipCode, String countryCode)`: Converts a zip code to geographic coordinates. Optionally, a country code can be provided. + - **Parameters**: + - `zipCode`: The zip code for the location. + - `countryCode` (optional): The country code in ISO 3166 format (e.g., "it" for Italy, "us" for the United States). + - `response()`: Returns a `GeocodingZipDTO` object containing details such as geographic coordinates and location names. + +#### 4.9.2. By Location Name +Convert a location name to geographic coordinates and other details. + +```java +var response = openWeatherMapClient.geocoding() + .locationName("London", "England", "GB") + .response(); + +var dto = response.get(0); +System.out.println("City: " + dto.getName()); +System.out.println("Country: " + dto.getCountry()); +``` + +#### 4.9.3. By Zip Code +Convert a zip code to geographic coordinates and other details. + +```java +var response = openWeatherMapClient.geocoding() + .zipCode("E14", "GB") + .response(); + +System.out.println("City: " + response.getName()); +System.out.println("Country: " + response.getCountry()); +``` + +### 4.10. Basic Weather Maps +Access various types of basic weather maps, including precipitation, clouds, pressure, temperature, and wind. + +#### 4.10.1. Available Methods for Basic Weather Maps +- `layerAndCoords(BasicMapLayer layer, Integer x, Integer y, Integer z)`: Prepares a request for a specific weather map layer using tile coordinates (x, y) and zoom level (z). + - **Parameters**: + - `layer`: The type of weather map layer to retrieve (e.g., precipitation, temperature). + - `x`: The x-coordinate of the tile. + - `y`: The y-coordinate of the tile. + - `z`: The zoom level for the map. +- `response()`: Returns the map image as a byte array for rendering or saving. + +#### 4.10.2. Get Map Layer +Retrieve a specific weather map layer for given coordinates and zoom level. + +```java +var response = openWeatherMapClient.basicWeatherMap() + .layerAndCoords(BasicMapLayer.PRECIPITATION, 0, 0, 0) + .response(); +``` + +### 4.11. Advanced Weather Maps +Access a variety of advanced weather maps, including forecast, historical, and current weather visualizations with customizable options. + +#### 4.11.1. Available Methods for Advanced Weather Maps +- `layerAndCoords(AdvancedMapLayer layer, Integer x, Integer y, Integer z)`: Prepares a request for a specific advanced weather map layer using tile coordinates (x, y) and zoom level (z). + - **Parameters**: + - `layer`: The type of advanced weather map layer to retrieve (e.g., wind, temperature). + - `x`: The x-coordinate of the tile. + - `y`: The y-coordinate of the tile. + - `z`: The zoom level for the map. +- `date(Integer date)` (optional): Specifies the date for historical data retrieval. +- `opacity(Double opacity)` (optional): Sets the opacity level for the map layer. +- `palette(String palette)` (optional): Chooses a color palette for the map visualization. +- `fillBound(boolean fillBound)` (optional): Determines whether to fill the boundaries in the map. +- `arrowStep(Integer arrowStep)` (optional): Sets the step for arrow representation on wind maps. +- `useNorm(boolean useNorm)` (optional): Specifies whether to use normalized values for the visualization. +- `response()`: Returns the map image as a byte array for rendering or saving. + +#### 4.11.2. Get Map Layer +Retrieve a specific advanced weather map layer for given coordinates and zoom level, with additional options for customization. + +```java +var response = openWeatherMapClient.advancedWeatherMap() + .layerAndCoords(AdvancedMapLayer.AIR_TEMPERATURE, 0, 0, 0) + .date(1552861800) + .opacity(0.6) + .palette("0:FF8800;10:88FF88;20:0088FF") + .fillBound(true) + .response(); +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 14f6b1b..4a64762 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.mbenincasa java-open-weather-map-client - 0.4.0 + 0.5.0 17 diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClient.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClient.java index 11d30f2..6056038 100644 --- a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClient.java +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClient.java @@ -3,6 +3,7 @@ import io.github.mbenincasa.javaopenweathermapclient.request.airPollution.AirPollutionRequest; import io.github.mbenincasa.javaopenweathermapclient.request.currentWeather.CurrentWeatherRequest; import io.github.mbenincasa.javaopenweathermapclient.request.geocoding.GeocodingRequest; +import io.github.mbenincasa.javaopenweathermapclient.request.oneCallApi.OneCallApiRequest; import io.github.mbenincasa.javaopenweathermapclient.request.weatherForecast.ClimaticWeatherForecastRequest; import io.github.mbenincasa.javaopenweathermapclient.request.weatherForecast.DailyWeatherForecastRequest; import io.github.mbenincasa.javaopenweathermapclient.request.weatherForecast.FiveDaysWeatherForecastRequest; @@ -62,4 +63,9 @@ public BasicWeatherMapRequest basicWeatherMap() { public AdvancedWeatherMapRequest advancedWeatherMap() { return new AdvancedWeatherMapRequest(this.apiKey); } + + @Override + public OneCallApiRequest oneCallApi() { + return new OneCallApiRequest(this.apiKey); + } } diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/OpenWeatherMapClient.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/OpenWeatherMapClient.java index f0b60f1..b9d2de3 100644 --- a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/OpenWeatherMapClient.java +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/client/OpenWeatherMapClient.java @@ -3,6 +3,7 @@ import io.github.mbenincasa.javaopenweathermapclient.request.airPollution.AirPollutionRequest; import io.github.mbenincasa.javaopenweathermapclient.request.currentWeather.CurrentWeatherRequest; import io.github.mbenincasa.javaopenweathermapclient.request.geocoding.GeocodingRequest; +import io.github.mbenincasa.javaopenweathermapclient.request.oneCallApi.OneCallApiRequest; import io.github.mbenincasa.javaopenweathermapclient.request.weatherForecast.ClimaticWeatherForecastRequest; import io.github.mbenincasa.javaopenweathermapclient.request.weatherForecast.DailyWeatherForecastRequest; import io.github.mbenincasa.javaopenweathermapclient.request.weatherForecast.FiveDaysWeatherForecastRequest; @@ -29,4 +30,6 @@ public interface OpenWeatherMapClient { BasicWeatherMapRequest basicWeatherMap(); AdvancedWeatherMapRequest advancedWeatherMap(); + + OneCallApiRequest oneCallApi(); } diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiCurrentAndForecastsDataDTO.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiCurrentAndForecastsDataDTO.java new file mode 100644 index 0000000..b13919b --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiCurrentAndForecastsDataDTO.java @@ -0,0 +1,86 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts.*; + +import java.util.List; + +public class OneCallApiCurrentAndForecastsDataDTO { + + private Double lat; + private Double lon; + private String timezone; + @JsonProperty("timezone_offset") + private Integer timezoneOffset; + private Current current; + private List minutely; + private List hourly; + private List daily; + private List alerts; + + public OneCallApiCurrentAndForecastsDataDTO() { + } + + public OneCallApiCurrentAndForecastsDataDTO(Double lat, Double lon, String timezone, Integer timezoneOffset, Current current, List minutely, List hourly, List daily, List alerts) { + this.lat = lat; + this.lon = lon; + this.timezone = timezone; + this.timezoneOffset = timezoneOffset; + this.current = current; + this.minutely = minutely; + this.hourly = hourly; + this.daily = daily; + this.alerts = alerts; + } + + public Double getLat() { + return lat; + } + + public Double getLon() { + return lon; + } + + public String getTimezone() { + return timezone; + } + + public Integer getTimezoneOffset() { + return timezoneOffset; + } + + public Current getCurrent() { + return current; + } + + public List getMinutely() { + return minutely; + } + + public List getHourly() { + return hourly; + } + + public List getDaily() { + return daily; + } + + public List getAlerts() { + return alerts; + } + + @Override + public String toString() { + return "OneCallApiCurrentAndForecastsDataDTO{" + + "lat=" + lat + + ", lon=" + lon + + ", timezone='" + timezone + '\'' + + ", timezoneOffset=" + timezoneOffset + + ", current=" + current + + ", minutely=" + minutely + + ", hourly=" + hourly + + ", daily=" + daily + + ", alerts=" + alerts + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiDaySummaryDTO.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiDaySummaryDTO.java new file mode 100644 index 0000000..f9a3d6f --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiDaySummaryDTO.java @@ -0,0 +1,98 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary.*; + +public class OneCallApiDaySummaryDTO { + + private Double lat; + private Double lon; + private String tz; + private String date; + private String units; + @JsonProperty("cloud_cover") + private CloudCover cloudCover; + private Humidity humidity; + private Precipitation precipitation; + private Temperature temperature; + private Pressure pressure; + private Wind wind; + + public OneCallApiDaySummaryDTO() { + } + + public OneCallApiDaySummaryDTO(Double lat, Double lon, String tz, String date, String units, CloudCover cloudCover, Humidity humidity, Precipitation precipitation, Temperature temperature, Pressure pressure, Wind wind) { + this.lat = lat; + this.lon = lon; + this.tz = tz; + this.date = date; + this.units = units; + this.cloudCover = cloudCover; + this.humidity = humidity; + this.precipitation = precipitation; + this.temperature = temperature; + this.pressure = pressure; + this.wind = wind; + } + + 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 CloudCover getCloudCover() { + return cloudCover; + } + + public Humidity getHumidity() { + return humidity; + } + + public Precipitation getPrecipitation() { + return precipitation; + } + + public Temperature getTemperature() { + return temperature; + } + + public Pressure getPressure() { + return pressure; + } + + public Wind getWind() { + return wind; + } + + @Override + public String toString() { + return "OneCallApiDaySummaryDTO{" + + "lat=" + lat + + ", lon=" + lon + + ", tz='" + tz + '\'' + + ", date='" + date + '\'' + + ", units='" + units + '\'' + + ", cloudCover=" + cloudCover + + ", humidity=" + humidity + + ", precipitation=" + precipitation + + ", temperature=" + temperature + + ", pressure=" + pressure + + ", wind=" + wind + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiOverviewDTO.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiOverviewDTO.java new file mode 100644 index 0000000..09f03f3 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiOverviewDTO.java @@ -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 + '\'' + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiTimemachineDTO.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiTimemachineDTO.java new file mode 100644 index 0000000..7605a8a --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/OneCallApiTimemachineDTO.java @@ -0,0 +1,58 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.timemachine.Data; + +import java.util.List; + +public class OneCallApiTimemachineDTO { + + private Double lat; + private Double lon; + private String timezone; + @JsonProperty("timezone_offset") + private Integer timezoneOffset; + private List data; + + public OneCallApiTimemachineDTO() { + } + + public OneCallApiTimemachineDTO(Double lat, Double lon, String timezone, Integer timezoneOffset, List data) { + this.lat = lat; + this.lon = lon; + this.timezone = timezone; + this.timezoneOffset = timezoneOffset; + this.data = data; + } + + public Double getLat() { + return lat; + } + + public Double getLon() { + return lon; + } + + public String getTimezone() { + return timezone; + } + + public Integer getTimezoneOffset() { + return timezoneOffset; + } + + public List getData() { + return data; + } + + @Override + public String toString() { + return "OneCallApiTimemachineDTO{" + + "lat=" + lat + + ", lon=" + lon + + ", timezone='" + timezone + '\'' + + ", timezoneOffset=" + timezoneOffset + + ", data=" + data + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Alerts.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Alerts.java new file mode 100644 index 0000000..2fd85b3 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Alerts.java @@ -0,0 +1,64 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class Alerts { + + @JsonProperty("sender_name") + private String senderName; + private String event; + private Integer start; + private Integer end; + private String description; + private List tags; + + public Alerts() { + } + + public Alerts(String senderName, String event, Integer start, Integer end, String description, List tags) { + this.senderName = senderName; + this.event = event; + this.start = start; + this.end = end; + this.description = description; + this.tags = tags; + } + + public String getSenderName() { + return senderName; + } + + public String getEvent() { + return event; + } + + public Integer getStart() { + return start; + } + + public Integer getEnd() { + return end; + } + + public String getDescription() { + return description; + } + + public List gettags() { + return tags; + } + + @Override + public String toString() { + return "Alerts{" + + "senderName='" + senderName + '\'' + + ", event='" + event + '\'' + + ", start=" + start + + ", end=" + end + + ", description='" + description + '\'' + + ", tags=" + tags + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Current.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Current.java new file mode 100644 index 0000000..0d8e70b --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Current.java @@ -0,0 +1,146 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.common.Weather; + +import java.util.List; + +public class Current { + + private Integer dt; + private Integer sunrise; + private Integer sunset; + private Double temp; + @JsonProperty("feels_like") + private Double feelsLike; + private Integer pressure; + private Integer humidity; + @JsonProperty("dew_point") + private Double dewPoint; + private Double uvi; + private Integer clouds; + private Integer visibility; + @JsonProperty("wind_speed") + private Double windSpeed; + @JsonProperty("wind_deg") + private Integer windDeg; + @JsonProperty("wind_gust") + private Double windGust; + private List weather; + private Rain rain; + private Snow snow; + + public Current() { + } + + public Current(Integer dt, Integer sunrise, Integer sunset, Double temp, Double feelsLike, Integer pressure, Integer humidity, Double dewPoint, Double uvi, Integer clouds, Integer visibility, Double windSpeed, Integer windDeg, Double windGust, List weather, Rain rain, Snow snow) { + this.dt = dt; + this.sunrise = sunrise; + this.sunset = sunset; + this.temp = temp; + this.feelsLike = feelsLike; + this.pressure = pressure; + this.humidity = humidity; + this.dewPoint = dewPoint; + this.uvi = uvi; + this.clouds = clouds; + this.visibility = visibility; + this.windSpeed = windSpeed; + this.windDeg = windDeg; + this.windGust = windGust; + this.weather = weather; + this.rain = rain; + this.snow = snow; + } + + public Integer getDt() { + return dt; + } + + public Integer getSunrise() { + return sunrise; + } + + public Integer getSunset() { + return sunset; + } + + public Double getTemp() { + return temp; + } + + public Double getFeelsLike() { + return feelsLike; + } + + public Integer getPressure() { + return pressure; + } + + public Integer getHumidity() { + return humidity; + } + + public Double getDewPoint() { + return dewPoint; + } + + public Double getUvi() { + return uvi; + } + + public Integer getClouds() { + return clouds; + } + + public Integer getVisibility() { + return visibility; + } + + public Double getWindSpeed() { + return windSpeed; + } + + public Integer getWindDeg() { + return windDeg; + } + + public Double getWindGust() { + return windGust; + } + + public List getWeather() { + return weather; + } + + public Rain getRain() { + return rain; + } + + public Snow getSnow() { + return snow; + } + + @Override + public String toString() { + return "Current{" + + "dt=" + dt + + ", sunrise=" + sunrise + + ", sunset=" + sunset + + ", temp=" + temp + + ", feelsLike=" + feelsLike + + ", pressure=" + pressure + + ", humidity=" + humidity + + ", dewPoint=" + dewPoint + + ", uvi=" + uvi + + ", clouds=" + clouds + + ", visibility=" + visibility + + ", windSpeed=" + windSpeed + + ", windDeg=" + windDeg + + ", windGust=" + windGust + + ", weather=" + weather + + ", rain=" + rain + + ", snow=" + snow + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Daily.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Daily.java new file mode 100644 index 0000000..409369d --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Daily.java @@ -0,0 +1,175 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.common.Weather; + +import java.util.List; + +public class Daily { + + private Integer dt; + private Integer sunrise; + private Integer sunset; + private Integer moonrise; + private Integer moonset; + @JsonProperty("moon_phase") + private Double moonPhase; + private String summary; + private Temp temp; + @JsonProperty("feels_like") + private FeelsLike feelsLike; + private Integer pressure; + private Integer humidity; + @JsonProperty("dew_point") + private Double dewPoint; + @JsonProperty("wind_speed") + private Double windSpeed; + @JsonProperty("wind_deg") + private Integer windDeg; + @JsonProperty("wind_gust") + private Double windGust; + private List weather; + private Integer clouds; + private Double pop; + private Double rain; + private Double snow; + private Double uvi; + + public Daily() { + } + + public Daily(Integer dt, Integer sunrise, Integer sunset, Integer moonrise, Integer moonset, Double moonPhase, String summary, Temp temp, FeelsLike feelsLike, Integer pressure, Integer humidity, Double dewPoint, Double windSpeed, Integer windDeg, Double windGust, List weather, Integer clouds, Double pop, Double rain, Double snow, Double uvi) { + this.dt = dt; + this.sunrise = sunrise; + this.sunset = sunset; + this.moonrise = moonrise; + this.moonset = moonset; + this.moonPhase = moonPhase; + this.summary = summary; + this.temp = temp; + this.feelsLike = feelsLike; + this.pressure = pressure; + this.humidity = humidity; + this.dewPoint = dewPoint; + this.windSpeed = windSpeed; + this.windDeg = windDeg; + this.windGust = windGust; + this.weather = weather; + this.clouds = clouds; + this.pop = pop; + this.rain = rain; + this.snow = snow; + this.uvi = uvi; + } + + public Integer getDt() { + return dt; + } + + public Integer getSunrise() { + return sunrise; + } + + public Integer getSunset() { + return sunset; + } + + public Integer getMoonrise() { + return moonrise; + } + + public Integer getMoonset() { + return moonset; + } + + public Double getMoonPhase() { + return moonPhase; + } + + public String getSummary() { + return summary; + } + + public Temp getTemp() { + return temp; + } + + public FeelsLike getFeelsLike() { + return feelsLike; + } + + public Integer getPressure() { + return pressure; + } + + public Integer getHumidity() { + return humidity; + } + + public Double getDewPoint() { + return dewPoint; + } + + public Double getWindSpeed() { + return windSpeed; + } + + public Integer getWindDeg() { + return windDeg; + } + + public Double getWindGust() { + return windGust; + } + + public List getWeather() { + return weather; + } + + public Integer getClouds() { + return clouds; + } + + public Double getPop() { + return pop; + } + + public Double getRain() { + return rain; + } + + public Double getSnow() { + return snow; + } + + public Double getUvi() { + return uvi; + } + + @Override + public String toString() { + return "Daily{" + + "dt=" + dt + + ", sunrise=" + sunrise + + ", sunset=" + sunset + + ", moonrise=" + moonrise + + ", moonset=" + moonset + + ", moonPhase=" + moonPhase + + ", summary='" + summary + '\'' + + ", temp=" + temp + + ", feelsLike=" + feelsLike + + ", pressure=" + pressure + + ", humidity=" + humidity + + ", dewPoint=" + dewPoint + + ", windSpeed=" + windSpeed + + ", windDeg=" + windDeg + + ", windGust=" + windGust + + ", weather=" + weather + + ", clouds=" + clouds + + ", pop=" + pop + + ", rain=" + rain + + ", snow=" + snow + + ", uvi=" + uvi + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/FeelsLike.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/FeelsLike.java new file mode 100644 index 0000000..08250bc --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/FeelsLike.java @@ -0,0 +1,45 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +public class FeelsLike { + + private Double day; + private Double night; + private Double eve; + private Double morn; + + public FeelsLike() { + } + + public FeelsLike(Double day, Double night, Double eve, Double morn) { + this.day = day; + this.night = night; + this.eve = eve; + this.morn = morn; + } + + public Double getDay() { + return day; + } + + public Double getNight() { + return night; + } + + public Double getEve() { + return eve; + } + + public Double getMorn() { + return morn; + } + + @Override + public String toString() { + return "FeelsLike{" + + "day=" + day + + ", night=" + night + + ", eve=" + eve + + ", morn=" + morn + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Hourly.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Hourly.java new file mode 100644 index 0000000..816ab32 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Hourly.java @@ -0,0 +1,139 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.common.Weather; + +import java.util.List; + +public class Hourly { + + private Integer dt; + private Double temp; + @JsonProperty("feels_like") + private Double feelsLike; + private Integer pressure; + private Integer humidity; + @JsonProperty("dew_point") + private Double dewPoint; + private Double uvi; + private Integer clouds; + private Integer visibility; + @JsonProperty("wind_speed") + private Double windSpeed; + @JsonProperty("wind_deg") + private Integer windDeg; + @JsonProperty("wind_gust") + private Double windGust; + private List weather; + private Rain rain; + private Snow snow; + private Double pop; + + public Hourly() { + } + + public Hourly(Integer dt, Double temp, Double feelsLike, Integer pressure, Integer humidity, Double dewPoint, Double uvi, Integer clouds, Integer visibility, Double windSpeed, Integer windDeg, Double windGust, List weather, Rain rain, Snow snow, Double pop) { + this.dt = dt; + this.temp = temp; + this.feelsLike = feelsLike; + this.pressure = pressure; + this.humidity = humidity; + this.dewPoint = dewPoint; + this.uvi = uvi; + this.clouds = clouds; + this.visibility = visibility; + this.windSpeed = windSpeed; + this.windDeg = windDeg; + this.windGust = windGust; + this.weather = weather; + this.rain = rain; + this.snow = snow; + this.pop = pop; + } + + public Integer getDt() { + return dt; + } + + public Double getTemp() { + return temp; + } + + public Double getFeelsLike() { + return feelsLike; + } + + public Integer getPressure() { + return pressure; + } + + public Integer getHumidity() { + return humidity; + } + + public Double getDewPoint() { + return dewPoint; + } + + public Double getUvi() { + return uvi; + } + + public Integer getClouds() { + return clouds; + } + + public Integer getVisibility() { + return visibility; + } + + public Double getWindSpeed() { + return windSpeed; + } + + public Integer getWindDeg() { + return windDeg; + } + + public Double getWindGust() { + return windGust; + } + + public List getWeather() { + return weather; + } + + public Rain getRain() { + return rain; + } + + public Snow getSnow() { + return snow; + } + + public Double getPop() { + return pop; + } + + @Override + public String toString() { + return "Hourly{" + + "dt=" + dt + + ", temp=" + temp + + ", feelsLike=" + feelsLike + + ", pressure=" + pressure + + ", humidity=" + humidity + + ", dewPoint=" + dewPoint + + ", uvi=" + uvi + + ", clouds=" + clouds + + ", visibility=" + visibility + + ", windSpeed=" + windSpeed + + ", windDeg=" + windDeg + + ", windGust=" + windGust + + ", weather=" + weather + + ", rain=" + rain + + ", snow=" + snow + + ", pop=" + pop + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Minutely.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Minutely.java new file mode 100644 index 0000000..3e28f4c --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Minutely.java @@ -0,0 +1,31 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +public class Minutely { + + private Integer dt; + private Double precipitation; + + public Minutely() { + } + + public Minutely(Integer dt, Double precipitation) { + this.dt = dt; + this.precipitation = precipitation; + } + + public Integer getDt() { + return dt; + } + + public Double getPrecipitation() { + return precipitation; + } + + @Override + public String toString() { + return "Minutely{" + + "dt=" + dt + + ", precipitation=" + precipitation + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Rain.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Rain.java new file mode 100644 index 0000000..b00eb4a --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Rain.java @@ -0,0 +1,27 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Rain { + + @JsonProperty("1h") + private Double oneH; + + public Rain() { + } + + public Rain(Double oneH) { + this.oneH = oneH; + } + + public Double getOneH() { + return oneH; + } + + @Override + public String toString() { + return "Rain{" + + "oneH=" + oneH + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Snow.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Snow.java new file mode 100644 index 0000000..3c0f7dc --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Snow.java @@ -0,0 +1,27 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Snow { + + @JsonProperty("1h") + private Double oneH; + + public Snow() { + } + + public Snow(Double oneH) { + this.oneH = oneH; + } + + public Double getOneH() { + return oneH; + } + + @Override + public String toString() { + return "Snow{" + + "oneH=" + oneH + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Temp.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Temp.java new file mode 100644 index 0000000..e10e439 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/currentAndForecasts/Temp.java @@ -0,0 +1,59 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts; + +public class Temp { + + private Double day; + private Double min; + private Double max; + private Double night; + private Double eve; + private Double morn; + + public Temp() { + } + + public Temp(Double day, Double min, Double max, Double night, Double eve, Double morn) { + this.day = day; + this.min = min; + this.max = max; + this.night = night; + this.eve = eve; + this.morn = morn; + } + + public Double getDay() { + return day; + } + + public Double getMin() { + return min; + } + + public Double getMax() { + return max; + } + + public Double getNight() { + return night; + } + + public Double getEve() { + return eve; + } + + public Double getMorn() { + return morn; + } + + @Override + public String toString() { + return "Temp{" + + "day=" + day + + ", min=" + min + + ", max=" + max + + ", night=" + night + + ", eve=" + eve + + ", morn=" + morn + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/CloudCover.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/CloudCover.java new file mode 100644 index 0000000..a76750f --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/CloudCover.java @@ -0,0 +1,24 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary; + +public class CloudCover { + + private Integer afternoon; + + public CloudCover() { + } + + public CloudCover(Integer afternoon) { + this.afternoon = afternoon; + } + + public Integer getAfternoon() { + return afternoon; + } + + @Override + public String toString() { + return "CloudCover{" + + "afternoon=" + afternoon + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Humidity.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Humidity.java new file mode 100644 index 0000000..eb9954c --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Humidity.java @@ -0,0 +1,24 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary; + +public class Humidity { + + private Integer afternoon; + + public Humidity() { + } + + public Humidity(Integer afternoon) { + this.afternoon = afternoon; + } + + public Integer getAfternoon() { + return afternoon; + } + + @Override + public String toString() { + return "Humidity{" + + "afternoon=" + afternoon + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Precipitation.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Precipitation.java new file mode 100644 index 0000000..8fa2dc8 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Precipitation.java @@ -0,0 +1,24 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary; + +public class Precipitation { + + private Double total; + + public Precipitation() { + } + + public Precipitation(Double total) { + this.total = total; + } + + public Double getTotal() { + return total; + } + + @Override + public String toString() { + return "Precipitation{" + + "total=" + total + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Pressure.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Pressure.java new file mode 100644 index 0000000..7974b75 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Pressure.java @@ -0,0 +1,24 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary; + +public class Pressure { + + private Integer afternoon; + + public Pressure() { + } + + public Pressure(Integer afternoon) { + this.afternoon = afternoon; + } + + public Integer getAfternoon() { + return afternoon; + } + + @Override + public String toString() { + return "Pressure{" + + "afternoon=" + afternoon + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Temperature.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Temperature.java new file mode 100644 index 0000000..7c5bebb --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Temperature.java @@ -0,0 +1,59 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary; + +public class Temperature { + + private Double min; + private Double max; + private Double afternoon; + private Double night; + private Double evening; + private Double morning; + + public Temperature() { + } + + public Temperature(Double min, Double max, Double afternoon, Double night, Double evening, Double morning) { + this.min = min; + this.max = max; + this.afternoon = afternoon; + this.night = night; + this.evening = evening; + this.morning = morning; + } + + public Double getMin() { + return min; + } + + public Double getMax() { + return max; + } + + public Double getAfternoon() { + return afternoon; + } + + public Double getNight() { + return night; + } + + public Double getEvening() { + return evening; + } + + public Double getMorning() { + return morning; + } + + @Override + public String toString() { + return "Temperature{" + + "min=" + min + + ", max=" + max + + ", afternoon=" + afternoon + + ", night=" + night + + ", evening=" + evening + + ", morning=" + morning + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Wind.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Wind.java new file mode 100644 index 0000000..d528184 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/daySummary/Wind.java @@ -0,0 +1,54 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.daySummary; + +public class Wind { + + private Max max; + + public Wind() { + } + + public Wind(Max max) { + this.max = max; + } + + public Max getMax() { + return max; + } + + @Override + public String toString() { + return "Wind{" + + "max=" + max + + '}'; + } + + public static class Max { + + private Double speed; + private Integer direction; + + public Max() { + } + + public Max(Double speed, Integer direction) { + this.speed = speed; + this.direction = direction; + } + + public Double getSpeed() { + return speed; + } + + public Integer getDirection() { + return direction; + } + + @Override + public String toString() { + return "Max{" + + "speed=" + speed + + ", direction=" + direction + + '}'; + } + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/timemachine/Data.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/timemachine/Data.java new file mode 100644 index 0000000..0759c46 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/dto/oneCallApi/timemachine/Data.java @@ -0,0 +1,140 @@ +package io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.timemachine; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.mbenincasa.javaopenweathermapclient.dto.common.Weather; +import io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts.Rain; +import io.github.mbenincasa.javaopenweathermapclient.dto.oneCallApi.currentAndForecasts.Snow; + +import java.util.List; + +public class Data { + + private Integer dt; + private Integer sunrise; + private Integer sunset; + private Double temp; + @JsonProperty("feels_like") + private Double feelsLike; + private Integer pressure; + private Integer humidity; + @JsonProperty("dew_point") + private Double dewPoint; + private Double uvi; + private Integer clouds; + private Integer visibility; + @JsonProperty("wind_speed") + private Double windSpeed; + @JsonProperty("wind_deg") + private Integer windDeg; + private List weather; + private Rain rain; + private Snow snow; + + public Data() { + } + + public Data(Integer dt, Integer sunrise, Integer sunset, Double temp, Double feelsLike, Integer pressure, Integer humidity, Double dewPoint, Double uvi, Integer clouds, Integer visibility, Double windSpeed, Integer windDeg, List weather, Rain rain, Snow snow) { + this.dt = dt; + this.sunrise = sunrise; + this.sunset = sunset; + this.temp = temp; + this.feelsLike = feelsLike; + this.pressure = pressure; + this.humidity = humidity; + this.dewPoint = dewPoint; + this.uvi = uvi; + this.clouds = clouds; + this.visibility = visibility; + this.windSpeed = windSpeed; + this.windDeg = windDeg; + this.weather = weather; + this.rain = rain; + this.snow = snow; + } + + public Integer getDt() { + return dt; + } + + public Integer getSunrise() { + return sunrise; + } + + public Integer getSunset() { + return sunset; + } + + public Double getTemp() { + return temp; + } + + public Double getFeelsLike() { + return feelsLike; + } + + public Integer getPressure() { + return pressure; + } + + public Integer getHumidity() { + return humidity; + } + + public Double getDewPoint() { + return dewPoint; + } + + public Double getUvi() { + return uvi; + } + + public Integer getClouds() { + return clouds; + } + + public Integer getVisibility() { + return visibility; + } + + public Double getWindSpeed() { + return windSpeed; + } + + public Integer getWindDeg() { + return windDeg; + } + + public List getWeather() { + return weather; + } + + public Rain getRain() { + return rain; + } + + public Snow getSnow() { + return snow; + } + + @Override + public String toString() { + return "Data{" + + "dt=" + dt + + ", sunrise=" + sunrise + + ", sunset=" + sunset + + ", temp=" + temp + + ", feelsLike=" + feelsLike + + ", pressure=" + pressure + + ", humidity=" + humidity + + ", dewPoint=" + dewPoint + + ", uvi=" + uvi + + ", clouds=" + clouds + + ", visibility=" + visibility + + ", windSpeed=" + windSpeed + + ", windDeg=" + windDeg + + ", weather=" + weather + + ", rain=" + rain + + ", snow=" + snow + + '}'; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/request/oneCallApi/OneCallApiExclude.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/request/oneCallApi/OneCallApiExclude.java new file mode 100644 index 0000000..aa2adcc --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/request/oneCallApi/OneCallApiExclude.java @@ -0,0 +1,20 @@ +package io.github.mbenincasa.javaopenweathermapclient.request.oneCallApi; + +public enum OneCallApiExclude { + + CURRENT("current"), + MINUTELY("minutely"), + HOURLY("hourly"), + DAILY("daily"), + ALERTS("alerts"); + + private final String value; + + OneCallApiExclude(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/io/github/mbenincasa/javaopenweathermapclient/request/oneCallApi/OneCallApiRequest.java b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/request/oneCallApi/OneCallApiRequest.java new file mode 100644 index 0000000..125ee00 --- /dev/null +++ b/src/main/java/io/github/mbenincasa/javaopenweathermapclient/request/oneCallApi/OneCallApiRequest.java @@ -0,0 +1,175 @@ +package io.github.mbenincasa.javaopenweathermapclient.request.oneCallApi; + +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; +import io.github.mbenincasa.javaopenweathermapclient.utils.HttpRequestExecutor; +import io.github.mbenincasa.javarestclient.exception.RestClientException; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +public class OneCallApiRequest { + + private final String apiKey; + + public OneCallApiRequest(String apiKey) { + this.apiKey = apiKey; + } + + public BuilderCurrentAndForecast currentAndForecastsData(Double lat, Double lon) { + return new BuilderCurrentAndForecast(lat, lon, this.apiKey); + } + + public BuilderTimemachine timemachine(Double lat, Double lon, Integer dt) { + return new BuilderTimemachine(lat, lon, dt, this.apiKey); + } + + 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 query; + + private BuilderCurrentAndForecast(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 BuilderCurrentAndForecast exclude(OneCallApiExclude... excludes) { + var excludesFormatted = Arrays.stream(excludes) + .map(OneCallApiExclude::getValue) + .collect(Collectors.joining(",")); + this.query.put("exclude", excludesFormatted); + return this; + } + + public BuilderCurrentAndForecast units(Unit unit) { + this.query.put("units", unit.getValue()); + return this; + } + + public BuilderCurrentAndForecast lang(Lang lang) { + this.query.put("lang", lang.getValue()); + return this; + } + + public OneCallApiCurrentAndForecastsDataDTO response() throws RestClientException { + return HttpRequestExecutor.execute( + "https://api.openweathermap.org/data/3.0/onecall", + this.query, + OneCallApiCurrentAndForecastsDataDTO.class + ); + } + } + + public static class BuilderTimemachine { + + private final Map query; + + private BuilderTimemachine(Double lat, Double lon, Integer dt, String apiKey) { + this.query = new HashMap<>(); + this.query.put("appid", apiKey); + this.query.put("lat", lat); + this.query.put("lon", lon); + this.query.put("dt", dt); + } + + public BuilderTimemachine units(Unit unit) { + this.query.put("units", unit.getValue()); + return this; + } + + public BuilderTimemachine lang(Lang lang) { + this.query.put("lang", lang.getValue()); + return this; + } + + public OneCallApiTimemachineDTO response() throws RestClientException { + return HttpRequestExecutor.execute( + "https://api.openweathermap.org/data/3.0/onecall/timemachine", + this.query, + OneCallApiTimemachineDTO.class + ); + } + } + + public static class BuilderDailyAggregation { + + private final Map query; + + private BuilderDailyAggregation(Double lat, Double lon, Integer dt, String apiKey) { + this.query = new HashMap<>(); + this.query.put("appid", apiKey); + this.query.put("lat", lat); + this.query.put("lon", lon); + this.query.put("dt", dt); + } + + public BuilderDailyAggregation units(Unit unit) { + this.query.put("units", unit.getValue()); + return this; + } + + public BuilderDailyAggregation lang(Lang lang) { + this.query.put("lang", lang.getValue()); + return this; + } + + public BuilderDailyAggregation tz(String tz) { + this.query.put("tz", tz); + return this; + } + + public OneCallApiDaySummaryDTO response() throws RestClientException { + return HttpRequestExecutor.execute( + "https://api.openweathermap.org/data/3.0/onecall/day_summary", + this.query, + OneCallApiDaySummaryDTO.class + ); + } + } + + public static class BuilderOverview { + + private final Map 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 + ); + } + } +} diff --git a/src/test/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClientTest.java b/src/test/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClientTest.java index 77f8143..2226682 100644 --- a/src/test/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClientTest.java +++ b/src/test/java/io/github/mbenincasa/javaopenweathermapclient/client/DefaultOpenWeatherMapClientTest.java @@ -3,6 +3,7 @@ import io.github.mbenincasa.javaopenweathermapclient.exception.OpenWeatherMapException; import io.github.mbenincasa.javaopenweathermapclient.request.common.Lang; import io.github.mbenincasa.javaopenweathermapclient.request.common.Unit; +import io.github.mbenincasa.javaopenweathermapclient.request.oneCallApi.OneCallApiExclude; import io.github.mbenincasa.javaopenweathermapclient.request.weatherMaps.AdvancedMapLayer; import io.github.mbenincasa.javaopenweathermapclient.request.weatherMaps.BasicMapLayer; import io.github.mbenincasa.javarestclient.exception.RestClientException; @@ -421,6 +422,57 @@ public void testAdvancedWeatherMap() throws RestClientException { assertTrue(response.length > 0); } + @Test + public void testOneCallApiCurrentAndForecastsData() throws RestClientException { + var response = openWeatherMapClient.oneCallApi() + .currentAndForecastsData(45.5101617, 9.0894415) + .exclude(OneCallApiExclude.CURRENT, OneCallApiExclude.MINUTELY) + .lang(Lang.ITALIAN) + .units(Unit.IMPERIAL) + .response(); + + assertNotNull(response); + assertNotNull(response.getHourly()); + assertNotNull(response.getDaily()); + } + + @Test + public void testOneCallApiTimemachine() throws RestClientException { + var response = openWeatherMapClient.oneCallApi() + .timemachine(39.099724, -94.578331, 1643803200) + .lang(Lang.ITALIAN) + .units(Unit.IMPERIAL) + .response(); + + assertNotNull(response); + assertNotNull(response.getData()); + } + + @Test + public void testOneCallApiDaySummary() throws RestClientException { + var response = openWeatherMapClient.oneCallApi() + .daySummary(39.099724, -94.578331, 1643803200) + .tz("+01:00") + .lang(Lang.ITALIAN) + .units(Unit.IMPERIAL) + .response(); + + assertNotNull(response); + 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() @@ -450,4 +502,5 @@ public void testRequestNotFound() { assertThrows(OpenWeatherMapException.class, requestBuilder::response); } + }