예제 #1
0
        /// <summary>
        /// Delete a contact from all contact lists.
        /// </summary>
        /// <param name="contact">Contact object.</param>
        /// <param name="list">List object.</param>
        /// <returns>Returns true if operation succeeded.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public bool DeleteContactFromList(Contact contact, ContactList list)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(Config.Errors.ContactOrId);
            }
            if (list == null)
            {
                throw new IllegalArgumentException(Config.Errors.ListOrId);
            }

            return this.DeleteContactFromList(contact.Id, list.Id);
        }
예제 #2
0
        /// <summary>
        /// Update an individual contact.
        /// </summary>
        /// <param name="contact">Contact to update.</param>
        /// <param name="actionByVisitor">Set to true if action by visitor.</param>
        /// <returns>Returns the updated contact.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public Contact UpdateContact(Contact contact, bool actionByVisitor)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(Config.Errors.ContactOrId);
            }

            return ContactService.UpdateContact(AccessToken, APIKey, contact, actionByVisitor);
        }
예제 #3
0
        public void LiveAddContactTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);

            var contact = new Contact();
            contact.EmailAddresses.Add(new EmailAddress { EmailAddr = String.Format("{0}@email.com", Guid.NewGuid()), ConfirmStatus = ConfirmStatus.NoConfirmationRequired, Status = Status.Active });
            contact.Lists.Add(new ContactList { Id = "1", Status = Status.Active });

            var nc = cc.AddContact(contact, false);
            Assert.IsNotNull(nc);
            Assert.IsNotNull(nc.Id);
        }
예제 #4
0
        /// <summary>
        /// Sets an individual contact to 'Unsubscribed' status.
        /// </summary>
        /// <param name="contact">Contact object.</param>
        /// <returns>Returns true if operation succeeded.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public bool DeleteContact(Contact contact)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(Config.Errors.ContactOrId);
            }

            return this.DeleteContact(contact.Id);
        }
예제 #5
0
        public void LiveUpdateContactTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);

            var contact = new Contact();
            contact.EmailAddresses.Add(new EmailAddress { EmailAddr = String.Format("{0}@email.com", Guid.NewGuid()), ConfirmStatus = ConfirmStatus.NoConfirmationRequired, Status = Status.Active });
            contact.Lists.Add(new ContactList { Id = "1", Status = Status.Active });

            var nc = cc.AddContact(contact, false);
            Assert.IsNotNull(nc);
            Assert.IsNotNull(nc.Id);

            nc.CompanyName = "some company";

            var retrievedContact = cc.UpdateContact(nc, false);

            Assert.IsNotNull(retrievedContact);
            Assert.AreEqual(retrievedContact.Id, nc.Id);
            Assert.AreEqual(retrievedContact.CompanyName, nc.CompanyName);
        }
예제 #6
0
        public void LiveGetContactByEmail()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);

            var contact = new Contact();
            contact.EmailAddresses.Add(new EmailAddress { EmailAddr = String.Format("{0}@email.com", Guid.NewGuid()), ConfirmStatus = ConfirmStatus.NoConfirmationRequired, Status = Status.Active });
            contact.Lists.Add(new ContactList { Id = "1", Status = Status.Active });

            Contact nc = cc.AddContact(contact, false);
            Assert.IsNotNull(nc);
            Assert.IsNotNull(nc.Id);

            var result = cc.GetContacts(nc.EmailAddresses[0].EmailAddr, 1, DateTime.Now.AddMonths(-1));
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Results);
            Assert.AreEqual(1, result.Results.Count);
        }
예제 #7
0
        /// <summary>
        /// Delete a contact from all contact lists.
        /// </summary>
        /// <param name="contact">Contact object.</param>
        /// <param name="list">List object.</param>
        /// <returns>Returns true if operation succeeded.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public bool DeleteContactFromList(Contact contact, ContactList list)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(Config.Errors.ContactOrId);
            }
            if (list == null)
            {
                throw new IllegalArgumentException(Config.Errors.ListOrId);
            }

            return ContactService.DeleteContactFromList(AccessToken, APIKey, contact.Id, list.Id);
        }
예제 #8
0
        public void LiveAddContactTest()
        {
            var cc = new ConstantContactFactory(userServiceContext);
            var contactService = cc.CreateContactService();

            var contact = new Contact();
            contact.EmailAddresses.Add(new EmailAddress { EmailAddr = String.Format("{0}@email.com", Guid.NewGuid()), ConfirmStatus = ConfirmStatus.NoConfirmationRequired, Status = Status.Active });
            contact.Lists.Add(new ContactList { Id = "1", Status = Status.Active });

            var nc = contactService.AddContact(contact, false);
            Assert.IsNotNull(nc);
            Assert.IsNotNull(nc.Id);
        }
예제 #9
0
 /// <summary>
 /// Add a new contact to an account.
 /// </summary>
 /// <param name="contact">Contact to add.</param>
 /// <param name="actionByVisitor">Set to true if action by visitor.</param>
 /// <returns>Returns the newly created contact.</returns>
 public Contact AddContact(Contact contact, bool actionByVisitor)
 {
     return ContactService.AddContact(AccessToken, APIKey, contact, actionByVisitor);
 }
예제 #10
0
파일: Form1.cs 프로젝트: lokygb/.net-sdk
        /// <summary>
        ///Update contact fields based on completed form fields
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        private Contact UpdateContactFields(Contact contact)
        {
            if (contact == null)
            {
                contact = new Contact();

                //add lists [Required]
                contact.Lists.Add(new ContactList() { Id = "1", Status = Status.Active });

                //add email_addresses [Required]
                var emailAddress = new EmailAddress() { 
                    Status = Status.Active, 
                    ConfirmStatus = ConfirmStatus.NoConfirmationRequired, 
                    EmailAddr = txtEmail.Text.Trim() 
                };
                contact.EmailAddresses.Add(emailAddress);   
            }

            contact.Status = Status.Active;

            #region Contact Information

            if (!string.IsNullOrWhiteSpace(txtFirstName.Text))
            {
                contact.FirstName = txtFirstName.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtMiddleName.Text))
            {
                contact.MiddleName = txtMiddleName.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtLastName.Text))
            {
                contact.LastName = txtLastName.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtHomePhone.Text))
            {
                contact.HomePhone = txtHomePhone.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtCity.Text) || !string.IsNullOrWhiteSpace(txtAddressLine1.Text) || 
                !string.IsNullOrWhiteSpace(txtAddressLine2.Text) || !string.IsNullOrWhiteSpace(txtAddressLine3.Text) ||
                !string.IsNullOrWhiteSpace(txtZip.Text) || !string.IsNullOrWhiteSpace(txtSubZip.Text) ||
                (cbCountry.SelectedItem != null))
            {
                Address address;

                if (contact.Addresses == null || contact.Addresses.Count() == 0)
                {
                    address = new Address();
                }
                else
                {
                    address = contact.Addresses[0];
                }

                if (!string.IsNullOrWhiteSpace(txtCity.Text))
                {
                    address.City = txtCity.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtAddressLine1.Text))
                {
                    address.Line1 = txtAddressLine1.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtAddressLine2.Text))
                {
                    address.Line2 = txtAddressLine2.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtAddressLine3.Text))
                {
                    address.Line3 = txtAddressLine3.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtZip.Text))
                {
                    address.PostalCode = txtZip.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtSubZip.Text))
                {
                    address.SubPostalCode = txtSubZip.Text.Trim();
                }

                if (cbCountry.SelectedItem != null)
                {
                    CountryInfo selectedCountry = cbCountry.SelectedItem as CountryInfo;
                    if (selectedCountry != null)
                    {
                        address.CountryCode = selectedCountry.TwoLetterCountryName;
                    }
                }

                if (contact.Addresses.Count() == 0)
                {
                    contact.Addresses.Add(address);
                }
                else
                {
                    contact.Addresses[0] = address;
                }
            }

            #endregion Contact Information

            #region Company Information

            if (!string.IsNullOrWhiteSpace(txtCompanyName.Text))
            {
                contact.CompanyName = txtCompanyName.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtJobTitle.Text))
            {
                contact.JobTitle = txtJobTitle.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtWorkPhone.Text))
            {
                contact.WorkPhone = txtWorkPhone.Text.Trim();
            }

            #endregion Company Information

            #region Notes

            if (!string.IsNullOrWhiteSpace(txtNotes.Text))
            {
                Note note = new Note();
                note.Content = txtNotes.Text.Trim();
                note.Id = "1";

                contact.Notes = new Note[] { note };
            }

            #endregion Notes

            return contact;
        }
예제 #11
0
        /// <summary>
        /// Update contact details for a specific contact.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="contact">Contact to be updated.</param>
        /// <param name="actionByVisitor">Set to true if action by visitor.</param>
        /// <returns>Returns the updated contact.</returns>
        public Contact UpdateContact(string accessToken, string apiKey, Contact contact, bool actionByVisitor)
        {
            Contact updateContact = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Contact, contact.Id), actionByVisitor ? String.Format("?action_by={0}", ActionBy.ActionByVisitor) : null);
            string json = contact.ToJSON();
            CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json);
            if (response.HasData)
            {
                updateContact = Component.FromJSON<Contact>(response.Body);
            }
            else
                if (response.IsError) {
                    throw new CtctException(response.GetErrorMessage());
                }

            return updateContact;
        }
예제 #12
0
        /// <summary>
        /// Update contact details for a specific contact.
        /// </summary>
        /// <param name="contact">Contact to be updated.</param>
        /// <param name="actionByVisitor">Set to true if action by visitor.</param>
        /// <returns>Returns the updated contact.</returns>
        public Contact UpdateContact(Contact contact, bool actionByVisitor)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ContactOrId);
            }

            if (contact.Id == null)
            {
                throw new CtctException(CTCT.Resources.Errors.UpdateId);
            }
            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Contact, contact.Id), actionByVisitor ? String.Format("?action_by={0}", ActionBy.ActionByVisitor) : null);
            string json = contact.ToJSON();
            RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var updateContact = response.Get<Contact>();
                return updateContact;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }  
        }
예제 #13
0
        /// <summary>
        /// Delete a contact from all contact lists.
        /// </summary>
        /// <param name="contact">The Contact</param>
        /// <returns>Returns true if operation succeeded.</returns>
        public bool DeleteContactFromLists(Contact contact)
        {
            if (contact == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ContactOrId);
            }

            return DeleteContactFromLists(contact.Id);
        }