/// <summary>
        /// Create an Add Contacts Activity.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="addContacts">AddContacts object.</param>
        /// <returns>Returns an Activity object.</returns>
        public Activity CreateAddContactsActivity(string accessToken, string apiKey, AddContacts addContacts)
        {
            Activity activity = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.AddContactsActivity);
            string json = addContacts.ToJSON();
            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);

            if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

            if(response.HasData)
            {
                activity = response.Get<Activity>();
            }

            return activity;
        }
Example #2
0
        /// <summary>
        /// Create an Add Contacts Activity.
        /// </summary>
        /// <param name="addContacts">AddContacts object.</param>
        /// <returns>Returns an Activity object.</returns>
        public Activity CreateAddContactsActivity(AddContacts addContacts)
        {
            if (addContacts == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ActivityOrId);
            }

            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.AddContactsActivity);
            string json = addContacts.ToJSON();
            RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var activity = response.Get<Activity>();
                return activity;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Example #3
0
        /// <summary>
        /// Create an Add Contacts Activity.
        /// </summary>
        /// <param name="addContacts">AddContacts object.</param>
        /// <returns>Returns an Activity object.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public Activity CreateAddContactsActivity(AddContacts addContacts)
        {
            if (addContacts == null)
            {
                throw new IllegalArgumentException(Config.Errors.ActivityOrId);
            }

            return ActivityService.CreateAddContactsActivity(AccessToken, APIKey, addContacts);
        }
Example #4
0
        public void LiveActivityGetSummaryReportTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);
            var add = new AddContacts(
                new List<AddContactsImportData>{
                    new AddContactsImportData{
                        EmailAddresses = new List<string>{ String.Format("{0}@example.com", Guid.NewGuid()) }
                    }
                },
                new List<string> { "1" },
                null
                );
            Activity act = cc.CreateAddContactsActivity(add);
            Assert.IsNotNull(act);

            IList<Activity> list = cc.GetActivities();
            foreach (Activity activity in list)
            {
                Activity a = cc.GetActivity(activity.Id);
                Assert.IsNotNull(a);
            }
        }
Example #5
0
        public void LiveActivityClearListTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);
            var emailAddresses = new List<string> { String.Format("{0}@example.com", Guid.NewGuid()) };
            var lists = new List<string> { "2" };

            var add = new AddContacts(
                new List<AddContactsImportData>{
                    new AddContactsImportData{
                        EmailAddresses = emailAddresses
                    }
                },
                lists,
                null
                );
            Activity act = cc.CreateAddContactsActivity(add);
            Assert.IsNotNull(act);

            Activity activity = cc.AddClearListsActivity(lists);

            Assert.IsNotNull(activity);
            Assert.AreEqual(activity.Type, "CLEAR_CONTACTS_FROM_LISTS");
        }
Example #6
0
        public void LiveActivityRemoveContactTest()
        {
            var cc = new ConstantContact(ApiKey, AccessToken);
            var emailAddresses = new List<string>{ String.Format("{0}@example.com", Guid.NewGuid()) };
            var lists = new List<string> { "2" };

            var add = new AddContacts(
                new List<AddContactsImportData>{
                    new AddContactsImportData{
                        EmailAddresses = emailAddresses
                    }
                },
                lists,
                null
                );
            Activity act = cc.CreateAddContactsActivity(add);
            Assert.IsNotNull(act);

            Activity activity = cc.AddRemoveContactsFromListsActivity(emailAddresses, lists);

            Assert.IsNotNull(activity);
            Assert.AreEqual(activity.ContactCount, emailAddresses.Count);
        }
Example #7
0
 public void LiveActivityAddContactTest()
 {
     var cc = new ConstantContact(ApiKey, AccessToken);
     var add = new AddContacts(
         new List<AddContactsImportData>{
             new AddContactsImportData{
                 EmailAddresses = new List<string>{ String.Format("{0}@example.com", Guid.NewGuid()) }
             }
         },
         new List<string> { "1" },
         null
         );
     var act = cc.CreateAddContactsActivity(add);
     Assert.IsNotNull(act);
 }
Example #8
0
        public void LiveActivityGetSummaryReportTest()
        {
            var cc = new ConstantContactFactory(userServiceContext);
            var activityService = cc.CreateActivityService();

            var add = new AddContacts(
                new List<AddContactsImportData>{
                    new AddContactsImportData{
                        EmailAddresses = new List<string>{ String.Format("{0}@example.com", Guid.NewGuid()) }
                    }
                },
                new List<string> { "1" }, 
                null
                );
            Activity act = activityService.CreateAddContactsActivity(add);
            Assert.IsNotNull(act);

            IList<Activity> list = activityService.GetActivities();
            Activity a = activityService.GetActivity(list[0].Id);
            Assert.IsNotNull(a);
        }
Example #9
0
        public void LiveActivityRemoveContactsMultipartTest()
        {
            var cc = new ConstantContactFactory(userServiceContext);
            var activityService = cc.CreateActivityService();

            var filename = "remove_contacts.csv";
            var fileContent = String.Format("{0}@example.com", Guid.NewGuid());
            var content = Encoding.UTF8.GetBytes(fileContent);
            var lists = new List<string>() { "1" }; 

            var add = new AddContacts(new List<AddContactsImportData>
                                      {
                                           new AddContactsImportData
                                           {
                                                EmailAddresses = new List<string> { fileContent }
                                           }
                                      }, lists, null);

            Activity act = activityService.CreateAddContactsActivity(add);
            Activity activity = activityService.RemoveContactsMultipartActivity(filename, content, lists);

            Assert.IsNotNull(activity);
            Assert.IsNotNull(activity.Id);
            Assert.AreEqual(activity.ContactCount, 1);
            Assert.AreEqual(activity.Type, "REMOVE_CONTACTS_FROM_LISTS");
        }