This is an android library to get the weather forecaset from OpenWeather using their OneCall API.
To get the library into your build:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.DimitrisKaltzidis:Open-Weather-One-Call-API:Version'
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.DimitrisKaltzidis</groupId>
<artifactId>Open-Weather-One-Call-API</artifactId>
<version>Version</version>
</dependency>
Replace the Version in the code above with the latest. Latest version:
Make sure you registered and got your API key from openweathermap.
Create the client with your api key from openweathermap.
OneCallApiClient oneCallApiClient = new OneCallApiClient("YOUR_API_KEY_HERE");
Use the OneCallApiRequest.Builder class to build your request. The builder constructor requires the latitude and longitude of the location of your interest.
OneCallApiRequest oneCallApiRequest = new OneCallApiRequest.Builder(37.971580, 23.726766)
.unit(MeasurementUnit.metric)
.lang(Language.el)
.exlude(WeatherPart.minutely)
.exlude(WeatherPart.daily)
.build();
The builder contains methods to tailor the request to your needs such as:
unit()
to configure the units the results will be in.
Possible values are: standard, metric, imperial
lang()
to configure the lang the results will be in.
For a list of possible values check this doc: Multilingual support
exlude()
to configure the excluded Weather parts from the results.
Possible values are: current, minutely, hourly, daily, alerts
Make sure you don't exclude the same Weather part twice.
The final step to get your result is to call the makeOneCallApiRequest
method of the OneCallApiClient
.
The result of the call will be available using the OnWeatherResponseReceivedListener
.
Feel free to implement the interface and get your Weather response. The OnWeatherResponseReceivedListener
contains two methods the onSuccessfulResponse
where you can find the response
if the call to retrieve the
forecast was successful and the onFailedResponse
if the call failed. Hopefully the Throwable t
will give you
an idea regarding what went wrong 😊.
oneCallApiClient.makeOneCallApiRequest(oneCallApiRequest, new OnWeatherResponseReceivedListener() {
@Override
public void onSuccessfulResponse(OneCallApiResponse response) {
// Feel free to use the response as you like.
}
@Override
public void onFailedResponse(Throwable t) {
// The call failed the throwable will contain information regarding what went wrong.
}
});
Feel free to use this library as you like. You can find additional information regarding the OneCallAPI here