public void checkJSON() { MashapeAPI m1 = new MashapeAPI(); Assert.True(m1.GetJSON ("https://nutritionix-api.p.mashape.com/v1_1/search/{term}?fields", "8H6stHhT25mshXH1okEaCywiRiCUp1DYIsxjsnyespJHYCy7ca") != null); Assert.True(m1.urlFormat("") != ""); }
// Commands void UpdateGenderExecute() { MashapeAPI mashapeAPI = new MashapeAPI(); string json = mashapeAPI.getGenderInformation(Name).Result; JsonObject jsonObject = JsonObject.Parse(json); Gender = jsonObject.GetNamedString("gender"); }
public static async Task prompt() { Console.WriteLine(@" Howdy, fatso!! -------- Enter a food or beverage to get caloric info: "); string term = Console.ReadLine(); IJSONAPI mashapi = new MashapeAPI(); var nutrixapiKey = "8H6stHhT25mshXH1okEaCywiRiCUp1DYIsxjsnyespJHYCy7ca"; Nutrition n = await mashapi.GetData <Nutrition>(term, nutrixapiKey, ""); if (term == "" || term == "n") { string hitGoogleWith = Search.mostCommonSearch(searchTerms); Console.WriteLine("most common search term:" + hitGoogleWith); //mostCommonSearch(searchTerms); googler.promptGoogle(hitGoogleWith).Wait(); Environment.Exit(0); } else if (n.hits.Count() > 0) { searchTerms.Add(term); string item = n.hits.ElementAt(0).fields.item_name; double?calories = n.hits.ElementAt(0).fields.nf_calories ?? 0; double?fatGrams = n.hits.ElementAt(0).fields.nf_total_fat ?? 0; Console.WriteLine("Item: " + item + " Calories: " + calories + " Fat Grams: " + fatGrams + " grams"); string stickem = (item + calories.ToString() + fatGrams.ToString()); List <string> list1 = new List <string>(); list1.Add(item); list1.Add(calories.ToString()); list1.Add(fatGrams.ToString()); if (!File.Exists(@"csv/nutrix.csv")) { File.AppendAllLines(@"csv/nutrix.csv", list1); // or : File.WriteAllText(@"csv/nutrix.csv", stickem); but writes all in 1 line } File.AppendAllLines(@"csv/nutrix.csv", list1); } prompt().Wait(); }
public static async Task prompt() { Console.WriteLine(@" Hey! Listen! -------- Enter a food or beverage to get caloric info: "); string term = Console.ReadLine(); IJSONAPI mashapi = new MashapeAPI(); // Nutrition n = await mashapi.GetData<Nutrition>("cheddar cheese", "APIKEY"); // Console.WriteLine(mashapi.ToJSON(n)); Gaucho: get JSON should work across //all child classes // IJSONAPI googapi = new GoogleAPI(); ea. API will either have a header info(use) Postman //if header required. // Google g = await googapi.GetData<Google>("tacos", "APIKEY"); //google: no header, api key appended to end. // Console.WriteLine(googapi.ToJSON(g)); }
public void getAPIUrl() { MashapeAPI m = new MashapeAPI(); Assert.True(m.urlFormat("TACOS") != ""); }