Android Open Source - UK-Weather-repo Open Weather Map Url






From Project

Back to project page UK-Weather-repo.

License

The source code is released under:

Apache License

If you think the Android project UK-Weather-repo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.haringeymobile.ukweather.data;
/*from w w  w. j ava2s. c o  m*/
import java.net.MalformedURLException;
import java.net.URL;

/** An Open Weather Map web page to fetch some kind of weather information. */
public class OpenWeatherMapUrl {

  private static final String OPEN_WEATHER_MAP_URL_PREFIX = "http://api.openweathermap.org/data/2.5/";
  private static final String WEATHER = "weather";
  private static final String ID = "?id=";
  private static final String FIND = "find?q=";
  private static final String LIKE = "&type=like";
  private static final String FORECAST = "forecast";
  private static final String FORECAST_DAILY = "forecast/daily";
  private static final String COUNT = "&cnt=";

  /**
   * Obtains a web address to extract the current weather information for the
   * provided city.
   * 
   * @param cityId
   *            Open Weather Map city identification number
   * @return web page containing current weather information
   */
  public URL generateCurrentWeatherByCityIdUrl(int cityId) {
    return getUrl(OPEN_WEATHER_MAP_URL_PREFIX + WEATHER + ID + cityId);
  }

  /**
   * Parses the provided string to a valid web address, that can be used to
   * fetch data.
   * 
   * @param urlString
   *            specification for the URL
   * @return a new URL instance
   */
  private URL getUrl(String urlString) {
    URL url = null;
    try {
      url = new URL(urlString);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    return url;
  }

  /**
   * Obtains a web address to extract the list of locations matching the
   * provided query.
   * 
   * @param query
   *            user provided city search query
   * @return web page with the list of cities
   */
  public URL getAvailableCitiesListUrl(String query) {
    return getUrl(OPEN_WEATHER_MAP_URL_PREFIX + FIND + query + LIKE);
  }

  /**
   * Obtains a web address to extract the daily weather forecast for the
   * specified number of days.
   * 
   * @param cityId
   *            Open Weather Map city identification number
   * @param days
   *            number of days that the weather should be forecasted
   * @return web page containing daily weather forecast
   */
  public URL generateDailyWeatherForecastUrl(int cityId, int days) {
    return getUrl(OPEN_WEATHER_MAP_URL_PREFIX + FORECAST_DAILY + ID
        + cityId + COUNT + days);
  }

  /**
   * Obtains a web address to extract the three hourly weather forecast for
   * the specified city.
   * 
   * @param cityId
   *            Open Weather Map city identification number
   * @return web page containing three hourly weather forecast
   */
  public URL generateThreeHourlyWeatherForecastUrl(int cityId) {
    return getUrl(OPEN_WEATHER_MAP_URL_PREFIX + FORECAST + ID + cityId);
  }

}




Java Source Code List

com.astuetz.PagerSlidingTabStrip.java
com.haringeymobile.ukweather.AboutActivity.java
com.haringeymobile.ukweather.BaseCityCursorAdapter.java
com.haringeymobile.ukweather.BaseCityListFragmentWithButtons.java
com.haringeymobile.ukweather.CityListFragmentWithUtilityButtons.java
com.haringeymobile.ukweather.CityListFragmentWithWeatherButtons.java
com.haringeymobile.ukweather.CityManagementActivity.java
com.haringeymobile.ukweather.CitySearchResultsDialog.java
com.haringeymobile.ukweather.CityUtilitiesCursorAdapter.java
com.haringeymobile.ukweather.CityWeatherCursorAdapter.java
com.haringeymobile.ukweather.DeleteCityDialog.java
com.haringeymobile.ukweather.GetAvailableCitiesTask.java
com.haringeymobile.ukweather.MainActivity.java
com.haringeymobile.ukweather.SettingsActivityPreHoneycomb.java
com.haringeymobile.ukweather.SettingsActivity.java
com.haringeymobile.ukweather.SettingsFragment.java
com.haringeymobile.ukweather.WeatherCurrentInfoFragment.java
com.haringeymobile.ukweather.WeatherDailyWeatherForecastChildFragment.java
com.haringeymobile.ukweather.WeatherForecastParentFragment.java
com.haringeymobile.ukweather.WeatherInfoActivity.java
com.haringeymobile.ukweather.WeatherInfoFragment.java
com.haringeymobile.ukweather.WeatherInfoType.java
com.haringeymobile.ukweather.WeatherThreeHourlyForecastChildFragment.java
com.haringeymobile.ukweather.WorkerFragmentToRetrieveJsonString.java
com.haringeymobile.ukweather.data.InitialCity.java
com.haringeymobile.ukweather.data.JsonFetcher.java
com.haringeymobile.ukweather.data.OpenWeatherMapUrl.java
com.haringeymobile.ukweather.data.objects.CityCurrentWeather.java
com.haringeymobile.ukweather.data.objects.CityDailyWeatherForecast.java
com.haringeymobile.ukweather.data.objects.CityInfo.java
com.haringeymobile.ukweather.data.objects.CityThreeHourlyWeatherForecast.java
com.haringeymobile.ukweather.data.objects.Clouds.java
com.haringeymobile.ukweather.data.objects.Coordinates.java
com.haringeymobile.ukweather.data.objects.NumericParameters.java
com.haringeymobile.ukweather.data.objects.Rain.java
com.haringeymobile.ukweather.data.objects.SearchResponseForDailyForecastQuery.java
com.haringeymobile.ukweather.data.objects.SearchResponseForFindQuery.java
com.haringeymobile.ukweather.data.objects.SearchResponseForThreeHourlyForecastQuery.java
com.haringeymobile.ukweather.data.objects.SystemParameters.java
com.haringeymobile.ukweather.data.objects.TemperatureScale.java
com.haringeymobile.ukweather.data.objects.Temperature.java
com.haringeymobile.ukweather.data.objects.WeatherInformation.java
com.haringeymobile.ukweather.data.objects.Weather.java
com.haringeymobile.ukweather.data.objects.WindSpeedMeasurementUnit.java
com.haringeymobile.ukweather.data.objects.Wind.java
com.haringeymobile.ukweather.database.CityTable.java
com.haringeymobile.ukweather.database.DatabaseHelper.java
com.haringeymobile.ukweather.database.GeneralDatabaseService.java
com.haringeymobile.ukweather.database.SqlOperation.java
com.haringeymobile.ukweather.database.WeatherContentProvider.java
com.haringeymobile.ukweather.utils.AsyncTaskWithProgressBar.java
com.haringeymobile.ukweather.utils.GlobalConstants.java
com.haringeymobile.ukweather.utils.MiscMethods.java
com.haringeymobile.ukweather.utils.SharedPrefsHelper.java