Created
June 24, 2016 08:08
-
-
Save bruferrari/577e03b5aa450df91eecd31e47cd0efa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Construct the URL for the OpenWeatherMap query | |
// Possible parameters are avaiable at OWM's forecast API page, at | |
// http://openweathermap.org/API#forecast | |
final String FORECAST_BASE_URL = | |
"http://api.openweathermap.org/data/2.5/forecast/daily?"; | |
final String QUERY_PARAM = "q"; | |
final String FORMAT_PARAM = "mode"; | |
final String UNITS_PARAM = "units"; | |
final String DAYS_PARAM = "cnt"; | |
final String APPID_PARAM = "APPID"; | |
Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon() | |
.appendQueryParameter(QUERY_PARAM, locationQuery) | |
.appendQueryParameter(FORMAT_PARAM, format) | |
.appendQueryParameter(UNITS_PARAM, units) | |
.appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)) | |
.appendQueryParameter(APPID_PARAM, BuildConfig.OPEN_WEATHER_MAP_API_KEY) | |
.build(); | |
URL url = new URL(builtUri.toString()); | |
// Create the request to OpenWeatherMap, and open the connection | |
urlConnection = (HttpURLConnection) url.openConnection(); | |
urlConnection.setRequestMethod("GET"); | |
urlConnection.connect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment