1
0
Fork 0
mirror of https://bitbucket.org/ethauvin/owm-japis.git synced 2025-04-26 02:07:11 -07:00

2.5.0.4 is here with bug-fixes and upload to Maven. :)

This commit is contained in:
Ashutosh Kumar Singh 2015-01-28 01:20:11 +05:30
parent eac5eb95c2
commit 4a32d93012
14 changed files with 173 additions and 90 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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;
/**
* <p>
* 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;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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;
/**
* <p>
* 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
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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: <code>null</code>
* </p>
*/
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";

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* 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;
/**
* <p>
* Lets you access data from OpenWeatherMap.org using its Web APIs.
* <b>The starting point for all API operations.</b>
* If you're new to this API, read the docs for this class first.
* </p>
* <p>
* Lets you access data from OpenWeatherMap.org using its Weather APIs.
* Henceforth, it's shortened as OWM.org to ease commenting.
* </p>
* <p>
@ -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());

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2014 Ashutosh Kumar Singh <me@aksingh.net>
* Copyright (c) 2013-2015 Ashutosh Kumar Singh <me@aksingh.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal