Beispiel #1
0
        /// <summary>
        /// Update a specific email campaign.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="campaign">Campaign to be updated.</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign UpdateCampaign(string accessToken, string apiKey, EmailCampaign campaign)
        {
            EmailCampaign emailCampaign = null;
            string        url           = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Campaign, campaign.Id));

            // Invalidate data that are not supported by the update API procedure
            campaign.CreatedDate     = null;
            campaign.TrackingSummary = null;
            campaign.ModifiedDate    = null;
            campaign.IsVisibleInUI   = null;
            // Convert to JSON string
            string       json     = campaign.ToJSON();
            CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json);

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

            if (response.HasData)
            {
                emailCampaign = response.Get <EmailCampaign>();
            }

            return(emailCampaign);
        }
Beispiel #2
0
        /// <summary>
        /// Get an activity.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="activityId">The activity identification.</param>
        /// <param name="status">The activity status.</param>
        /// <param name="type">The activity type.</param>
        /// <returns>Returns the activity identified by its id.</returns>
        public IList <Activity> GetDetailedReport(string accessToken, string apiKey, string activityId, ActivityStatus?status, ActivityType?type)
        {
            IList <Activity> activities = new List <Activity>();
            string           url        = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Activities);

            if (status != null)
            {
                url = String.Concat(url, "?status=", status.ToString());
            }
            if (type != null)
            {
                url = String.Concat(url, (status != null) ? "&type=" : "?type=", type.ToString());
            }
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

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

            return(activities);
        }
Beispiel #3
0
        /// <summary>
        /// Removes contacts from one ore more contact lists.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="emailAddresses">List of email addresses.</param>
        /// <param name="lists">List of id's.</param>
        /// <returns>Returns an Activity object.</returns>
        public Activity RemoveContactsFromLists(string accessToken, string apiKey, IList <string> emailAddresses, IList <string> lists)
        {
            Activity      activity      = null;
            string        url           = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.RemoveFromListsActivity);
            RemoveContact removeContact = new RemoveContact()
            {
                ImportData = new List <ImportEmailAddress>()
                {
                    new ImportEmailAddress()
                    {
                        EmailAddresses = emailAddresses
                    }
                },
                Lists = lists
            };

            string       json     = removeContact.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);
        }
        /// <summary>
        /// View all existing events
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 50</param>
        /// <param name="pag">Pagination object</param>
        /// <returns>ResultSet containing a results array of IndividualEvents</returns>
        public ResultSet <IndividualEvent> GetAllEventSpots(string accessToken, string apiKey, int?limit, Pagination pag)
        {
            string url = (pag == null) ? String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventSpots, GetQueryParameters(new object[] { "limit", limit })) : pag.GetNextUrl();

            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                return(response.Get <ResultSet <IndividualEvent> >());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new ResultSet <IndividualEvent>());
        }
        /// <summary>
        /// Retrieve all existing attributes for an item
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="itemId">EventItem id</param>
        /// <returns>A list of Attributes</returns>
        public List <CTCT.Components.EventSpot.Attribute> GetAllEventItemAttributes(string accessToken, string apiKey, string eventId, string itemId)
        {
            string url = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.ItemAttribute), eventId, itemId, null);

            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                return(response.Get <List <CTCT.Components.EventSpot.Attribute> >());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new List <CTCT.Components.EventSpot.Attribute>());
        }
        /// <summary>
        /// Publish an event
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventSpot">The event to publish</param>
        /// <returns>The published event</returns>
        public IndividualEvent PostEventSpot(string accessToken, string apiKey, IndividualEvent eventSpot)
        {
            string       url      = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventSpots);
            string       json     = eventSpot.ToJSON();
            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);

            if (response.HasData)
            {
                return(response.Get <IndividualEvent>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new IndividualEvent());
        }
        /// <summary>
        ///  Retrieve specific event item
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="itemId">Eventitem id</param>
        /// <returns>EventItem object</returns>
        public EventItem GetEventItem(string accessToken, string apiKey, string eventId, string itemId)
        {
            string url = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventItem), eventId, itemId);

            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                return(response.Get <EventItem>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new EventItem());
        }
        /// <summary>
        /// Retrieve an event specified by the event_id
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <returns>The event</returns>
        public IndividualEvent GetEventSpot(string accessToken, string apiKey, string eventId)
        {
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventSpots, "/", eventId);

            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                return(response.Get <IndividualEvent>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new IndividualEvent());
        }
        /// <summary>
        /// Retrieve a list of registrants for the specified event
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <returns>ResultSet containing a results array of Registrant</returns>
        public ResultSet <Registrant> GetAllRegistrants(string accessToken, string apiKey, string eventId)
        {
            string url = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventRegistrant), eventId, null);

            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                return(response.Get <ResultSet <Registrant> >());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new ResultSet <Registrant>());
        }
        /// <summary>
        /// Retrieve an existing promo codes for an event
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="promocodeId">Promocode id</param>
        /// <returns>The Promocode object</returns>
        public Promocode GetPromocode(string accessToken, string apiKey, string eventId, string promocodeId)
        {
            string url = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventPromocode), eventId, promocodeId);

            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                return(response.Get <Promocode>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new Promocode());
        }
        /// <summary>
        /// Updates an existing attributes for an item
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="itemId">EventItem id</param>
        /// <param name="attributeId">Attribute id</param>
        /// <param name="attribute">Attribute new values</param>
        /// <returns>The newly updated attribute</returns>
        public CTCT.Components.EventSpot.Attribute PutEventItemAttribute(string accessToken, string apiKey, string eventId, string itemId, string attributeId, CTCT.Components.EventSpot.Attribute attribute)
        {
            string url  = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.ItemAttribute), eventId, itemId, attributeId);
            string json = attribute.ToJSON();

            CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json);

            if (response.HasData)
            {
                return(response.Get <CTCT.Components.EventSpot.Attribute>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new CTCT.Components.EventSpot.Attribute());
        }
        /// <summary>
        ///  Create a specific event item
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="eventItem">EventItem id</param>
        /// <returns>The newly created EventItem</returns>
        public EventItem PostEventItem(string accessToken, string apiKey, string eventId, EventItem eventItem)
        {
            string url  = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventItem), eventId, null);
            string json = eventItem.ToJSON();

            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);

            if (response.HasData)
            {
                return(response.Get <EventItem>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new EventItem());
        }
        /// <summary>
        /// Get a set of campaigns.
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="status">Returns list of email campaigns with specified status.</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
        /// <param name="modifiedSince">limit campaigns to campaigns modified since the supplied date</param>
        /// <param name="pag">Pagination object returned by a previous call to GetCampaigns</param>
        /// <returns>Returns a ResultSet of campaigns.</returns>
        public ResultSet <EmailCampaign> GetCampaigns(string accessToken, string apiKey, CampaignStatus?status, int?limit, DateTime?modifiedSince, Pagination pag)
        {
            ResultSet <EmailCampaign> results = null;
            string       url      = (pag == null) ? String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Campaigns, GetQueryParameters(new object[] { "status", status, "limit", limit, "modified_since", Extensions.ToISO8601String(modifiedSince) })) : pag.GetNextUrl();
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                results = response.Get <ResultSet <EmailCampaign> >();
            }

            return(results);
        }
        /// <summary>
        /// Create a new promo code for an event
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="promocode">Promocode object to be created</param>
        /// <returns>The newly created Promocode</returns>
        public Promocode PostPromocode(string accessToken, string apiKey, string eventId, Promocode promocode)
        {
            string url = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventPromocode), eventId, null);

            string json = promocode.ToJSON();

            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);

            if (response.HasData)
            {
                return(response.Get <Promocode>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new Promocode());
        }
Beispiel #15
0
        /// <summary>
        /// Create a new campaign.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="campaign">Campign to be created</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign AddCampaign(string accessToken, string apiKey, EmailCampaign campaign)
        {
            EmailCampaign emailcampaign = null;
            string        url           = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Campaigns);
            string        json          = campaign.ToJSON();
            CUrlResponse  response      = RestClient.Post(url, accessToken, apiKey, json);

            if (response.HasData)
            {
                emailcampaign = response.Get <EmailCampaign>();
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

            return(emailcampaign);
        }
Beispiel #16
0
        /// <summary>
        /// Get campaign details for a specific campaign.
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="campaignId">Campaign id.</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign GetCampaign(string accessToken, string apiKey, string campaignId)
        {
            EmailCampaign campaign = null;
            string        url      = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Campaign, campaignId));
            CUrlResponse  response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                campaign = response.Get <EmailCampaign>();
            }

            return(campaign);
        }
Beispiel #17
0
        /// <summary>
        /// Get all contacts from an individual list.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="listId">List id to retrieve contacts for.</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
        /// <param name="modifiedSince">limit contacts retrieved to contacts modified since the supplied date</param>
        /// <param name="pag">Pagination object.</param>
        /// <returns>Returns a list of contacts.</returns>
        private ResultSet <Contact> GetContactsFromList(string accessToken, string apiKey, string listId, int?limit, DateTime?modifiedSince, Pagination pag)
        {
            var          contacts = new ResultSet <Contact>();
            string       url      = (pag == null) ? Config.ConstructUrl(Config.Endpoints.ListContacts, new object[] { listId }, new object[] { "limit", limit, "modified_since", Extensions.ToISO8601String(modifiedSince) }) : pag.GetNextUrl();
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                contacts = response.Get <ResultSet <Contact> >();
            }

            return(contacts);
        }
Beispiel #18
0
        /// <summary>
        /// Get all existing MyLibrary folders
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="sortBy">Specifies how the list of folders is sorted</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 50, default = 50.</param>
        /// <param name="pag">Pagination object.</param>
        /// <returns>Returns a collection of MyLibraryFolder objects.</returns>
        public ResultSet <MyLibraryFolder> GetLibraryFolders(string accessToken, string apiKey, FoldersSortBy?sortBy, int?limit, Pagination pag)
        {
            ResultSet <MyLibraryFolder> results = null;
            string       url      = (pag == null) ? String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.MyLibraryFolders, GetQueryParameters(new object[] { "sort_by", sortBy, "limit", limit })) : pag.GetNextUrl();
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                results = response.Get <ResultSet <MyLibraryFolder> >();
            }

            return(results);
        }
        /// <summary>
        /// Update an individual event fee
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="eventId">Event id</param>
        /// <param name="feeId">EventFee id</param>
        /// <param name="eventFee">The new values of EventFee</param>
        /// <returns>The updated EventFee</returns>
        public EventFee PutEventFee(string accessToken, string apiKey, string eventId, string feeId, EventFee eventFee)
        {
            string url = String.Format(String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.EventFees), eventId, feeId);

            string json = eventFee.ToJSON();

            CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json);

            if (response.HasData)
            {
                return(response.Get <EventFee>());
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new EventFee());
        }
Beispiel #20
0
        /// <summary>
        /// Returns the status of the specified activity.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application.</param>
        /// <param name="activityId">The activity id.</param>
        /// <returns></returns>
        public Activity GetActivity(string accessToken, string apiKey, string activityId)
        {
            Activity     activity = null;
            string       url      = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Activity, activityId));
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

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

            return(activity);
        }
Beispiel #21
0
        /// <summary>
        /// Returns a list with the last 50 bulk activities.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <returns>Returns the list of activities.</returns>
        public IList <Activity> GetLast50BulkActivities(string accessToken, string apiKey)
        {
            IList <Activity> activities = new List <Activity>();
            string           url        = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Activities);
            CUrlResponse     response   = RestClient.Get(url, accessToken, apiKey);

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

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

            return(activities);
        }
Beispiel #22
0
        /// <summary>
        /// Get status for an upload file
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="fileId">The id of the file</param>
        /// <returns>Returns a list of FileUploadStatus objects</returns>
        public IList <FileUploadStatus> GetLibraryFileUploadStatus(string accessToken, string apiKey, string fileId)
        {
            IList <FileUploadStatus> lists = null;
            string       url      = String.Concat(Config.Endpoints.BaseUrl, string.Format(Config.Endpoints.MyLibraryFileUploadStatus, fileId));
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                lists = response.Get <IList <FileUploadStatus> >();
            }

            return(lists);
        }
Beispiel #23
0
        /// <summary>
        /// Get MyLibrary usage information
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <returns>Returns a MyLibraryInfo object</returns>
        public MyLibraryInfo GetLibraryInfo(string accessToken, string apiKey)
        {
            MyLibraryInfo result   = null;
            string        url      = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.MyLibraryInfo);
            CUrlResponse  response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                result = response.Get <MyLibraryInfo>();
            }

            return(result);
        }
Beispiel #24
0
        /// <summary>
        /// Adds or updates contacts to one or more contact lists.
        /// </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 AddContacts(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);
        }
Beispiel #25
0
        /// <summary>
        /// Get a set of campaigns.
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="status">Returns list of email campaigns with specified status.</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
        /// <returns>Returns a list of campaigns.</returns>
        public IList <EmailCampaign> GetCampaigns(string accessToken, string apiKey, CampaignStatus?status, int?limit)
        {
            IList <EmailCampaign> campaigns = new List <EmailCampaign>();
            string       url      = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Campaigns, GetQueryParameters(new object[] { "status", status, "limit", limit }));
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                ResultSet <EmailCampaign> res = response.Get <ResultSet <EmailCampaign> >();
                campaigns = res.Results;
            }

            return(campaigns);
        }
Beispiel #26
0
        /// <summary>
        /// Get account summary information
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <returns>An AccountSummaryInformation object</returns>
        public AccountSummaryInformation GetAccountSummaryInformation(string accessToken, string apiKey)
        {
            // Construct access URL
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.AccountSummaryInformation);

            // Get REST response
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                AccountSummaryInformation result = response.Get <AccountSummaryInformation>();
                return(result);
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }
            return(new AccountSummaryInformation());
        }
Beispiel #27
0
        /// <summary>
        ///  Create a Remove Contacts Multipart Activity
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>>
        /// <param name="fileName">The file name to be imported</param>
        /// <param name="fileContent">The file content to be imported</param>
        /// <param name="lists">Array of list's id</param>
        /// <returns>Returns an Activity object.</returns>
        public Activity RemoveContactsMultipartActivity(string accessToken, string apiKey, string fileName, byte[] fileContent, IList <string> lists)
        {
            Activity activity = null;
            string   url      = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.RemoveFromListsActivity);

            byte[]       data     = MultipartBuilder.CreateMultipartContent(fileName, fileContent, lists);
            CUrlResponse response = RestClient.PostMultipart(url, accessToken, apiKey, data);

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

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

            return(activity);
        }
        /// <summary>
        /// Get an array of contacts.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="email">Match the exact email address.</param>
        /// <param name="limit">Limit the number of returned values.</param>
        /// <param name="modifiedSince">limit contact to contacts modified since the supplied date</param>
        /// <param name="pag">Pagination object.</param>
        /// <returns>Returns a list of contacts.</returns>
        private ResultSet <Contact> GetContacts(string accessToken, string apiKey, string email, int?limit, DateTime?modifiedSince, Pagination pag)
        {
            ResultSet <Contact> results = null;
            // Construct access URL
            string url = (pag == null) ? Config.ConstructUrl(Config.Endpoints.Contacts, null, new object[] { "email", email, "limit", limit, "modified_since", Extensions.ToISO8601String(modifiedSince) }) : pag.GetNextUrl();
            // Get REST response
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

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

            if (response.HasData)
            {
                // Convert from JSON
                results = response.Get <ResultSet <Contact> >();
            }

            return(results);
        }
Beispiel #29
0
        /// <summary>
        /// Removes contacts from one ore more contact lists.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application.</param>
        /// <param name="filename">Multipart file name.</param>
        /// <param name="lists">List of id's.</param>
        /// <returns>Returns an Activity object.</returns>
        public Activity RemoveContactsMultipart(string accessToken, string apiKey, string filename, IList <string> lists)
        {
            Activity            activity = null;
            string              url      = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.RemoveFromListsActivity);
            NameValueCollection nvc      = new NameValueCollection();

            nvc.Add("file_name", Path.GetFileName(filename));
            nvc.Add("lists", String.Join(",", lists.ToArray()));
            CUrlResponse response = RestClient.HttpPostMultipart(url, accessToken, apiKey, filename, nvc);

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

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

            return(activity);
        }
Beispiel #30
0
        /// <summary>
        /// Retrieve a list of all the account owner's email addresses
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <returns>list of all verified account owner's email addresses</returns>
        public IList <VerifiedEmailAddress> GetVerifiedEmailAddress(string accessToken, string apiKey)
        {
            IList <VerifiedEmailAddress> emails = new List <VerifiedEmailAddress>();

            // Construct access URL
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.AccountVerifiedEmailAddressess);

            // Get REST response
            CUrlResponse response = RestClient.Get(url, accessToken, apiKey);

            if (response.HasData)
            {
                IList <VerifiedEmailAddress> result = response.Get <IList <VerifiedEmailAddress> >();
                return(result);
            }
            else
            if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

            return(emails);
        }