mirror of
https://bitbucket.org/ethauvin/owm-japis.git
synced 2025-04-25 09:47:11 -07:00
License changed to default MIT and replaced net.aksingh.java.api.owm.Tools.HTML.strictAddress() with java.net.URLEncoder()
This commit is contained in:
parent
5003871bff
commit
b5fca648fe
7 changed files with 334 additions and 378 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
lib/nblibraries.properties
|
||||||
|
nbproject/
|
||||||
|
lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
|
||||||
|
/build/
|
||||||
|
build.xml
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C)2013 Ashutosh Kumar Singh [me@AKSingh.net]
|
* Copyright (C)2013-2014 Ashutosh Kumar Singh [me@AKSingh.net]
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the "Software"),
|
* a copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
* The above copyright notice and this permission notice shall be included
|
* The above copyright notice and this permission notice shall be included
|
||||||
* in all copies or substantial portions of the Software.
|
* in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* The Software shall be used for Good, not Evil.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C)2013 Ashutosh Kumar Singh [me@AKSingh.net]
|
* Copyright (C)2013-2014 Ashutosh Kumar Singh [me@AKSingh.net]
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the "Software"),
|
* a copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
* The above copyright notice and this permission notice shall be included
|
* The above copyright notice and this permission notice shall be included
|
||||||
* in all copies or substantial portions of the Software.
|
* in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* The Software shall be used for Good, not Evil.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C)2013 Ashutosh Kumar Singh [me@AKSingh.net]
|
* Copyright (C)2013-2014 Ashutosh Kumar Singh [me@AKSingh.net]
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the "Software"),
|
* a copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
* The above copyright notice and this permission notice shall be included
|
* The above copyright notice and this permission notice shall be included
|
||||||
* in all copies or substantial portions of the Software.
|
* in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* The Software shall be used for Good, not Evil.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C)2013 Ashutosh Kumar Singh [me@AKSingh.net]
|
* Copyright (C)2013-2014 Ashutosh Kumar Singh [me@AKSingh.net]
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the "Software"),
|
* a copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
* The above copyright notice and this permission notice shall be included
|
* The above copyright notice and this permission notice shall be included
|
||||||
* in all copies or substantial portions of the Software.
|
* in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* The Software shall be used for Good, not Evil.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C)2013 Ashutosh Kumar Singh [me@AKSingh.net]
|
* Copyright (C)2013-2014 Ashutosh Kumar Singh [me@AKSingh.net]
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the "Software"),
|
* a copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
* The above copyright notice and this permission notice shall be included
|
* The above copyright notice and this permission notice shall be included
|
||||||
* in all copies or substantial portions of the Software.
|
* in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* The Software shall be used for Good, not Evil.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
@ -25,6 +23,7 @@ package net.aksingh.java.api.owm;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@ -41,32 +40,26 @@ public class OpenWeatherMap {
|
||||||
public static enum OWM_URL {
|
public static enum OWM_URL {
|
||||||
// Base URL for OpenWeatherMap.org API 2.5
|
// Base URL for OpenWeatherMap.org API 2.5
|
||||||
|
|
||||||
BASE_URL ("http://api.openweathermap.org/data/2.5/"),
|
BASE_URL("http://api.openweathermap.org/data/2.5/"),
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
|
|
||||||
PARAMETER_CURRENT_WEATHER ("weather?"),
|
PARAMETER_CURRENT_WEATHER("weather?"),
|
||||||
PARAMETER_FORECAST_WEATHER ("forecast?"),
|
PARAMETER_FORECAST_WEATHER("forecast?"),
|
||||||
PARAMETER_DAILY_FORECAST ("forecast/daily?"),
|
PARAMETER_DAILY_FORECAST("forecast/daily?"),
|
||||||
PARAMETER_SEARCH_CITY ("find?"),
|
PARAMETER_SEARCH_CITY("find?"),
|
||||||
|
PARAMETER_COUNT("cnt="),
|
||||||
PARAMETER_COUNT ("cnt="),
|
PARAMETER_CITY_NAME("q="),
|
||||||
|
PARAMETER_CITY_ID("id="),
|
||||||
PARAMETER_CITY_NAME ("q="),
|
PARAMETER_LATITUDE("lat="),
|
||||||
PARAMETER_CITY_ID ("id="),
|
PARAMETER_LONGITUDE("lon="),
|
||||||
PARAMETER_LATITUDE ("lat="),
|
PARAMETER_MODE("mode="),
|
||||||
PARAMETER_LONGITUDE ("lon="),
|
PARAMETER_UNITS("units="),
|
||||||
|
PARAMETER_APPID("APPID="),
|
||||||
PARAMETER_MODE ("mode="),
|
|
||||||
PARAMETER_UNITS ("units="),
|
|
||||||
PARAMETER_APPID ("APPID="),
|
|
||||||
|
|
||||||
// Possible values of parameters
|
// Possible values of parameters
|
||||||
|
|
||||||
PARAMETER_MODE_VALUE_JSON ("json"),
|
PARAMETER_MODE_VALUE_JSON("json"),
|
||||||
PARAMETER_UNITS_VALUE_IMPERIAL ("imperial"),
|
PARAMETER_UNITS_VALUE_IMPERIAL("imperial"),
|
||||||
PARAMETER_UNITS_VALUE_METRIC ("metric");
|
PARAMETER_UNITS_VALUE_METRIC("metric");
|
||||||
|
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
@ -76,15 +69,16 @@ public class OpenWeatherMap {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parameter.
|
* Returns the parameter.
|
||||||
|
*
|
||||||
* @return Parameter
|
* @return Parameter
|
||||||
*/
|
*/
|
||||||
public String getParameter() {
|
public String getParameter() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class OWM_Response {
|
public static class OWM_Response {
|
||||||
|
|
||||||
private final String OWM_MODE_VALUE;
|
private final String OWM_MODE_VALUE;
|
||||||
private final String OWM_UNITS_VALUE;
|
private final String OWM_UNITS_VALUE;
|
||||||
private final String OWM_APPID_VALUE;
|
private final String OWM_APPID_VALUE;
|
||||||
|
@ -101,279 +95,278 @@ public class OpenWeatherMap {
|
||||||
|
|
||||||
public String currentWeatherByCityName(String cityName)
|
public String currentWeatherByCityName(String cityName)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
String address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_NAME.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
Tools.HTML.strictAddress(cityName) + "&" +
|
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String currentWeatherByCityName(String cityName, String countryCode)
|
public String currentWeatherByCityName(String cityName, String countryCode)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_NAME.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
Tools.HTML.strictAddress(cityName) +
|
+ URLEncoder.encode(cityName, "US-ASCII")
|
||||||
"," + countryCode + "&" +
|
+ "," + countryCode + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String currentWeatherByCityCode(long cityCode)
|
public String currentWeatherByCityCode(long cityCode)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_ID.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
||||||
Long.toString(cityCode) + "&" +
|
+ Long.toString(cityCode) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String currentWeatherByCoordinates(float latitude, float longitude)
|
public String currentWeatherByCoordinates(float latitude, float longitude)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_CURRENT_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_LATITUDE.getParameter() +
|
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
||||||
Float.toString(latitude) + "&" +
|
+ Float.toString(latitude) + "&"
|
||||||
OWM_URL.PARAMETER_LONGITUDE.getParameter() +
|
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
||||||
Float.toString(longitude) + "&" +
|
+ Float.toString(longitude) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String forecastWeatherByCityName(String cityName)
|
public String forecastWeatherByCityName(String cityName)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_NAME.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
Tools.HTML.strictAddress(cityName) + "&" +
|
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String forecastWeatherByCityName(String cityName, String countryCode)
|
public String forecastWeatherByCityName(String cityName, String countryCode)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_NAME.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
Tools.HTML.strictAddress(cityName) +
|
+ URLEncoder.encode(cityName, "US-ASCII")
|
||||||
"," + countryCode + "&" +
|
+ "," + countryCode + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String forecastWeatherByCityCode(long cityCode)
|
public String forecastWeatherByCityCode(long cityCode)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_ID.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
||||||
Long.toString(cityCode) + "&" +
|
+ Long.toString(cityCode) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String forecastWeatherByCoordinates(float latitude, float longitude)
|
public String forecastWeatherByCoordinates(float latitude, float longitude)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter() +
|
+ OWM_URL.PARAMETER_FORECAST_WEATHER.getParameter()
|
||||||
OWM_URL.PARAMETER_LATITUDE.getParameter() +
|
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
||||||
Float.toString(latitude) + "&" +
|
+ Float.toString(latitude) + "&"
|
||||||
OWM_URL.PARAMETER_LONGITUDE.getParameter() +
|
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
||||||
Float.toString(longitude) + "&" +
|
+ Float.toString(longitude) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dailyForecastByCityName(String cityName, byte count)
|
public String dailyForecastByCityName(String cityName, byte count)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_DAILY_FORECAST.getParameter() +
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_NAME.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
Tools.HTML.strictAddress(cityName) + "&" +
|
+ URLEncoder.encode(cityName, "US-ASCII") + "&"
|
||||||
OWM_URL.PARAMETER_COUNT.getParameter() +
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
Byte.toString(count) + "&" +
|
+ Byte.toString(count) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dailyForecastByCityName(String cityName, String countryCode, byte count)
|
public String dailyForecastByCityName(String cityName, String countryCode, byte count)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_DAILY_FORECAST.getParameter() +
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_NAME.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_NAME.getParameter()
|
||||||
Tools.HTML.strictAddress(cityName) +
|
+ URLEncoder.encode(cityName, "US-ASCII")
|
||||||
"," + countryCode + "&" +
|
+ "," + countryCode + "&"
|
||||||
OWM_URL.PARAMETER_COUNT.getParameter() +
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
Byte.toString(count) + "&" +
|
+ Byte.toString(count) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dailyForecastByCityCode(long cityCode, byte count)
|
public String dailyForecastByCityCode(long cityCode, byte count)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_DAILY_FORECAST.getParameter() +
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
OWM_URL.PARAMETER_CITY_ID.getParameter() +
|
+ OWM_URL.PARAMETER_CITY_ID.getParameter()
|
||||||
Long.toString(cityCode) + "&" +
|
+ Long.toString(cityCode) + "&"
|
||||||
OWM_URL.PARAMETER_COUNT.getParameter() +
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
Byte.toString(count) + "&" +
|
+ Byte.toString(count) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String dailyForecastByCoordinates(float latitude, float longitude, byte count)
|
public String dailyForecastByCoordinates(float latitude, float longitude, byte count)
|
||||||
throws MalformedURLException, IOException {
|
throws MalformedURLException, IOException {
|
||||||
String url;
|
String address;
|
||||||
String response;
|
String response;
|
||||||
|
|
||||||
url = OWM_URL.BASE_URL.getParameter() +
|
address = OWM_URL.BASE_URL.getParameter()
|
||||||
OWM_URL.PARAMETER_DAILY_FORECAST.getParameter() +
|
+ OWM_URL.PARAMETER_DAILY_FORECAST.getParameter()
|
||||||
OWM_URL.PARAMETER_LATITUDE.getParameter() +
|
+ OWM_URL.PARAMETER_LATITUDE.getParameter()
|
||||||
Float.toString(latitude) + "&" +
|
+ Float.toString(latitude) + "&"
|
||||||
OWM_URL.PARAMETER_COUNT.getParameter() +
|
+ OWM_URL.PARAMETER_COUNT.getParameter()
|
||||||
Byte.toString(count) + "&" +
|
+ Byte.toString(count) + "&"
|
||||||
OWM_URL.PARAMETER_LONGITUDE.getParameter() +
|
+ OWM_URL.PARAMETER_LONGITUDE.getParameter()
|
||||||
Float.toString(longitude) + "&" +
|
+ Float.toString(longitude) + "&"
|
||||||
OWM_URL.PARAMETER_MODE.getParameter() +
|
+ OWM_URL.PARAMETER_MODE.getParameter()
|
||||||
this.OWM_MODE_VALUE + "&" +
|
+ this.OWM_MODE_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_UNITS.getParameter() +
|
+ OWM_URL.PARAMETER_UNITS.getParameter()
|
||||||
this.OWM_UNITS_VALUE + "&" +
|
+ this.OWM_UNITS_VALUE + "&"
|
||||||
OWM_URL.PARAMETER_APPID.getParameter() +
|
+ OWM_URL.PARAMETER_APPID.getParameter()
|
||||||
this.OWM_APPID_VALUE;
|
+ this.OWM_APPID_VALUE;
|
||||||
|
|
||||||
response = Tools.Downloader.downloadPage(url);
|
response = Tools.Downloader.downloadPage(address);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/***********************
|
* *********************
|
||||||
* Declaring this class
|
* Declaring this class
|
||||||
***********************/
|
**********************
|
||||||
|
*/
|
||||||
private final OWM_Response owmResponse;
|
private final OWM_Response owmResponse;
|
||||||
|
|
||||||
public OpenWeatherMap(String apiKey) {
|
public OpenWeatherMap(String apiKey) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C)2013 Ashutosh Kumar Singh [me@AKSingh.net]
|
* Copyright (C)2013-2014 Ashutosh Kumar Singh [me@AKSingh.net]
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the "Software"),
|
* a copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -11,8 +11,6 @@
|
||||||
* The above copyright notice and this permission notice shall be included
|
* The above copyright notice and this permission notice shall be included
|
||||||
* in all copies or substantial portions of the Software.
|
* in all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* The Software shall be used for Good, not Evil.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
@ -32,7 +30,7 @@ import java.util.Scanner;
|
||||||
/**
|
/**
|
||||||
* Provides various tools, which help doing tasks in this application.
|
* Provides various tools, which help doing tasks in this application.
|
||||||
* For example, tool for downloading content from the Internet, tool for
|
* For example, tool for downloading content from the Internet, tool for
|
||||||
* correcting and stricting web addresses, etc.
|
* correcting, etc.
|
||||||
*
|
*
|
||||||
* <p>Note: This class directly do not provide any functions, but has
|
* <p>Note: This class directly do not provide any functions, but has
|
||||||
* <code>static</code> sub-classes which provide various
|
* <code>static</code> sub-classes which provide various
|
||||||
|
@ -40,7 +38,7 @@ import java.util.Scanner;
|
||||||
* classes.
|
* classes.
|
||||||
*
|
*
|
||||||
* @author Ashutosh Kumar Singh
|
* @author Ashutosh Kumar Singh
|
||||||
* @version 2013-08-05
|
* @version 2014-07-01
|
||||||
* @since 2.5.0.1
|
* @since 2.5.0.1
|
||||||
*/
|
*/
|
||||||
public class Tools {
|
public class Tools {
|
||||||
|
@ -92,39 +90,6 @@ public class Tools {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides functions to handle HTML, e.g., correcting
|
|
||||||
* non-compliant or non-strict web addresses, etc.
|
|
||||||
*
|
|
||||||
* @author Ashutosh Kumar Singh
|
|
||||||
* @version 2013/08/05
|
|
||||||
* @since 2.5.0.1
|
|
||||||
*/
|
|
||||||
public static class HTML {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stricts a non-strict or non-compliant web address
|
|
||||||
* to a proper URL.
|
|
||||||
*
|
|
||||||
* <p>Note: This function checks and stricts only some parts of the
|
|
||||||
* URL, which are necessary to be corrected for accessing data from
|
|
||||||
* the OpenWeatherMap.org
|
|
||||||
*
|
|
||||||
* @param inputString String to be converted to strict HTML address
|
|
||||||
* @return HTML standards-followed and stricted URL
|
|
||||||
*/
|
|
||||||
public static String strictAddress(String inputString) {
|
|
||||||
String outputString = "";
|
|
||||||
|
|
||||||
if (inputString != null) {
|
|
||||||
outputString = inputString.replace(" ", "%20").replace(".", "%2E");
|
|
||||||
}
|
|
||||||
|
|
||||||
return outputString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides methods to do conversions.
|
* Provides methods to do conversions.
|
||||||
* For example, converting degree to direction, etc.
|
* For example, converting degree to direction, etc.
|
||||||
|
@ -137,6 +102,7 @@ public class Tools {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts degree to direction.
|
* Converts degree to direction.
|
||||||
|
* @param degree
|
||||||
* @return Direction
|
* @return Direction
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue