Skip to content

Instantly share code, notes, and snippets.

@naanT
Created August 20, 2015 21:46
Show Gist options
  • Save naanT/fcd5607f1a471c74564e to your computer and use it in GitHub Desktop.
Save naanT/fcd5607f1a471c74564e to your computer and use it in GitHub Desktop.
UriBuilder
URL url = new URL("http://api.openweathermap.org/data/2.5/forecast/daily?q=94043&mode=json&units=metric&cnt=7");
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";
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))
.build();
url = new URL(builtUri.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment