From 4a32d9301272d9d5837a82619def5016d2e8ff67 Mon Sep 17 00:00:00 2001 From: Ashutosh Kumar Singh Date: Wed, 28 Jan 2015 01:20:11 +0530 Subject: [PATCH] 2.5.0.4 is here with bug-fixes and upload to Maven. :) --- LICENSE.txt | 2 +- README.md | 22 ++++++-- build.gradle | 4 +- .../aksingh/owmjapis/AbstractForecast.java | 25 ++++----- .../aksingh/owmjapis/AbstractResponse.java | 6 ++- .../net/aksingh/owmjapis/AbstractWeather.java | 54 +++++++++---------- .../net/aksingh/owmjapis/CurrentWeather.java | 38 +++++++------ .../net/aksingh/owmjapis/DailyForecast.java | 5 +- .../net/aksingh/owmjapis/HourlyForecast.java | 5 +- .../net/aksingh/owmjapis/OpenWeatherMap.java | 24 +++++---- src/main/java/net/aksingh/owmjapis/Tools.java | 2 +- .../aksingh/owmjapis/CurrentWeatherTest.java | 2 +- .../aksingh/owmjapis/DailyForecastTest.java | 37 +++++++++++-- .../aksingh/owmjapis/HourlyForecastTest.java | 37 +++++++++++-- 14 files changed, 173 insertions(+), 90 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 743258e..24a127e 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013-2014 Ashutosh Kumar Singh +Copyright (c) 2013-2015 Ashutosh Kumar Singh Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a0ab0b5..c7ba62e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ #OWM JAPIs -####Java Wrapper Library for OpenWeatherMap.org Web APIs +####Java Library for OpenWeatherMap.org Weather APIs -Create weather-aware applications for **Java and Android platforms** in minimum time using OWM JAPIs, an easy-to-use, detailed and documented weather API library for retrieving weather data from OpenWeatherMap.org. You can easily **retrieve and use weather data** in your applications using this library. +Create weather-aware applications for **Java and Android platforms** in minimum time using OWM JAPIs, an easy-to-use, detailed and documented weather APIs wrapper library for retrieving weather data from OpenWeatherMap.org. You can easily **retrieve and use weather data** in your applications using this library. -OWM JAPIs lets you **get weather data in only 3-5 lines of code** (excluding any other/skeleton code, of course). You can develop applications for multiple platforms using this library, such as Windows, Mac OS X, Linux, and Android. +OWM JAPIs lets you **get weather data in only 3-5 lines of code** (excluding any other/skeleton code, of course). You can develop applications and services for multiple platforms using Java and this library, such as Windows, Mac OS X, Linux, and Android. @@ -20,13 +20,24 @@ OWM JAPIs lets you **focus just on your application's logic** and **weather retr ##Downloads Download the library's source and binaries from [OWM JAPIs Downloads][1]. +Use Maven, Gradle or an build tool? [OWM JAPIs is available in Maven Central repository][10]. + ##Versions ###2.5 (Compatible with OpenWeatherMap.org's API v2.5) -####2.5.0.3 (latest) +####2.5.0.4 (latest) + +**Bug-fix version:** + +1. Fixed lang parameter bug. +2. Library supports serialization and parcelization. +3. Uploaded the library to Maven Central repository. + + +####2.5.0.3 **Implemented:** @@ -231,4 +242,5 @@ Released under the terms of the [MIT license][7]. It's open source and developer [6]: http://www.json.org/java/index.html [7]: http://opensource.org/licenses/MIT [8]: https://github.com/dvdme/forecastio-lib-java - [9]: mailto:me@aksingh.net \ No newline at end of file + [9]: mailto:me@aksingh.net + [10]: http://search.maven.org/#search%7Cga%7C1%7Cowm-japis \ No newline at end of file diff --git a/build.gradle b/build.gradle index eb10d2c..a8b052e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,14 +6,14 @@ sourceCompatibility = 1.5 group = 'net.aksingh' archivesBaseName = "owm-japis" -version = '2.5.0.3' +version = '2.5.0.4' repositories { mavenCentral() } dependencies { - compile group: 'org.json', name: 'json', version: '20141113' + compile group: 'org.json', name: 'json', version: '20140107' testCompile group: 'junit', name: 'junit', version: '4.12' } diff --git a/src/main/java/net/aksingh/owmjapis/AbstractForecast.java b/src/main/java/net/aksingh/owmjapis/AbstractForecast.java index d9da4bf..228cf55 100644 --- a/src/main/java/net/aksingh/owmjapis/AbstractForecast.java +++ b/src/main/java/net/aksingh/owmjapis/AbstractForecast.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,8 @@ package net.aksingh.owmjapis; import org.json.JSONObject; +import java.io.Serializable; + /** *

* Provides default behaviours and implementations for: @@ -40,7 +42,10 @@ public abstract class AbstractForecast extends AbstractResponse { /* JSON Keys */ - final String JSON_FORECAST_LIST = "list"; + static final String JSON_FORECAST_LIST = "list"; + static final String JSON_MESSAGE = "message"; + static final String JSON_CITY = "city"; + static final String JSON_FORECAST_COUNT = "cnt"; /* Instance variables @@ -64,10 +69,6 @@ public abstract class AbstractForecast extends AbstractResponse { AbstractForecast(JSONObject jsonObj) { super(jsonObj); - final String JSON_MESSAGE = "message"; - final String JSON_CITY = "city"; - final String JSON_FORECAST_COUNT = "cnt"; - this.message = (jsonObj != null) ? jsonObj.optDouble(JSON_MESSAGE, Double.NaN) : Double.NaN; this.city = (jsonObj != null) ? new City(jsonObj.optJSONObject(JSON_CITY)) : null; @@ -124,12 +125,12 @@ public abstract class AbstractForecast extends AbstractResponse { * * @author Ashutosh Kumar Singh */ - public static class City { - private final String JSON_CITY_ID = "id"; - private final String JSON_CITY_NAME = "name"; - private final String JSON_CITY_COUNTRY_CODE = "country"; - private final String JSON_CITY_POPULATION = "population"; - private final String JSON_CITY_COORD = "coord"; + public static class City implements Serializable { + private static final String JSON_CITY_ID = "id"; + private static final String JSON_CITY_NAME = "name"; + private static final String JSON_CITY_COUNTRY_CODE = "country"; + private static final String JSON_CITY_POPULATION = "population"; + private static final String JSON_CITY_COORD = "coord"; private final long cityID; private final String cityName; diff --git a/src/main/java/net/aksingh/owmjapis/AbstractResponse.java b/src/main/java/net/aksingh/owmjapis/AbstractResponse.java index efa6e33..80d7764 100644 --- a/src/main/java/net/aksingh/owmjapis/AbstractResponse.java +++ b/src/main/java/net/aksingh/owmjapis/AbstractResponse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,8 @@ package net.aksingh.owmjapis; import org.json.JSONObject; +import java.io.Serializable; + /** *

* Provides default behaviours and implementations for the response from OWM.org @@ -33,7 +35,7 @@ import org.json.JSONObject; * @version 2014/12/28 * @since 2.5.0.3 */ -abstract class AbstractResponse { +abstract class AbstractResponse implements Serializable { /* Instance variables */ diff --git a/src/main/java/net/aksingh/owmjapis/AbstractWeather.java b/src/main/java/net/aksingh/owmjapis/AbstractWeather.java index f428867..ee9f497 100644 --- a/src/main/java/net/aksingh/owmjapis/AbstractWeather.java +++ b/src/main/java/net/aksingh/owmjapis/AbstractWeather.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,7 @@ package net.aksingh.owmjapis; import org.json.JSONArray; import org.json.JSONObject; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -45,10 +46,12 @@ public abstract class AbstractWeather extends AbstractResponse { /* JSON Keys */ - final String JSON_CLOUDS = "clouds"; - final String JSON_COORD = "coord"; - final String JSON_MAIN = "main"; - final String JSON_WIND = "wind"; + static final String JSON_CLOUDS = "clouds"; + static final String JSON_COORD = "coord"; + static final String JSON_MAIN = "main"; + static final String JSON_WIND = "wind"; + private static final String JSON_WEATHER = "weather"; + private static final String JSON_DATE_TIME = "dt"; /* Instance variables @@ -72,9 +75,6 @@ public abstract class AbstractWeather extends AbstractResponse { AbstractWeather(JSONObject jsonObj) { super(jsonObj); - final String JSON_WEATHER = "weather"; - final String JSON_DATE_TIME = "dt"; - long sec = (jsonObj != null) ? jsonObj.optLong(JSON_DATE_TIME, Long.MIN_VALUE) : Long.MIN_VALUE; if (sec != Long.MIN_VALUE) { // converting seconds to Date object /* @@ -147,8 +147,8 @@ public abstract class AbstractWeather extends AbstractResponse { * @version 2013/12/23 * @since 2.5.0.1 */ - abstract public static class Clouds { - private final String JSON_CLOUDS_ALL = "all"; + abstract public static class Clouds implements Serializable { + private static final String JSON_CLOUDS_ALL = "all"; private final float percentOfClouds; @@ -186,9 +186,9 @@ public abstract class AbstractWeather extends AbstractResponse { * @version 2013/12/23 * @since 2.5.0.1 */ - abstract public static class Coord { - private final String JSON_COORD_LATITUDE = "lat"; - private final String JSON_COORD_LONGITUDE = "lon"; + abstract public static class Coord implements Serializable { + private static final String JSON_COORD_LATITUDE = "lat"; + private static final String JSON_COORD_LONGITUDE = "lon"; private final float lat; private final float lon; @@ -245,13 +245,13 @@ public abstract class AbstractWeather extends AbstractResponse { * @version 2013/12/23 * @since 2.5.0.1 */ - abstract public static class Main { + abstract public static class Main implements Serializable { - private final String JSON_MAIN_TEMP = "temp"; - private final String JSON_MAIN_TEMP_MIN = "temp_min"; - private final String JSON_MAIN_TEMP_MAX = "temp_max"; - private final String JSON_MAIN_PRESSURE = "pressure"; - private final String JSON_MAIN_HUMIDITY = "humidity"; + private static final String JSON_MAIN_TEMP = "temp"; + private static final String JSON_MAIN_TEMP_MIN = "temp_min"; + private static final String JSON_MAIN_TEMP_MAX = "temp_max"; + private static final String JSON_MAIN_PRESSURE = "pressure"; + private static final String JSON_MAIN_HUMIDITY = "humidity"; private final float temp; private final float minTemp; @@ -376,11 +376,11 @@ public abstract class AbstractWeather extends AbstractResponse { * @version 2014/12/27 * @since 2.5.0.3 */ - public static class Weather { - private final String JSON_WEATHER_ID = "id"; - private final String JSON_WEATHER_MAIN = "main"; - private final String JSON_WEATHER_DESCRIPTION = "description"; - private final String JSON_WEATHER_ICON = "icon"; + public static class Weather implements Serializable { + private static final String JSON_WEATHER_ID = "id"; + private static final String JSON_WEATHER_MAIN = "main"; + private static final String JSON_WEATHER_DESCRIPTION = "description"; + private static final String JSON_WEATHER_ICON = "icon"; private final int id; private final String name; @@ -475,9 +475,9 @@ public abstract class AbstractWeather extends AbstractResponse { * @version 2013/12/23 * @since 2.5.0.1 */ - abstract public static class Wind { - private final String JSON_WIND_SPEED = "speed"; - private final String JSON_WIND_DEGREE = "deg"; + abstract public static class Wind implements Serializable { + private static final String JSON_WIND_SPEED = "speed"; + private static final String JSON_WIND_DEGREE = "deg"; private final float speed; private final float degree; diff --git a/src/main/java/net/aksingh/owmjapis/CurrentWeather.java b/src/main/java/net/aksingh/owmjapis/CurrentWeather.java index 3a3791a..09478f8 100644 --- a/src/main/java/net/aksingh/owmjapis/CurrentWeather.java +++ b/src/main/java/net/aksingh/owmjapis/CurrentWeather.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,7 @@ package net.aksingh.owmjapis; import org.json.JSONObject; +import java.io.Serializable; import java.util.Date; /** @@ -48,6 +49,15 @@ import java.util.Date; * @since 2.5.0.1 */ public class CurrentWeather extends AbstractWeather { + /* + JSON Keys + */ + private static final String JSON_RAIN = "rain"; + private static final String JSON_SYS = "sys"; + private static final String JSON_BASE = "base"; + private static final String JSON_CITY_ID = "id"; + private static final String JSON_CITY_NAME = "name"; + /* Instance variables */ @@ -68,12 +78,6 @@ public class CurrentWeather extends AbstractWeather { CurrentWeather(JSONObject jsonObj) { super(jsonObj); - final String JSON_RAIN = "rain"; - final String JSON_SYS = "sys"; - final String JSON_BASE = "base"; - final String JSON_CITY_ID = "id"; - final String JSON_CITY_NAME = "name"; - this.base = (jsonObj != null) ? jsonObj.optString(JSON_BASE, null) : null; this.cityId = (jsonObj != null) ? jsonObj.optLong(JSON_CITY_ID, Long.MIN_VALUE) : Long.MIN_VALUE; this.cityName = (jsonObj != null) ? jsonObj.optString(JSON_CITY_NAME, null) : null; @@ -336,9 +340,9 @@ public class CurrentWeather extends AbstractWeather { * @version 2014/12/26 * @since 2.5.0.1 */ - public static class Rain { + public static class Rain implements Serializable { - private final String JSON_RAIN_1HOUR = "1h"; + private static final String JSON_RAIN_1HOUR = "1h"; private final float rain1h; @@ -379,14 +383,14 @@ public class CurrentWeather extends AbstractWeather { * @version 2014/12/26 * @since 2.5.0.1 */ - public static class Sys { + public static class Sys implements Serializable { - private final String JSON_SYS_TYPE = "type"; - private final String JSON_SYS_ID = "id"; - private final String JSON_SYS_MESSAGE = "message"; - private final String JSON_SYS_COUNTRY_CODE = "country"; - private final String JSON_SYS_SUNRISE = "sunrise"; - private final String JSON_SYS_SUNSET = "sunset"; + private static final String JSON_SYS_TYPE = "type"; + private static final String JSON_SYS_ID = "id"; + private static final String JSON_SYS_MESSAGE = "message"; + private static final String JSON_SYS_COUNTRY_CODE = "country"; + private static final String JSON_SYS_SUNRISE = "sunrise"; + private static final String JSON_SYS_SUNSET = "sunset"; private final int type; private final int id; @@ -510,7 +514,7 @@ public class CurrentWeather extends AbstractWeather { */ public static class Wind extends AbstractWeather.Wind { - private final String JSON_WIND_GUST = "gust"; + private static final String JSON_WIND_GUST = "gust"; private final float gust; diff --git a/src/main/java/net/aksingh/owmjapis/DailyForecast.java b/src/main/java/net/aksingh/owmjapis/DailyForecast.java index 788e873..2450e26 100644 --- a/src/main/java/net/aksingh/owmjapis/DailyForecast.java +++ b/src/main/java/net/aksingh/owmjapis/DailyForecast.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,7 @@ package net.aksingh.owmjapis; import org.json.JSONArray; import org.json.JSONObject; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -233,7 +234,7 @@ public class DailyForecast extends AbstractForecast { * Others: null *

*/ - public static class Temperature { + public static class Temperature implements Serializable { public final String JSON_TEMP_DAY = "day"; public final String JSON_TEMP_MIN = "min"; public final String JSON_TEMP_MAX = "max"; diff --git a/src/main/java/net/aksingh/owmjapis/HourlyForecast.java b/src/main/java/net/aksingh/owmjapis/HourlyForecast.java index 98915db..9503957 100644 --- a/src/main/java/net/aksingh/owmjapis/HourlyForecast.java +++ b/src/main/java/net/aksingh/owmjapis/HourlyForecast.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,6 +25,7 @@ package net.aksingh.owmjapis; import org.json.JSONArray; import org.json.JSONObject; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -321,7 +322,7 @@ public class HourlyForecast extends AbstractForecast { * @version 2014/12/26 * @since 2.5.0.1 */ - public static class Sys { + public static class Sys implements Serializable { private final String JSON_SYS_POD = "pod"; private final String pod; diff --git a/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java b/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java index fe547fc..4032a2e 100644 --- a/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java +++ b/src/main/java/net/aksingh/owmjapis/OpenWeatherMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,7 +38,11 @@ import java.util.zip.InflaterInputStream; /** *

- * Lets you access data from OpenWeatherMap.org using its Web APIs. + * The starting point for all API operations. + * If you're new to this API, read the docs for this class first. + *

+ *

+ * Lets you access data from OpenWeatherMap.org using its Weather APIs. * Henceforth, it's shortened as OWM.org to ease commenting. *

*

@@ -320,8 +324,8 @@ public class OpenWeatherMap { * @since 2.5.0.3 */ public static class OWMAddress { - private final String MODE = "json"; - private final String ENCODING = "UTF-8"; + private static final String MODE = "json"; + private static final String ENCODING = "UTF-8"; private String mode; private Units units; @@ -548,7 +552,7 @@ public class OpenWeatherMap { } /* - Responses for daily forecasts + Responses for hourly forecasts */ public String hourlyForecastByCityName(String cityName) throws UnsupportedEncodingException { String address = owmAddress.hourlyForecastByCityName(cityName); @@ -605,7 +609,7 @@ public class OpenWeatherMap { HttpURLConnection connection = null; BufferedReader reader = null; - String s; + String tmpStr; String response = null; try { @@ -631,8 +635,8 @@ public class OpenWeatherMap { reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); } - while ((s = reader.readLine()) != null) { - response = s; + while ((tmpStr = reader.readLine()) != null) { + response = tmpStr; } } catch (IOException e) { System.err.println("Error: " + e.getMessage()); @@ -648,8 +652,8 @@ public class OpenWeatherMap { } else { // if HttpURLConnection is not okay try { reader = new BufferedReader(new InputStreamReader(connection.getErrorStream())); - while ((s = reader.readLine()) != null) { - response = s; + while ((tmpStr = reader.readLine()) != null) { + response = tmpStr; } } catch (IOException e) { System.err.println("Error: " + e.getMessage()); diff --git a/src/main/java/net/aksingh/owmjapis/Tools.java b/src/main/java/net/aksingh/owmjapis/Tools.java index 9800b2d..dc5430e 100644 --- a/src/main/java/net/aksingh/owmjapis/Tools.java +++ b/src/main/java/net/aksingh/owmjapis/Tools.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java b/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java index ea4d04e..b08ee11 100644 --- a/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java +++ b/src/test/java/net/aksingh/owmjapis/CurrentWeatherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/src/test/java/net/aksingh/owmjapis/DailyForecastTest.java b/src/test/java/net/aksingh/owmjapis/DailyForecastTest.java index 4ab63f1..acacdb6 100644 --- a/src/test/java/net/aksingh/owmjapis/DailyForecastTest.java +++ b/src/test/java/net/aksingh/owmjapis/DailyForecastTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,19 +30,48 @@ import java.io.IOException; *

* * @author Ashutosh Kumar Singh - * @version 2014/12/27 + * @version 2015/01/22 * @since 2.5.0.3 */ public class DailyForecastTest { public static void main(String[] args) throws IOException { OpenWeatherMap owm = new OpenWeatherMap(""); - DailyForecast dailyForecast = owm.dailyForecastByCityName("London, UK", Byte.parseByte("5")); + DailyForecast df = owm.dailyForecastByCityName("London, UK", Byte.parseByte("5")); - if (!dailyForecast.isValid()) { + if (!df.isValid()) { System.out.println("Reponse is inValid!"); } else { System.out.println("Reponse is Valid!"); + System.out.println(); + + if (df.hasCityInstance()) { + DailyForecast.City city = df.getCityInstance(); + if (city.hasCityName()) { + if (city.hasCityCode()) { + System.out.println("City code: " + city.getCityCode()); + } + if (city.hasCityName()) { + System.out.println("City name: " + city.getCityName()); + } + System.out.println(); + } + } + + System.out.println("Total forecast instances: " + df.getForecastCount()); + System.out.println(); + + for (int i = 0; i < df.getForecastCount(); i++) { + DailyForecast.Forecast forecast = df.getForecastInstance(i); + + System.out.println("*** Forecast instance number " + (i+1) + " ***"); + + if (forecast.hasDateTime()) { + System.out.println(forecast.getDateTime()); + } + + System.out.println(); + } } } } diff --git a/src/test/java/net/aksingh/owmjapis/HourlyForecastTest.java b/src/test/java/net/aksingh/owmjapis/HourlyForecastTest.java index 0400536..c9539ff 100644 --- a/src/test/java/net/aksingh/owmjapis/HourlyForecastTest.java +++ b/src/test/java/net/aksingh/owmjapis/HourlyForecastTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Ashutosh Kumar Singh + * Copyright (c) 2013-2015 Ashutosh Kumar Singh * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,19 +30,48 @@ import java.io.IOException; *

* * @author Ashutosh Kumar Singh - * @version 2014/12/27 + * @version 2015/01/22 * @since 2.5.0.3 */ public class HourlyForecastTest { public static void main(String[] args) throws IOException { OpenWeatherMap owm = new OpenWeatherMap(""); - HourlyForecast hourlyForecast = owm.hourlyForecastByCityName("London, UK"); + HourlyForecast hf = owm.hourlyForecastByCityName("London, UK"); - if (!hourlyForecast.isValid()) { + if (!hf.isValid()) { System.out.println("Reponse is inValid!"); } else { System.out.println("Reponse is Valid!"); + System.out.println(); + + if (hf.hasCityInstance()) { + HourlyForecast.City city = hf.getCityInstance(); + if (city.hasCityName()) { + if (city.hasCityCode()) { + System.out.println("City code: " + city.getCityCode()); + } + if (city.hasCityName()) { + System.out.println("City name: " + city.getCityName()); + } + System.out.println(); + } + } + + System.out.println("Total forecast instances: " + hf.getForecastCount()); + System.out.println(); + + for (int i = 0; i < hf.getForecastCount(); i++) { + HourlyForecast.Forecast forecast = hf.getForecastInstance(i); + + System.out.println("*** Forecast instance number " + (i+1) + " ***"); + + if (forecast.hasDateTime()) { + System.out.println(forecast.getDateTime()); + } + + System.out.println(); + } } } }