public object CoopCloseStore() { //BearerAccessToken bearerAccessToken = new BearerAccessToken("f0cabde6bb8d4bd78c28270ee203253f"); /* Code #1 */ //BearerAccessToken bearerAccessToken = new BearerAccessToken("d0b9a5266a2749cda99d4468319b6d9f"); /* Code #2 */ BearerAccessToken bearerAccessToken = new BearerAccessToken(_token); // Create link to a store with radius as input string url = linkMaker.GetRadiusLink(10000); // Open the link using the url and token OpenHttp <CoopStoreApi> openHttp = new OpenHttp <CoopStoreApi>(url, bearerAccessToken.GetBearerToken()); // Parse CoopStoreApi stuff = openHttp.ReadAndParseAPISingle(); // Create list for StoreId in the different stores found inside the radius //List<int> storId = new List<int>(); // Fill the StoreId list with Kardex (storeid) for the different stores //foreach (var product in stuff.Data) //{ // storId.Add(product.Kardex); //} //foreach (var store in stuff.Data) //{ // Console.WriteLine(store.RetailGroupName + " - " + store.Kardex + " - " + store.Address + " - " + store.Zipcode); //} return(stuff); }
/// <summary> /// If a searchterms yields no results in the databae then this methos is used to check for results in the salling api(currently disabled because of technical issus on sallings side) /// </summary> /// <param name="Searchterm"></param> /// <returns>returns bool based on wheter or not any products are found to match the serchterm</returns> private bool CheckIngredientsInApi(string Searchterm) { System.Threading.Thread.Sleep(4000); BearerAccessToken bearerAccessToken = new BearerAccessToken("fc5aefca-c70f-4e59-aaaa-1c4603607df8"); SallingAPILink linkMaker = new SallingAPILink(); SallingAPIProductSuggestions productSuggestions = new SallingAPIProductSuggestions(); string apiLink = linkMaker.GetProductAPILink(Searchterm); OpenHttp <SallingAPIProductSuggestions> openHttp; try { openHttp = new OpenHttp <SallingAPIProductSuggestions>(apiLink, bearerAccessToken.GetBearerToken()); productSuggestions = openHttp.ReadAndParseAPISingle(); if (productSuggestions.Suggestions != null) { foreach (var p in productSuggestions.Suggestions) { dc.Product.Add(new Product(p.title, p.id, p.prod_id, p.price, p.description, p.link, p.img)); } } } catch (System.Net.WebException) { Console.WriteLine("Exception found is being handled"); System.Threading.Thread.Sleep(30000); Console.WriteLine("Exception resolved"); return(false); } if (productSuggestions.Suggestions != null) { return(productSuggestions.Suggestions.Count != 0 ? true : false); } else { return(false); } }
public List <Product> SearchForProducts(String searchterm) { BearerAccessToken bearerAccessToken = new BearerAccessToken("fc5aefca-c70f-4e59-aaaa-1c4603607df8"); SallingAPILink linkMaker = new SallingAPILink(); SallingAPIProductSuggestions productSuggestions = new SallingAPIProductSuggestions(); // Creates a link to the Salling api with the searchterm as input string apiLink = linkMaker.GetProductAPILink(searchterm); OpenHttp <SallingAPIProductSuggestions> openHttp; List <Product> returnList = new List <Product>(); try { // Opens the Salling API openHttp = new OpenHttp <SallingAPIProductSuggestions>(apiLink, bearerAccessToken.GetBearerToken()); // Parsese the returned Json string into a list of SallingAPIProduct productSuggestions = openHttp.ReadAndParseAPISingle(); if (productSuggestions.Suggestions.Count != 0) { foreach (SallingAPIProduct products in productSuggestions.Suggestions) { // Adds all SallingAPIProduct to the returnList and converts them all to the class Product returnList.Add(new Product(products.id, products.title, products.description, products.price, products.img, "Bilka")); } } } catch (WebException e) { // If there is an error while loading the Salling api. Console.WriteLine("This program is expected to throw WebException on successful run." + "\n\nException Message :" + e.Message); } return(returnList); }