Open-Weather-API-Wrapper
Open Weather API Wrapper is an Android wrapper for the APIs of https://openweathermap.org. This library handles all the network operations and parameter validations on behalf of the developer.
Dependency:
- Add below lines to
app/build.gradle
file of your project.
dependencies {
compile 'com.kevalpatel2106:open-weather-wrapper:1.0'
}
How to use this library?:
- Initialization:
Initialize the library in your launch activity by providing the open weather api key and the unit system you want to use throughout the application. If you don't have the open weather api key, you can generate it from here.
OpenWeatherApi.initialize("YOUR API KEY", Unit.STANDARD);
- Accessing the API:
Open weather api provides you functions to access below information:
- Get current weather for provided city, geo point or postal code.
- Get three hourly forecast for city or, geo point.
- Get the daily forecast for provided city or geo point.
You can get the required information by passing the required parameters. The information will be received in specific listeners.
Here is the example of getting the three hourly forecast of the weather by city name.
OpenWeatherApi.getThreeHoursForecast("Landon,uk", new ForecastListener() {
@Override
public void onResponse(WeatherForecast weatherForecasts) {
//Forecast received.
//Do someting
}
@Override
public void onError(String message) {
//Something went wrong.
//Display the error message to the user.
}
});
Open Weather API Wrapper uses RxJava and Retrofit to handle the network operations.
Demo:
- You can download the sample application from here.
Contribute:
- Still there are many open weather apis to implement. Any pull request are most welcome. Simple 3 step to contribute into this repo:
- Fork the project.
- Make required changes and commit.
- Generate pull request. Mention all the required description regarding changes you made.
Questions:
License
Copyright 2017 Keval Patel
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.