static void Main(string[] args) { try { // We'll need an API TOKEN and KEY. You can get these from your dashboard on Custructor.io // Store them as an Environment Variable or hardcoded here. API_TOKEN = Environment.GetEnvironmentVariable("CONSTRUCTORIO_API_TOKEN", EnvironmentVariableTarget.User); KEY = Environment.GetEnvironmentVariable("CONSTRUCTORIO_KEY", EnvironmentVariableTarget.User); // Create a Constructor.IO client ConstructorIOAPI constructorClient = new ConstructorIOAPI(API_TOKEN, KEY); // Verify the API and KEY. While this is not strictly nesseary, it is nice to be methodical. if (!constructorClient.Verify()) throw new Exception("Authentication failed. Please check that you have the correct API token and KEY"); Console.WriteLine("Authentication verified"); // Lets load a CSV file IEnumerable<ListItem> listItems = Util.LoadCSV("sample.csv"); Console.WriteLine("CSV file loaded and has "+listItems.Count() +" entries"); // And upload it to Construtor.IO, under the section "Products" // We will use AddOrUpdate function, which will add entries that don't exist, and overwrite entries that do. if (!constructorClient.AddOrUpdateBatch(listItems, ListItemAutocompleteType.Products)) throw new Exception("AddOrUpdateBatch failed."); Console.WriteLine("Entries sent to Constructor.IO successfully"); // We can also create a ListItem manualy, this time under "Search Suggestions" section ListItem newListItem = new ListItem("Testing 123",ListItemAutocompleteType.SearchSuggestions); newListItem.SuggestedScore = 10; // Lets upload it to the server if (!constructorClient.Add(newListItem)) throw new Exception("Adding new ListItem failed."); // We can modify it and update newListItem.SuggestedScore = 42; if (!constructorClient.AddOrUpdate(newListItem)) throw new Exception("Updaing ListItem failed."); // And finally delete it if (!constructorClient.Remove(newListItem)) throw new Exception("Removing new ListItem failed."); Console.WriteLine("ListItem created, updated and delete successfully. All done!"); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } }
/// <summary> /// LoadData() /// </summary> private void Init() { m_constructorClient = new ConstructorIOAPI(txtAPIToken.Text, txtKey.Text); }
private async void btnProcess_Click(object sender, EventArgs e) { pictureBoxLoading.Visible = true; try { bool bResult = false; m_constructorClient = new ConstructorIOAPI(txtAPI.Text, txtKey.Text); ListItem createdItem = GetListItem(); switch (m_sActionValue) { case "Add": bResult = await m_constructorClient.AddAsync(createdItem); break; case "Modify ( name of item )": bResult = await m_constructorClient.ModifyAsync(createdItem); break; case "Delete": bResult = await m_constructorClient.RemoveAsync(createdItem); break; } if(bResult) { MessageBox.Show("Success."); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } pictureBoxLoading.Visible = false; }
private async void btnVerify_Click(object sender, EventArgs e) { m_constructorClient = new ConstructorIOAPI(txtAPI.Text, txtKey.Text); try { bool success = await m_constructorClient.VerifyAsync(); if(success) { MessageBox.Show("Valid Credentials"); } } catch(Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } }
internal Tracker(ConstructorIOAPI ParentAPI) { _parentAPI = ParentAPI; }