public static GetDataFromService ( string queryString ) : Task |
||
queryString | string | |
Результат | Task |
public static async Task <WeatherViewModel> GetWeatherViewModel(string zipCode) { string openWeatherkey = "bab095c7df7c83c287d14b64558c6fcf"; string queryString = $@"https://api.openweathermap.org/data/2.5/weather?zip={zipCode},us&appid={openWeatherkey}&units=imperial"; string results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); WeatherViewModel viewModel = null; if (!String.IsNullOrWhiteSpace(results)) { Rootobject weatherData = JsonConvert.DeserializeObject <Rootobject>(results); DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)weatherData.sys.sunrise); DateTime sunset = time.AddSeconds((double)weatherData.sys.sunset); DateTime sunriseLocal = sunrise.ToLocalTime(); DateTime sunsetLocal = sunset.ToLocalTime(); viewModel = new WeatherViewModel { Title = weatherData.name, Temperature = weatherData.main.temp.ToString(), Wind = weatherData.wind.speed.ToString(), Humidity = weatherData.main.humidity.ToString(), Visibility = weatherData.visibility.ToString(), Sunrise = sunriseLocal.ToString("hh:mm"), Sunset = sunsetLocal.ToString("hh:mm") }; } return(viewModel); }
public static async Task <Weather> GetWeather(string zipCode) { //Sign up for a free API key at http://openweathermap.org/appid string key = "YOUR API KEY HERE"; string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + key + "&units=imperial"; var results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] != null) { Weather weather = new Weather(); weather.Title = (string)results["name"]; weather.Temperature = (string)results["main"]["temp"] + " F"; weather.Wind = (string)results["wind"]["speed"] + " mph"; weather.Humidity = (string)results["main"]["humidity"] + " %"; weather.Visibility = (string)results["weather"][0]["main"]; DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]); DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]); weather.Sunrise = sunrise.ToString() + " UTC"; weather.Sunset = sunset.ToString() + " UTC"; return(weather); } else { return(null); } }
public static async Task <Weather> GetWeather(string zipCode) { //Info for open weather string key = "b0f6583a877d6f9d042e76e575470acb"; string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + "&units=imperial&appid=" + key; var results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] != null) { //Differnt weather information Weather weather = new Weather(); weather.Title = (string)results["name"]; weather.Temperature = (string)results["main"]["temp"] + " F"; weather.Wind = (string)results["wind"]["speed"] + " mph"; weather.Humidity = (string)results["main"]["humidity"] + " %"; weather.Visibility = (string)results["weather"][0]["main"]; //Time info for sunrise/sunset DateTime time = new System.DateTime(1970, 1, 1, 19, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]); DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]); weather.Sunrise = sunrise.ToString() + " CST"; weather.Sunset = sunset.ToString() + " CST"; return(weather); } else { return(null); } }
public static async Task <Weather> GetWeather(string zipCode) { //Sign up for a free API key at http://openweathermap.org/appid string key = "092c794ba9787c8e74be486d94cfc224"; string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + key + "&units=imperial"; dynamic results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] == null) { return(null); } var weather = new Weather { Title = (string)results["name"], Temperature = (string)results["main"]["temp"] + " F", Wind = (string)results["wind"]["speed"] + " mph", Humidity = (string)results["main"]["humidity"] + " %", Visibility = (string)results["weather"][0]["main"] }; DateTime time = new DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]); DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]); weather.Sunrise = sunrise + " UTC"; weather.Sunset = sunset + " UTC"; return(weather); }
public static async Task <Weather> GetWeather(string zipCode) { const string key = "1c655688dd5648fa75230968bf9fcc91"; var queryString = $"http://api.openweathermap.org/data/2.5/weather?zip={zipCode},us&appid={key}&units=imperial"; var results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] != null) { var weather = new Weather { Title = results["name"], Temperature = $"{results["main"]["temp"]} F", Wind = $"{results["wind"]["speed"]} mph", Humidity = $"{results["main"]["humidity"]} %", Visibility = $"{results["weather"][0]["main"]}", Sunrise = $"{epoch.AddSeconds((double)results["sys"]["sunrise"])} UTC", Sunset = $"{epoch.AddSeconds((double)results["sys"]["sunset"])} UTC", }; return(weather); } return(null); }
public static async Task <Recipe> GetRecipe(string searchTerm) { // **START recipe search API // documentation https://developer.edamam.com/edamam-docs-recipe-api string key = "4f9099da52f998eb02261e0714715495"; string id = "cfafedc8"; string queryString = "https://api.edamam.com/search?q=" + System.Uri.EscapeUriString(searchTerm) + "&app_id=" + id + "&app_key=" + key; // **END recipe search API dynamic results = await DataService.GetDataFromService(queryString).ConfigureAwait(true); Recipe recipe = new Recipe(); // recipe name recipe.RecipeLabelContent = (string)results["hits"][0]["recipe"]["label"]; // recipe ingredients // count all ingredients in array int NumberofIngredients = results["hits"][0]["recipe"]["ingredients"].Count; // loop to put all ingredients in ingredient array in 1 string for (int i = 0; i < NumberofIngredients; i++) { recipe.IngredientsContent += ((string)results["hits"][i]["recipe"]["ingredients"][1]["text"] + "\n"); } // recipe URL recipe.RecipeURL = (string)results["hits"][0]["recipe"]["url"]; // recipe image URL recipe.RecipeImageURL = (string)results["hits"][0]["recipe"]["image"]; return(recipe); }
public static async Task <Weather> GetWeather(string zipCode) { //Sign up for a free API key at http://openweathermap.org/appid string key = Api.Key; string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",&appid=" + key; //Make sure developers running this sample replaced the API key if (key == "YOUR API KEY HERE") { throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable."); } var results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] != null) { Weather weather = new Weather(); weather.Title = (string)results["name"]; weather.Temperature = ConvertToFahrenheit((string)results["main"]["temp"]) + " F"; weather.Wind = (string)results["wind"]["speed"] + " mph"; weather.Humidity = (string)results["main"]["humidity"] + " %"; weather.Visibility = (string)results["weather"][0]["main"]; DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]); DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]); weather.Sunrise = sunrise.ToString() + " UTC"; weather.Sunset = sunset.ToString() + " UTC"; weather.Icon = (string)results["weather"][0]["id"]; return(weather); } else { return(null); } }
public static async Task<Weather> GetWeather(string zipCode) { //Sign up for a free API key at http://openweathermap.org/appid string key = "4631e97ee958707f2f8602991c39afb8"; string queryString = "http://api.openweathermap.org/data/2.5/weather?zip=" + zipCode + ",us&appid=" + key + "&units=imperial"; //Make sure developers running this sample replaced the API key if (key != "4631e97ee958707f2f8602991c39afb8") { throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable."); } dynamic results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] != null) { Weather weather = new Weather(); weather.Title = (string)results["name"]; weather.Temperature = (string)results["main"]["temp"] + " F"; weather.Wind = (string)results["wind"]["speed"] + " mph"; weather.Humidity = (string)results["main"]["humidity"] + " %"; weather.Visibility = (string)results["weather"][0]["main"]; DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]); DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]); weather.Sunrise = sunrise.ToString() + " UTC"; weather.Sunset = sunset.ToString() + " UTC"; return weather; } else { return null; } }
public static async Task <Weather> GetWeather(string city) { //Sign up for a free API key at http://openweathermap.org/appid string key = "f43ac9da3e8483cd16c5343a57ad2655"; string queryString = "http://api.openweathermap.org/data/2.5/weather?q=" + city + ",au&appid=" + key + "&units=metric"; //Make sure developers running this sample replaced the API key if (key == "YOUR API KEY HERE") { throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable."); } dynamic results = await DataService.GetDataFromService(queryString).ConfigureAwait(false); if (results["weather"] != null) { Weather weather = new Weather(); weather.Title = (string)results["name"]; weather.Temperature = (string)results["main"]["temp"] + " C"; weather.Wind = (string)results["wind"]["speed"] + " kph"; weather.Humidity = (string)results["main"]["humidity"] + " %"; weather.Visibility = (string)results["weather"][0]["main"]; DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]); DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]); weather.Sunrise = sunrise.ToString() + " UTC"; weather.Sunset = sunset.ToString() + " UTC"; return(weather); } else { return(null); } }
public static async Task <Recipe> GetRecipe(string searchTerm, bool GlutenFree, bool DairyFree, bool Vegetarian) { string HealthParam = ""; if (GlutenFree || DairyFree || Vegetarian == true) { HealthParam = "?"; } if (GlutenFree == true) { HealthParam += "health=gluten-free"; } if (DairyFree == true) { if (GlutenFree == true) { HealthParam += "&"; } HealthParam += "health=gluten-free"; } if (Vegetarian == true) { if (GlutenFree || Vegetarian == true) { HealthParam += "&"; } HealthParam += "health=vegetarian"; } // **START recipe search API // documentation https://developer.edamam.com/edamam-docs-recipe-api string key = "4f9099da52f998eb02261e0714715495"; string id = "cfafedc8"; string queryString = "https://api.edamam.com/search?q=" + /* URI encoding */ System.Uri.EscapeUriString(searchTerm) + HealthParam + "&app_id=" + id + "&app_key=" + key; // **END recipe search API dynamic results = await DataService.GetDataFromService(queryString).ConfigureAwait(true); Recipe recipe = new Recipe(); //count of search results recipe.CountOfResults = (string)results["count"]; // recipe name recipe.RecipeLabelContent1 = (string)results["hits"][0]["recipe"]["label"]; recipe.RecipeLabelContent2 = (string)results["hits"][1]["recipe"]["label"]; recipe.RecipeLabelContent3 = (string)results["hits"][2]["recipe"]["label"]; recipe.RecipeLabelContent4 = (string)results["hits"][3]["recipe"]["label"]; recipe.RecipeLabelContent5 = (string)results["hits"][4]["recipe"]["label"]; // loop to put all ingredients in ingredient JSON array in single string for (int i = 0; i < (results["hits"][0]["recipe"]["ingredients"].Count); i++) { recipe.IngredientsContent1 += ((string)results["hits"][0]["recipe"]["ingredients"][i]["text"] + "\n"); } for (int i = 0; i < (results["hits"][1]["recipe"]["ingredients"].Count); i++) { recipe.IngredientsContent2 += ((string)results["hits"][1]["recipe"]["ingredients"][i]["text"] + "\n"); } for (int i = 0; i < (results["hits"][2]["recipe"]["ingredients"].Count); i++) { recipe.IngredientsContent3 += ((string)results["hits"][2]["recipe"]["ingredients"][i]["text"] + "\n"); } for (int i = 0; i < (results["hits"][3]["recipe"]["ingredients"].Count); i++) { recipe.IngredientsContent4 += ((string)results["hits"][3]["recipe"]["ingredients"][i]["text"] + "\n"); } for (int i = 0; i < (results["hits"][4]["recipe"]["ingredients"].Count); i++) { recipe.IngredientsContent5 += ((string)results["hits"][4]["recipe"]["ingredients"][i]["text"] + "\n"); } // recipe URL recipe.RecipeURL1 = (string)results["hits"][0]["recipe"]["url"]; recipe.RecipeURL2 = (string)results["hits"][1]["recipe"]["url"]; recipe.RecipeURL3 = (string)results["hits"][2]["recipe"]["url"]; recipe.RecipeURL4 = (string)results["hits"][3]["recipe"]["url"]; recipe.RecipeURL5 = (string)results["hits"][4]["recipe"]["url"]; // recipe image URL recipe.RecipeImageURL1 = (string)results["hits"][0]["recipe"]["image"]; recipe.RecipeImageURL2 = (string)results["hits"][1]["recipe"]["image"]; recipe.RecipeImageURL3 = (string)results["hits"][2]["recipe"]["image"]; recipe.RecipeImageURL4 = (string)results["hits"][3]["recipe"]["image"]; recipe.RecipeImageURL5 = (string)results["hits"][4]["recipe"]["image"]; return(recipe); }