public async Task <ActionResult> GetDetailedWeather(vmZipCodeEntry model) { string apiKey = "e1db07dc00a073bfedbd4ef37ba27fd8"; var openWeather = new OpenWeatherAPI(apiKey); string response = await openWeather.ProcessResponse(model.ZipCode); // return response; var data = JsonConvert.DeserializeObject <OpenWeatherResults>(response); //return data.main.CurrentTemp.ToString(); var viewModel = new vmDetailedWeather { temp = data.main.CurrentTemp, city = data.name, main = data.weather[0].main, description = data.weather[0].description, speed = data.wind.speed, humidity = data.main.humidity, temp_max = data.main.temp_max, temp_min = data.main.temp_min, pressure = data.main.pressure, // rainfall =data.clouds.all, sunrise = data.sys.sunrise, sunset = data.sys.sunset }; return(View("DetailedWeather", viewModel)); }
private WeatherData GetInfo() { PastWeather pastWeather = null; WeatherData data = new WeatherData(); // set input parameters for the API LocalWeatherInput input = new LocalWeatherInput(); input.query = m_info_future.query; input.num_of_days = m_info_future.num_of_days; input.date = m_info_future.date; input.format = "JSON"; // call the local weather method with input parameters OpenWeatherAPI api = new OpenWeatherAPI(); LocalWeather localWeather = api.GetLocalWeather(input); //set data in datastore based on which kind of datastore refresh was requested if (m_reftype == RefreshType.AddLeft) { DataStore.Instance().AddLeft(pastWeather); } else if (m_reftype == RefreshType.AddLeft) { DataStore.Instance().AddRight(localWeather); } else { DataStore.Instance().SetWeather(localWeather, pastWeather); } return(data); }
public async Task <ActionResult> Index(vmZipCodeEntry model) { string apiKey = "e1db07dc00a073bfedbd4ef37ba27fd8"; var openWeather = new OpenWeatherAPI(apiKey); string response = await openWeather.ProcessResponse(model.ZipCode); // return response; var data = JsonConvert.DeserializeObject <OpenWeatherResults>(response); //return data.main.CurrentTemp.ToString(); var viewModel = new vmBasicWeather { zip = ToInt32(model.ZipCode), temp = data.main.CurrentTemp, city = data.name, main = data.weather[0].main, description = data.weather[0].description }; return(View("BasicWeather", viewModel)); }
public ActionResult AsyncSearchCityName(string cityName) { ApplicationConfiguration configuration = new ApplicationConfiguration(); configuration.Load(); try { IRestResponse response = OpenWeatherAPI.Get(configuration.BaseAddressAPI, cityName, configuration.Query, configuration.APIKey); if (response.StatusCode == System.Net.HttpStatusCode.OK) { ContentResult content = new ContentResult(); content = Content(response.Content, "application/json"); return(content); } else { return(Json(null, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { TempData["Error"] = ex.Message; return(Content(null, "application/json; charset=utf-8")); } }
public async Task GetCurrentWeather(string city) { var openWeatherAPIClient = new OpenWeatherAPI(Configuration.config.OpenWeatherAPIKey); var result = await openWeatherAPIClient.QueryAsync(city); string response = $"The temperature in {city} is {result}C"; await ReplyAsync(response); }
public void CurrentWeatherTest() { OpenWeatherAPI openWeatherAPI = new OpenWeatherAPI(HttpClientFactory.CreateClient(), "a1fcc507923163ff1bae113a80d8f82a"); var sut = Task.Run(() => openWeatherAPI.GetCurrentWeather(80339)); sut.Wait(); var json = sut.Result; }
public void OneCallAPITest_GetWeatherForFourteenDays_ReturnsTrue() { OpenWeatherAPI sut = new OpenWeatherAPI(HttpClientFactory.CreateClient(), "a1fcc507923163ff1bae113a80d8f82a"); var data = Task.Run(() => sut.GetWeatherForFourteenDays(80339)); data.Wait(); var result = data.Result; result.Should().BeOfType(typeof(FourteenDayValuesDomainModel)); }
public void GetForecastStrategy_FourteenDayForecastStrategy_ReturnsFourteenDayForecastStrategy() { //arr var sut = ForecastTypeEnum.fourteenDays; IWeatherForecastProvider weatherForecastProvider = new OpenWeatherAPI(HttpClientFactory.CreateClient(), "a1fcc507923163ff1bae113a80d8f82a"); WeatherForecast weatherForecast = new WeatherForecast(weatherForecastProvider); //act var result = ForecastStrategyFactory.GetForecastStrategy(sut, weatherForecast); //assert result.Should().BeOfType(typeof(FourteenDayForecastStrategy)); }
public void GetWeatherForecastForZip_OpenWeatherOneCallAPI_ReturnsFourteenDayForecast() { //arr IWeatherForecastProvider weatherForecastProvider = new OpenWeatherAPI(HttpClientFactory.CreateClient(), "a1fcc507923163ff1bae113a80d8f82a"); WeatherForecast sut = new WeatherForecast(weatherForecastProvider); //act var result = sut.GetFourteenDayWeatherForecast(80339, TemperatureStrategyFactory.GetTemperatureStrategy(TemperatureTypeEnum.Celsius), DateTime.Now); //assert result.Count.Should().Be(14); }
public async Task <IActionResult> InputZipCode(vmZipCodeEntry model) { string apiKey = "e1db07dc00a073bfedbd4ef37ba27fd8"; var openWeather = new OpenWeatherAPI(apiKey); string response = await openWeather.ProcessResponse(model.ZipCode); string zipCode = model.ZipCode; var test = new vmRawJson(); test.output = response; return(View("RawJson", test)); // return View("RawJson", test); }
static void Main(string[] args) { // Create the API client var openWeatherAPI = new OpenWeatherAPI("d83a046287643b8cb45524900cb0bb88"); while (true) { // Ask for a city to get weather data from Console.Write("Please enter a valid city id: "); // Try to parse the input // TODO here of course we should check if the id entered is valid (does this city even exist?) int.TryParse(Console.ReadLine(), out int id); // Process the data from the given API var currentWeather = openWeatherAPI.GetCurrentWeatherData(id).Result; // Output the temperature Console.WriteLine($"Current Temperature: {currentWeather.Main.Temperature.ToCelsius()} °C"); } }
public List <string> GetForecast( int zipcode, DateTime date, TemperatureTypeEnum temperatureType, ForecastTypeEnum forecastType) { try { CheckParametersValid(zipcode, date, temperatureType, forecastType); } catch (ArgumentException ae) { //ToDo Fehlermeldung an UI } // = "Orchestrierung", ruft Methoden auf ohne zu wissen, woher bspw. Parameter herkommen // Funktionales Programmieren _temperatureStrategy = TemperatureStrategyFactory.GetTemperatureStrategy(temperatureType); // Exercise: New Provider (e.g. Random) and change next Line to see if it still work IWeatherForecastProvider weatherForecastProvider = new OpenWeatherAPI(HttpClientFactory.CreateClient(), "a1fcc507923163ff1bae113a80d8f82a"); WeatherForecast weatherForecast = new WeatherForecast(weatherForecastProvider); _forecastStrategy = ForecastStrategyFactory.GetForecastStrategy(forecastType, weatherForecast); List <string> result = new List <string>(); try { result = _forecastStrategy.GetForecast(zipcode, _temperatureStrategy, date); } catch (ZipNotFoundException ex) { result.Add(ex.Message); } catch (Exception ex) { result.Add($"Exception: {ex.Message}"); } return(result); }
public CurrentWeather GetCurrentWeather(float latitude, float longitude) { IWeatherSource weatherAPI = new OpenWeatherAPI("Enter the Open weather API key"); return(weatherAPI.GetCurrentWeather(latitude, longitude)); }