Skip to content

ColyTeam/weather-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WeatherAPI

An API wrapper for the openweathermap.org API

Installation

Download the jar file from the release page.

Maven

<repository>
    <id>coly</id>
    <url>https://m2.coly.dev/releases</url>
</repository>

<dependency>
    <groupId>dev.coly</groupId>
    <artifactId>weather-api</artifactId>
    <version>VERSION</version>
</dependency>

Usage

This project can only be used as a libary.

Create WeatherClient object with api key. This key can be obtained at home.openweathermap.org/api_keys using an account.

WeatherClient client = new WeatherClient(API_KEY);

Examples

CurrentWeather weather = client.getCurrentWeatherByCityName("Berlin", UnitType.Metric, "EN");
System.out.println("It is currently " + weather.getWeatherState().getTemperature() + "°C in " + weather.getStation().getName());
CurrentWeather weather = client.getCurrentWeatherByCoordinates(52.5, 13.4, UnitType.Metric, "EN");
System.out.println("It is currently " + weather.getWeatherState().getTemperature() + "°C in " + weather.getStation().getName());
ForecastWeather weather = client.getForecastWeatherByCityName("Berlin", UnitType.Metric, "EN");
System.out.println("There are " + weather.getWeatherStates().size() + " forecasts for " + weather.getStation().getName());