mirror of
https://bitbucket.org/akapribot/owm-japis.git
synced 2025-04-24 14:57:11 -07:00
2.5.0.4 is here with bug-fixes and upload to Maven. :)
This commit is contained in:
parent
eac5eb95c2
commit
4a32d93012
14 changed files with 173 additions and 90 deletions
|
@ -1,4 +1,4 @@
|
||||||
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
22
README.md
22
README.md
|
@ -1,10 +1,10 @@
|
||||||
#OWM JAPIs
|
#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
|
##Downloads
|
||||||
Download the library's source and binaries from [OWM JAPIs Downloads][1].
|
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
|
##Versions
|
||||||
###2.5 (Compatible with OpenWeatherMap.org's API v2.5)
|
###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:**
|
**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
|
[6]: http://www.json.org/java/index.html
|
||||||
[7]: http://opensource.org/licenses/MIT
|
[7]: http://opensource.org/licenses/MIT
|
||||||
[8]: https://github.com/dvdme/forecastio-lib-java
|
[8]: https://github.com/dvdme/forecastio-lib-java
|
||||||
[9]: mailto:me@aksingh.net
|
[9]: mailto:me@aksingh.net
|
||||||
|
[10]: http://search.maven.org/#search%7Cga%7C1%7Cowm-japis
|
|
@ -6,14 +6,14 @@ sourceCompatibility = 1.5
|
||||||
|
|
||||||
group = 'net.aksingh'
|
group = 'net.aksingh'
|
||||||
archivesBaseName = "owm-japis"
|
archivesBaseName = "owm-japis"
|
||||||
version = '2.5.0.3'
|
version = '2.5.0.4'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -24,6 +24,8 @@ package net.aksingh.owmjapis;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Provides default behaviours and implementations for:
|
* Provides default behaviours and implementations for:
|
||||||
|
@ -40,7 +42,10 @@ public abstract class AbstractForecast extends AbstractResponse {
|
||||||
/*
|
/*
|
||||||
JSON Keys
|
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
|
Instance variables
|
||||||
|
@ -64,10 +69,6 @@ public abstract class AbstractForecast extends AbstractResponse {
|
||||||
AbstractForecast(JSONObject jsonObj) {
|
AbstractForecast(JSONObject jsonObj) {
|
||||||
super(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.message = (jsonObj != null) ? jsonObj.optDouble(JSON_MESSAGE, Double.NaN) : Double.NaN;
|
||||||
|
|
||||||
this.city = (jsonObj != null) ? new City(jsonObj.optJSONObject(JSON_CITY)) : null;
|
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
|
* @author Ashutosh Kumar Singh
|
||||||
*/
|
*/
|
||||||
public static class City {
|
public static class City implements Serializable {
|
||||||
private final String JSON_CITY_ID = "id";
|
private static final String JSON_CITY_ID = "id";
|
||||||
private final String JSON_CITY_NAME = "name";
|
private static final String JSON_CITY_NAME = "name";
|
||||||
private final String JSON_CITY_COUNTRY_CODE = "country";
|
private static final String JSON_CITY_COUNTRY_CODE = "country";
|
||||||
private final String JSON_CITY_POPULATION = "population";
|
private static final String JSON_CITY_POPULATION = "population";
|
||||||
private final String JSON_CITY_COORD = "coord";
|
private static final String JSON_CITY_COORD = "coord";
|
||||||
|
|
||||||
private final long cityID;
|
private final long cityID;
|
||||||
private final String cityName;
|
private final String cityName;
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -24,6 +24,8 @@ package net.aksingh.owmjapis;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Provides default behaviours and implementations for the response from OWM.org
|
* Provides default behaviours and implementations for the response from OWM.org
|
||||||
|
@ -33,7 +35,7 @@ import org.json.JSONObject;
|
||||||
* @version 2014/12/28
|
* @version 2014/12/28
|
||||||
* @since 2.5.0.3
|
* @since 2.5.0.3
|
||||||
*/
|
*/
|
||||||
abstract class AbstractResponse {
|
abstract class AbstractResponse implements Serializable {
|
||||||
/*
|
/*
|
||||||
Instance variables
|
Instance variables
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* 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.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -45,10 +46,12 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
/*
|
/*
|
||||||
JSON Keys
|
JSON Keys
|
||||||
*/
|
*/
|
||||||
final String JSON_CLOUDS = "clouds";
|
static final String JSON_CLOUDS = "clouds";
|
||||||
final String JSON_COORD = "coord";
|
static final String JSON_COORD = "coord";
|
||||||
final String JSON_MAIN = "main";
|
static final String JSON_MAIN = "main";
|
||||||
final String JSON_WIND = "wind";
|
static final String JSON_WIND = "wind";
|
||||||
|
private static final String JSON_WEATHER = "weather";
|
||||||
|
private static final String JSON_DATE_TIME = "dt";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Instance variables
|
Instance variables
|
||||||
|
@ -72,9 +75,6 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
AbstractWeather(JSONObject jsonObj) {
|
AbstractWeather(JSONObject jsonObj) {
|
||||||
super(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;
|
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
|
if (sec != Long.MIN_VALUE) { // converting seconds to Date object
|
||||||
/*
|
/*
|
||||||
|
@ -147,8 +147,8 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
* @version 2013/12/23
|
* @version 2013/12/23
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Clouds {
|
abstract public static class Clouds implements Serializable {
|
||||||
private final String JSON_CLOUDS_ALL = "all";
|
private static final String JSON_CLOUDS_ALL = "all";
|
||||||
|
|
||||||
private final float percentOfClouds;
|
private final float percentOfClouds;
|
||||||
|
|
||||||
|
@ -186,9 +186,9 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
* @version 2013/12/23
|
* @version 2013/12/23
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Coord {
|
abstract public static class Coord implements Serializable {
|
||||||
private final String JSON_COORD_LATITUDE = "lat";
|
private static final String JSON_COORD_LATITUDE = "lat";
|
||||||
private final String JSON_COORD_LONGITUDE = "lon";
|
private static final String JSON_COORD_LONGITUDE = "lon";
|
||||||
|
|
||||||
private final float lat;
|
private final float lat;
|
||||||
private final float lon;
|
private final float lon;
|
||||||
|
@ -245,13 +245,13 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
* @version 2013/12/23
|
* @version 2013/12/23
|
||||||
* @since 2.5.0.1
|
* @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 static final String JSON_MAIN_TEMP = "temp";
|
||||||
private final String JSON_MAIN_TEMP_MIN = "temp_min";
|
private static final String JSON_MAIN_TEMP_MIN = "temp_min";
|
||||||
private final String JSON_MAIN_TEMP_MAX = "temp_max";
|
private static final String JSON_MAIN_TEMP_MAX = "temp_max";
|
||||||
private final String JSON_MAIN_PRESSURE = "pressure";
|
private static final String JSON_MAIN_PRESSURE = "pressure";
|
||||||
private final String JSON_MAIN_HUMIDITY = "humidity";
|
private static final String JSON_MAIN_HUMIDITY = "humidity";
|
||||||
|
|
||||||
private final float temp;
|
private final float temp;
|
||||||
private final float minTemp;
|
private final float minTemp;
|
||||||
|
@ -376,11 +376,11 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
* @version 2014/12/27
|
* @version 2014/12/27
|
||||||
* @since 2.5.0.3
|
* @since 2.5.0.3
|
||||||
*/
|
*/
|
||||||
public static class Weather {
|
public static class Weather implements Serializable {
|
||||||
private final String JSON_WEATHER_ID = "id";
|
private static final String JSON_WEATHER_ID = "id";
|
||||||
private final String JSON_WEATHER_MAIN = "main";
|
private static final String JSON_WEATHER_MAIN = "main";
|
||||||
private final String JSON_WEATHER_DESCRIPTION = "description";
|
private static final String JSON_WEATHER_DESCRIPTION = "description";
|
||||||
private final String JSON_WEATHER_ICON = "icon";
|
private static final String JSON_WEATHER_ICON = "icon";
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -475,9 +475,9 @@ public abstract class AbstractWeather extends AbstractResponse {
|
||||||
* @version 2013/12/23
|
* @version 2013/12/23
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
abstract public static class Wind {
|
abstract public static class Wind implements Serializable {
|
||||||
private final String JSON_WIND_SPEED = "speed";
|
private static final String JSON_WIND_SPEED = "speed";
|
||||||
private final String JSON_WIND_DEGREE = "deg";
|
private static final String JSON_WIND_DEGREE = "deg";
|
||||||
|
|
||||||
private final float speed;
|
private final float speed;
|
||||||
private final float degree;
|
private final float degree;
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -24,6 +24,7 @@ package net.aksingh.owmjapis;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +49,15 @@ import java.util.Date;
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public class CurrentWeather extends AbstractWeather {
|
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
|
Instance variables
|
||||||
*/
|
*/
|
||||||
|
@ -68,12 +78,6 @@ public class CurrentWeather extends AbstractWeather {
|
||||||
CurrentWeather(JSONObject jsonObj) {
|
CurrentWeather(JSONObject jsonObj) {
|
||||||
super(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.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.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;
|
this.cityName = (jsonObj != null) ? jsonObj.optString(JSON_CITY_NAME, null) : null;
|
||||||
|
@ -336,9 +340,9 @@ public class CurrentWeather extends AbstractWeather {
|
||||||
* @version 2014/12/26
|
* @version 2014/12/26
|
||||||
* @since 2.5.0.1
|
* @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;
|
private final float rain1h;
|
||||||
|
|
||||||
|
@ -379,14 +383,14 @@ public class CurrentWeather extends AbstractWeather {
|
||||||
* @version 2014/12/26
|
* @version 2014/12/26
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public static class Sys {
|
public static class Sys implements Serializable {
|
||||||
|
|
||||||
private final String JSON_SYS_TYPE = "type";
|
private static final String JSON_SYS_TYPE = "type";
|
||||||
private final String JSON_SYS_ID = "id";
|
private static final String JSON_SYS_ID = "id";
|
||||||
private final String JSON_SYS_MESSAGE = "message";
|
private static final String JSON_SYS_MESSAGE = "message";
|
||||||
private final String JSON_SYS_COUNTRY_CODE = "country";
|
private static final String JSON_SYS_COUNTRY_CODE = "country";
|
||||||
private final String JSON_SYS_SUNRISE = "sunrise";
|
private static final String JSON_SYS_SUNRISE = "sunrise";
|
||||||
private final String JSON_SYS_SUNSET = "sunset";
|
private static final String JSON_SYS_SUNSET = "sunset";
|
||||||
|
|
||||||
private final int type;
|
private final int type;
|
||||||
private final int id;
|
private final int id;
|
||||||
|
@ -510,7 +514,7 @@ public class CurrentWeather extends AbstractWeather {
|
||||||
*/
|
*/
|
||||||
public static class Wind extends AbstractWeather.Wind {
|
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;
|
private final float gust;
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* 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.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -233,7 +234,7 @@ public class DailyForecast extends AbstractForecast {
|
||||||
* Others: <code>null</code>
|
* Others: <code>null</code>
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public static class Temperature {
|
public static class Temperature implements Serializable {
|
||||||
public final String JSON_TEMP_DAY = "day";
|
public final String JSON_TEMP_DAY = "day";
|
||||||
public final String JSON_TEMP_MIN = "min";
|
public final String JSON_TEMP_MIN = "min";
|
||||||
public final String JSON_TEMP_MAX = "max";
|
public final String JSON_TEMP_MAX = "max";
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* 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.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -321,7 +322,7 @@ public class HourlyForecast extends AbstractForecast {
|
||||||
* @version 2014/12/26
|
* @version 2014/12/26
|
||||||
* @since 2.5.0.1
|
* @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 JSON_SYS_POD = "pod";
|
||||||
private final String pod;
|
private final String pod;
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -38,7 +38,11 @@ import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <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.
|
* Henceforth, it's shortened as OWM.org to ease commenting.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -320,8 +324,8 @@ public class OpenWeatherMap {
|
||||||
* @since 2.5.0.3
|
* @since 2.5.0.3
|
||||||
*/
|
*/
|
||||||
public static class OWMAddress {
|
public static class OWMAddress {
|
||||||
private final String MODE = "json";
|
private static final String MODE = "json";
|
||||||
private final String ENCODING = "UTF-8";
|
private static final String ENCODING = "UTF-8";
|
||||||
|
|
||||||
private String mode;
|
private String mode;
|
||||||
private Units units;
|
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 {
|
public String hourlyForecastByCityName(String cityName) throws UnsupportedEncodingException {
|
||||||
String address = owmAddress.hourlyForecastByCityName(cityName);
|
String address = owmAddress.hourlyForecastByCityName(cityName);
|
||||||
|
@ -605,7 +609,7 @@ public class OpenWeatherMap {
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
|
|
||||||
String s;
|
String tmpStr;
|
||||||
String response = null;
|
String response = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -631,8 +635,8 @@ public class OpenWeatherMap {
|
||||||
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((s = reader.readLine()) != null) {
|
while ((tmpStr = reader.readLine()) != null) {
|
||||||
response = s;
|
response = tmpStr;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Error: " + e.getMessage());
|
System.err.println("Error: " + e.getMessage());
|
||||||
|
@ -648,8 +652,8 @@ public class OpenWeatherMap {
|
||||||
} else { // if HttpURLConnection is not okay
|
} else { // if HttpURLConnection is not okay
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
|
reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
|
||||||
while ((s = reader.readLine()) != null) {
|
while ((tmpStr = reader.readLine()) != null) {
|
||||||
response = s;
|
response = tmpStr;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Error: " + e.getMessage());
|
System.err.println("Error: " + e.getMessage());
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -30,19 +30,48 @@ import java.io.IOException;
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2014/12/27
|
* @version 2015/01/22
|
||||||
* @since 2.5.0.3
|
* @since 2.5.0.3
|
||||||
*/
|
*/
|
||||||
public class DailyForecastTest {
|
public class DailyForecastTest {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
OpenWeatherMap owm = new OpenWeatherMap("");
|
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!");
|
System.out.println("Reponse is inValid!");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Reponse is Valid!");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -30,19 +30,48 @@ import java.io.IOException;
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2014/12/27
|
* @version 2015/01/22
|
||||||
* @since 2.5.0.3
|
* @since 2.5.0.3
|
||||||
*/
|
*/
|
||||||
public class HourlyForecastTest {
|
public class HourlyForecastTest {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
OpenWeatherMap owm = new OpenWeatherMap("");
|
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!");
|
System.out.println("Reponse is inValid!");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Reponse is Valid!");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue