private void AddToCart(string pizzaName) { var addToCartUrl = SearchForPizza(pizzaName); var response = httpClient.GetString(addToCartUrl); DebugContent.WriteToHtmlFile(response); }
private PersistentSessionHttpClient LoginToPizzaProvider(string username, string password) { var client = new PersistentSessionHttpClient(); var loginPostForm = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("email", username), new KeyValuePair <string, string>("passwd", password), new KeyValuePair <string, string>("back", "identity"), new KeyValuePair <string, string>("SubmitLogin", "") }; var response = client.Post(loginPage, loginPostForm); var content = response.Content.ReadAsStringAsync().Result; // Failed to login - page was not redirected to identity page if (!content.Contains("<title>Identity - CarusoPizza</title>")) { throw new PizzaProviderException($"Failed to login user '{username}'. Check that password is correct, try to log via web on {loginPage}"); } DebugContent.WriteToHtmlFile(content); return(client); }
private string GetToken() { var cartPage = httpClient.GetString(orderUrl); DebugContent.WriteToHtmlFile(cartPage); var tokenVariable = Regex.Match(cartPage, "var static_token = '.*'").Value; sessionToken = tokenVariable.Substring(20, 32); if (sessionToken == null) { throw new PizzaProviderException("Failed to get static sessionToken"); } return(sessionToken); }
private string SearchForPizza(string pizzaName) { pizzaName = pizzaName.ToLower(); var url = $"{ProviderUrlConst}cs/vyhledavani?search_query={pizzaName}"; var content = httpClient.GetString(url); DebugContent.WriteToHtmlFile(content); var document = new HtmlDocument(); document.LoadHtml(content); var pizzas = GetPizzas(document.DocumentNode).ToList(); var searched = pizzas.FirstOrDefault(p => p.Name == pizzaName); if (searched == null) { throw new PizzaProviderException($"Failed to find order button for pizza {pizzaName}. It is possible that the pizzeria is closed at the moment or that there are no pizzas with name {pizzaName}."); } return(searched.OrderUrl); }