Created
March 13, 2016 01:39
-
-
Save aibolik/5d80868d75570961e9e2 to your computer and use it in GitHub Desktop.
Using Uri Builder to build good URLs
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
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, params[0]) | |
+ .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()); | |
+ | |
+ Log.v(LOG_TAG, "Built URI " + builtUri.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment