Пример #1
0
        public async static Task <List <Food> > SearchFood(string foodName, string brand)
        {
            string Uri = "https://api.edamam.com/api/food-database/v2/parser?app_id=103664a0&app_key=b1ce1d8f2c9a98f79d67f9e3cb070d3a";

            if (foodName == null)
            {
                //requires a value and dont know what else to do for default
                Uri += "&ingr=a";
            }
            else
            {
                Uri += "&ingr=" + foodName;
            }
            Uri += "&brand=" + brand;
            HttpResponseMessage response = await client.GetAsync(Uri);

            if (response.IsSuccessStatusCode)
            {
                APIFoods f = JsonConvert.DeserializeObject <APIFoods>(response.Content.ReadAsStringAsync().Result);
                return(ConvertAPIFoodsToFood(f));
            }
            else
            {
                throw new Exception("Application failed to access API at address: " + Uri);
            }
        }
Пример #2
0
        private static List <Food> ConvertAPIFoodsToFood(APIFoods FoodsIn)
        {
            List <Food> f = new List <Food>();

            for (int i = 0; i < FoodsIn.hints.Length; i++)
            {
                f.Add(new Food(FoodsIn.hints[i].food));
            }
            return(f);
        }