private string BuildRequestUrl(string urlparams) { var unit = OptionalParameters?.MeasurementUnits; _weatherProviderUnits = string.IsNullOrEmpty(unit) ? WeatherProviderUnits.Imperial // Right presure unit : (WeatherProviderUnits)Enum.Parse(typeof(WeatherProviderUnits), unit, true); var result = string.Format( "yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where {0}) and u='{1}'&format=json", urlparams, _weatherProviderUnits.ToValue()); return(result); }
private string BuildRequestUrl(string urlparams) { var unit = OptionalParameters?.MeasurementUnits; _weatherProviderUnits = string.IsNullOrEmpty(unit) ? WeatherProviderUnits.Metric : (WeatherProviderUnits)Enum.Parse(typeof(WeatherProviderUnits), unit, true); var urlbase = string.Format("{0}?appid={1}", _weatherDataType.ToValue(), ApiKey?.Decrypt()); var lang = GetValidLanguage(OptionalParameters?.LanguageCode); var result = string.Format("{0}&{1}&units={2}&lang={3}", urlbase, urlparams, _weatherProviderUnits.ToValue(), lang); return(result); }
protected override string BuildRequestUri(double latitude, double longitude) { Latitude = latitude; Longitude = longitude; var queryString = new StringBuilder(string.Format(FormatProvider, "forecast/{0}/{1:N4},{2:N4}", ApiKey?.Decrypt(), latitude, longitude)); if (OptionalParameters?.UnixTimeInSeconds != null) { queryString.AppendFormat(",{0}", OptionalParameters.UnixTimeInSeconds); } if (OptionalParameters != null) { queryString.Append("?"); } if (OptionalParameters?.DataBlocksToExclude != null && OptionalParameters.DataBlocksToExclude.Count > 0) { queryString.AppendFormat("&exclude={0}", string.Join(",", OptionalParameters.DataBlocksToExclude)); } if (OptionalParameters?.ExtendHourly != null && OptionalParameters.ExtendHourly.Value) { queryString.Append("&extend=hourly"); } var languageCode = GetValidLanguage(OptionalParameters?.LanguageCode); queryString.AppendFormat("&lang={0}", languageCode); var unit = OptionalParameters?.MeasurementUnits; _weatherProviderUnits = string.IsNullOrEmpty(unit) ? WeatherProviderUnits.Si : (WeatherProviderUnits)Enum.Parse(typeof(WeatherProviderUnits), unit, true); queryString.AppendFormat("&units={0}", _weatherProviderUnits.ToValue()); return(queryString.ToString()); }
protected override WeatherForecast OnProcessResponse(object responseResult, CancellationToken token) { if (IfCancellationRequested(token)) { return(null); } if (responseResult == null) { return(null); } var response = responseResult as DarkSkyResponse; if (string.IsNullOrEmpty(response?.Response) || string.IsNullOrWhiteSpace(response.Response)) { return(null); } var forecast = JsonConvert.DeserializeObject <Forecast>(response.Response); if (forecast == null) { return(null); } // weather forecast var weather = new WeatherForecast(providerId: ProviderId, latitude: Latitude, longitude: Longitude, units: ResponseUnits, languageCode: OptionalParameters?.LanguageCode, link: string.Format(FormatProvider, "https://darksky.net/forecast/{0:N4},{1:N4}/{2}", Latitude, Longitude, _weatherProviderUnits.ToValue() + "12"), hasIcons: false) { Currently = CreateWeatherDataPoint(forecast.Currently, token), Daily = CreateItems(forecast.Daily?.Data, token), Hourly = CreateItems(forecast.Hourly?.Data, token) }; if (IfCancellationRequested(token)) { return(null); } // error if (!ValidateForecast(weather)) { return(null); } if (IfCancellationRequested(token)) { return(null); } weather.UpdatedDate = DateTime.UtcNow; return(weather); }