public static List <DrinkMultiple> getAllDrinks(List <String> drinkNames) { List <DrinkMultiple> availableDrinks = new List <DrinkMultiple>(); foreach (var stringDrinkName in drinkNames) { // Get all drinks accosieated with the ingridient // ! Only shallow information ! DrinkMultiple tempDrinks = HttpGet(stringDrinkName, HttpGetRequests.CocktailByIngridient); if (tempDrinks == null) { continue; } // Get all drinks details based on id for (int i = 0; i < tempDrinks.Drinks.Count; i++) { string drinkID = tempDrinks.Drinks[i].idDrink.ToString(); tempDrinks.Drinks[i] = HttpGet(drinkID, HttpGetRequests.CocktailByID).Drinks[0]; } availableDrinks.Add(tempDrinks); } return(availableDrinks); }
public static List <DrinkMultiple> FilterMixableDrinks(List <DrinkMultiple> availableDrinks, List <String> drinkNames, int miniCoherentAmountForMix) { List <DrinkMultiple> filteredDrinkList = new List <DrinkMultiple>(); DrinkMultiple tempDrinkMultiple = new DrinkMultiple(); tempDrinkMultiple.Drinks = new List <Drink>(); foreach (DrinkMultiple drinksMultiple in availableDrinks) { foreach (Drink drink in drinksMultiple.Drinks) { if (checkIfCanBeMixed(drink, miniCoherentAmountForMix, drinkNames)) { if ( !tempDrinkMultiple.Drinks.Exists(x => x.strDrink == drink.strDrink)) //!String.IsNullOrEmpty(drink.strDrinkThumb) && { tempDrinkMultiple.Drinks.Add(drink); } } } } filteredDrinkList.Add(tempDrinkMultiple); return(filteredDrinkList); }
private SortedDictionary <string, DrinkMultiple> UpdateRepositoryData(List <string> drinkNames) { bool changed = false; // Repo is empty, get all new data if (TransporterClass.Repository == null) { foreach (var item in drinkNames) { DrinkMultiple availableDrinks = CocktailDBService.getAllDrinks(item); Repository.AddDrinkMultiple(availableDrinks, item); changed = true; } } else { // Check if exist in repo or get it from DB foreach (string drinkItem in drinkNames) { if (!TransporterClass.Repository.ContainsKey(drinkItem)) { DrinkMultiple missingDrinkMultiple = CocktailDBService.getAllDrinks(drinkItem); Repository.AddDrinkMultiple(missingDrinkMultiple, drinkItem); changed = true; } } } if (changed) { Repository.SaveData(); TransporterClass.Repository = Repository.repositoryDictionery; } return(TransporterClass.Repository); }
public static DrinkMultiple HttpGet(string stringGet, HttpGetRequests enumRequest) { string html = string.Empty; string requestApi = "empty"; switch (enumRequest) { case HttpGetRequests.CocktailByIngridient: requestApi = "filter"; break; case HttpGetRequests.CocktailByID: requestApi = "lookup"; break; case HttpGetRequests.IngridientInfo: requestApi = "search"; break; default: break; } string url = $"http://www.thecocktaildb.com/api/json/v1/1/{requestApi}.php?i={stringGet}"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Accept = "application/json"; DrinkMultiple drinks = new DrinkMultiple(); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); drinks = JsonConvert.DeserializeObject <DrinkMultiple>(html); } return(drinks); }
public static List <DrinkMultiple> getAllDrinksShallow(List <String> drinkNames) { List <DrinkMultiple> availableDrinks = new List <DrinkMultiple>(); foreach (var stringDrinkName in drinkNames) { // Get all drinks accosieated with the ingridient // ! Only shallow information ! DrinkMultiple tempDrinks = HttpGet(stringDrinkName, HttpGetRequests.CocktailByIngridient); if (tempDrinks == null) { continue; } availableDrinks.Add(tempDrinks); } return(availableDrinks); }
public static DrinkMultiple getAllDrinks(String drinkNames) { // Get all drinks accosieated with the ingridient // ! Only shallow information ! DrinkMultiple tempDrinks = HttpGet(drinkNames, HttpGetRequests.CocktailByIngridient); if (tempDrinks == null) { return(null); } // Get all drinks details based on id for (int i = 0; i < tempDrinks.Drinks.Count; i++) { string drinkID = tempDrinks.Drinks[i].idDrink.ToString(); tempDrinks.Drinks[i] = HttpGet(drinkID, HttpGetRequests.CocktailByID).Drinks[0]; } return(tempDrinks); }
public static void AddDrinkMultiple(DrinkMultiple newDrinkMultiple, string newSearchedIngridient) { repositoryDictionery.Add(newSearchedIngridient, newDrinkMultiple); }