Пример #1
0
        /// <summary>
        /// Get bounces for a given contact.
        /// </summary>
        /// <param name="contactId">Contact id.</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
        /// <param name="pag">Pagination object.</param>
        /// <returns>ResultSet containing a results array of @link BounceActivity</returns>
        private ResultSet <BounceActivity> GetBounces(string contactId, int?limit, Pagination pag)
        {
            string         url      = (pag == null) ? ConstructUrl(Settings.Endpoints.Default.ContactTrackingBounces, new object[] { contactId }, new object[] { "limit", limit }) : pag.GetNextUrl();
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var results = response.Get <ResultSet <BounceActivity> >();
                return(results);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Get opt outs for a given contact.
        /// </summary>
        /// <param name="contactId">Contact id.</param>
        /// <param name="limit">Specifies the number of results per page in the output, from 1 - 500, default = 500.</param>
        /// <param name="createdSince">filter for activities created since the supplied date in the collection</param>
        /// <param name="pag">Pagination object.</param>
        /// <returns>ResultSet containing a results array of @link OptOutActivity.</returns>
        private ResultSet <OptOutActivity> GetOptOuts(string contactId, int?limit, DateTime?createdSince, Pagination pag)
        {
            string         url      = (pag == null) ? ConstructUrl(Settings.Endpoints.Default.ContactTrackingUnsubscribes, new object[] { contactId }, new object[] { "limit", limit, "created_since", Extensions.ToISO8601String(createdSince) }) : pag.GetNextUrl();
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var results = response.Get <ResultSet <OptOutActivity> >();
                return(results);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
        /// <summary>
        /// Get a set of campaigns.
        /// </summary>
        /// <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(CampaignStatus?status, int?limit, DateTime?modifiedSince, Pagination pag)
        {
            string         url      = (pag == null) ? String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.Campaigns, GetQueryParameters(new object[] { "status", status, "limit", limit, "modified_since", Extensions.ToISO8601String(modifiedSince) })) : pag.GetNextUrl();
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var results = response.Get <ResultSet <EmailCampaign> >();
                return(results);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #4
0
        /// <summary>
        /// Add files using the multipart content-type
        /// </summary>
        /// <param name="fileName">The file name and extension</param>
        /// <param name="fileType">The file type</param>
        /// <param name="folderId">The id of the folder</param>
        /// <param name="description">The description of the file</param>
        /// <param name="source">The source of the original file</param>
        /// <param name="data">The data contained in the file being uploaded</param>
        /// <returns>Returns the file Id associated with the uploaded file</returns>
        public string AddLibraryFilesMultipart(string fileName, FileType fileType, string folderId, string description, FileSource source, byte[] data)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.FileNameNull);
            }

            var extension = Path.GetExtension(fileName).ToLowerInvariant();

            string[] fileTypes = new string[5] {
                ".jpeg", ".jpg", ".gif", ".png", ".pdf"
            };

            if (!((IList <string>)fileTypes).Contains(extension))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.FileTypeInvalid);
            }

            if (string.IsNullOrEmpty(folderId) || string.IsNullOrEmpty(description))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.FieldNull);
            }

            if (data == null)
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.FileNull);
            }

            string result = null;
            string url    = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.MyLibraryFiles);

            byte[]         content  = MultipartBuilder.CreateMultipartContent(fileName, data, null, fileType.ToString(), folderId, description, source.ToString());
            RawApiResponse response = RestClient.PostMultipart(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, content);

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

            if (!response.IsError && response.StatusCode == System.Net.HttpStatusCode.Accepted)
            {
                string location = response.Headers["Location"];
                int    idStart  = location.LastIndexOf("/") + 1;
                result = location.Substring(idStart);
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// View all existing events
        /// </summary>
        /// <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(int?limit, Pagination pag)
        {
            string url = (pag == null) ? String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.EventSpots, GetQueryParameters(new object[] { "limit", limit })) : pag.GetNextUrl();

            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var individualEventSet = response.Get <ResultSet <IndividualEvent> >();
                return(individualEventSet);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #6
0
        /// <summary>
        /// Update a specific schedule for a campaign.
        /// </summary>
        /// <param name="campaignId">Campaign id to be scheduled.</param>
        /// <param name="schedule">Schedule to retrieve.</param>
        /// <returns>Returns the updated schedule object.</returns>
        public Schedule UpdateSchedule(string campaignId, Schedule schedule)
        {
            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.CampaignSchedule, campaignId, schedule.Id));
            string         json     = schedule.ToJSON();
            RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);

            try
            {
                var upd = response.Get <Schedule>();
                return(upd);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #7
0
        /// <summary>
        /// Gets the status report for an activity by ID
        /// </summary>
        /// <param name="activityId">The activity ID</param>
        /// <returns>The StatusReport</returns>
        public StatusReport GetBulkActivityStatusById(string activityId)
        {
            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Activity, activityId));

            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var bulkStatusReport = response.Get <StatusReport>();
                return(bulkStatusReport);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #8
0
        /// <summary>
        /// Get an array of contacts.
        /// </summary>
        /// <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="status">Match the exact contact status.</param>
        /// <param name="pag">Pagination object.</param>
        /// <returns>Returns a list of contacts.</returns>
        private ResultSet <Contact> GetContacts(string email, int?limit, DateTime?modifiedSince, ContactStatus?status, Pagination pag)
        {
            // Construct access URL
            string url = (pag == null) ? ConstructUrl(Settings.Endpoints.Default.Contacts, null, new object[] { "email", email, "limit", limit, "modified_since", Extensions.ToISO8601String(modifiedSince), "status", status }) : pag.GetNextUrl();
            // Get REST response
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var results = response.Get <ResultSet <Contact> >();
                return(results);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #9
0
        /// <summary>
        /// Get account summary information
        /// </summary>
        /// <returns>An AccountSummaryInformation object</returns>
        public AccountSummaryInformation GetAccountSummaryInformation()
        {
            // Construct access URL
            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.AccountSummaryInformation);

            // Get REST response
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var result = response.Get <AccountSummaryInformation>();
                return(result);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #10
0
        /// <summary>
        ///  Create a Remove Contacts Multipart Activity
        /// </summary>
        /// <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 fileName, byte[] fileContent, IList <string> lists)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FileNameNull);
            }

            var extension = Path.GetExtension(fileName).ToLowerInvariant();

            string[] fileTypes = new string[4] {
                ".txt", ".csv", ".xls", ".xlsx"
            };

            if (!((IList <string>)fileTypes).Contains(extension))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FileTypeInvalid);
            }

            if (fileContent == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.FileNull);
            }

            if (lists == null || lists.Count.Equals(0))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ActivityOrId);
            }

            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.RemoveFromListsActivity);

            byte[]         data     = MultipartBuilder.CreateMultipartContent(fileName, fileContent, lists);
            RawApiResponse response = RestClient.PostMultipart(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, data);

            try
            {
                var activity = response.Get <Activity>();
                return(activity);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #11
0
        /// <summary>
        /// Delete a specific file
        /// </summary>
        /// <param name="fileId">The id of the file</param>
        /// <returns>Returns true if folder was deleted successfully, false otherwise</returns>
        public bool DeleteLibraryFile(string fileId)
        {
            if (string.IsNullOrEmpty(fileId))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.MyLibraryOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.MyLibraryFile, fileId));
            RawApiResponse response = RestClient.Delete(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                return(!response.IsError && response.StatusCode == System.Net.HttpStatusCode.NoContent);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #12
0
        /// <summary>
        /// Delete a contact from all contact lists.
        /// </summary>
        /// <param name="contactId">Contact id to be removed from lists.</param>
        /// <returns>Returns true if operation succeeded.</returns>
        public bool DeleteContactFromLists(string contactId)
        {
            if (string.IsNullOrEmpty(contactId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.ContactOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.ContactLists, contactId));
            RawApiResponse response = RestClient.Delete(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                return(!response.IsError && response.StatusCode == System.Net.HttpStatusCode.NoContent);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #13
0
        /// <summary>
        /// Get a summary of reporting data for a given campaign.
        /// </summary>
        /// <param name="campaignId">Campaign id.</param>
        /// <returns>Tracking summary.</returns>
        public TrackingSummary GetSummary(string campaignId)
        {
            if (string.IsNullOrEmpty(campaignId))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.CampaignTrackingOrId);
            }

            string         url      = ConstructUrl(Settings.Endpoints.Default.CampaignTrackingSummary, new object[] { campaignId }, null);
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var summary = response.Get <TrackingSummary>();
                return(summary);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #14
0
        public Lists CreateList(Lists lists)
        {
            if (lists == null)
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.Lists);
            RawApiResponse response = RestClient.Post(url, UserServiceContext.ApiKey, lists.ToJSON());

            try
            {
                Lists list = response.Get <Lists>();
                return(list);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #15
0
        public Lists GetList(string listId = null)
        {
            if (listId == null)
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = string.Concat(Settings.Endpoints.Default.BaseUrl, string.Format(Settings.Endpoints.Default.Lists, listId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.ApiKey);

            try
            {
                Lists lists = response.Get <Lists>();
                return(lists);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #16
0
        public Dictionary <string, object> AddPersonToList(string listId, KeyValuePair <string, string> personEmail)
        {
            if (personEmail.Key != "email")
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, string.Format(Settings.Endpoints.Default.ListMembers, listId));
            RawApiResponse response = RestClient.PostXwwwFormUrlEncoded(url, UserServiceContext.ApiKey, personEmail.Key + "=" + personEmail.Value);

            try
            {
                Dictionary <string, object> person = response.Get <Dictionary <string, object> >();
                return(person);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #17
0
        /// <summary>
        /// Get campaign details for a specific campaign.
        /// </summary>
        /// <param name="campaignId">Campaign id.</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign GetCampaign(string campaignId)
        {
            if (string.IsNullOrEmpty(campaignId))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.EmailCampaignOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Campaign, campaignId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var campaign = response.Get <EmailCampaign>();
                return(campaign);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #18
0
        /// <summary>
        /// Get status for an upload file
        /// </summary>
        /// <param name="fileId">The id of the file</param>
        /// <returns>Returns a list of FileUploadStatus objects</returns>
        public IList <FileUploadStatus> GetLibraryFileUploadStatus(string fileId)
        {
            if (string.IsNullOrEmpty(fileId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.MyLibraryOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, string.Format(Settings.Endpoints.Default.MyLibraryFileUploadStatus, fileId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var lists = response.Get <IList <FileUploadStatus> >();
                return(lists);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #19
0
        /// <summary>
        /// Get files from a specific folder
        /// </summary>
        /// <param name="folderId">The id of the folder from which to retrieve files</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 MyLibraryFile objects.</returns>
        public ResultSet <MyLibraryFile> GetLibraryFilesByFolder(string folderId, int?limit, Pagination pag)
        {
            if (string.IsNullOrEmpty(folderId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.MyLibraryOrId);
            }

            string         url      = (pag == null) ? String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.MyLibraryFolderFiles, folderId), GetQueryParameters(new object[] { "limit", limit })) : pag.GetNextUrl();
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var results = response.Get <ResultSet <MyLibraryFile> >();
                return(results);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #20
0
        /// <summary>
        /// Get a folder by Id
        /// </summary>
        /// <param name="folderId">The id of the folder</param>
        /// <returns>Returns a MyLibraryFolder object.</returns>
        public MyLibraryFolder GetLibraryFolder(string folderId)
        {
            if (string.IsNullOrEmpty(folderId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.MyLibraryOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.MyLibraryFolder, folderId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var folder = response.Get <MyLibraryFolder>();
                return(folder);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #21
0
        /// <summary>
        /// Get all contacts from an individual list.
        /// </summary>
        /// <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>
        public ResultSet <Contact> GetContactsFromList(string listId, int?limit, DateTime?modifiedSince, Pagination pag)
        {
            if (string.IsNullOrEmpty(listId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.ListOrId);
            }

            string         url      = (pag == null) ? ConstructUrl(Settings.Endpoints.Default.ListContacts, new object[] { listId }, new object[] { "limit", limit, "modified_since", Extensions.ToISO8601String(modifiedSince) }) : pag.GetNextUrl();
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var contacts = response.Get <ResultSet <Contact> >();
                return(contacts);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #22
0
        public Dictionary <string, object> GetPerson(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, string.Format(Settings.Endpoints.Default.Person, id));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.ApiKey);

            try
            {
                Dictionary <string, object> person = response.Get <Dictionary <string, object> >();
                return(person);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #23
0
        /// <summary>
        /// Get an activity.
        /// </summary>
        /// <param name="activityId">The activity identification.</param>
        /// <returns>Returns the activity identified by its id.</returns>
        public Activity GetActivity(string activityId)
        {
            if (string.IsNullOrEmpty(activityId))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ActivityOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Activity, activityId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var activity = response.Get <Activity>();
                return(activity);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #24
0
        /// <summary>
        /// Get activities by email campaign for a given contact.
        /// </summary>
        /// <param name="contactId">Contact id.</param>
        /// <returns>ResultSet containing a results array of @link TrackingSummary</returns>
        public IList <TrackingSummary> GetEmailCampaignActivities(string contactId)
        {
            if (string.IsNullOrEmpty(contactId))
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ContactTrackingOrId);
            }

            string         url      = ConstructUrl(Settings.Endpoints.Default.ContactTrackingEmailCampaignActivities, new object[] { contactId }, null);
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var results = response.Get <IList <TrackingSummary> >();
                return(results);
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Пример #25
0
        /// <summary>
        /// Get a specific schedule for a campaign.
        /// </summary>
        /// <param name="campaignId">Campaign id to be get a schedule for.</param>
        /// <param name="scheduleId">Schedule id to retrieve.</param>
        /// <returns>Returns the requested schedule object.</returns>
        public Schedule GetSchedule(string campaignId, string scheduleId)
        {
            if (string.IsNullOrEmpty(campaignId) || string.IsNullOrEmpty(scheduleId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.ScheduleOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.CampaignSchedule, campaignId, scheduleId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var schedule = response.Get <Schedule>();
                return(schedule);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #26
0
        /// <summary>
        /// Retrieve a list of all the account owner's email addresses
        /// </summary>
        /// <returns>list of all verified account owner's email addresses</returns>
        public IList <VerifiedEmailAddress> GetVerifiedEmailAddress()
        {
            IList <VerifiedEmailAddress> emails = new List <VerifiedEmailAddress>();

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

            // Get REST response
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var result = response.Get <IList <VerifiedEmailAddress> >();
                return(result);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #27
0
        public Dictionary <string, object> AddPerson(Dictionary <string, object> person)
        {
            if (person == null)
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, string.Format(Settings.Endpoints.Default.Person, person.Where(x => x.Key == "id")));
            RawApiResponse response = RestClient.Put(url, UserServiceContext.ApiKey, JsonConvert.SerializeObject(person));

            try
            {
                Dictionary <string, object> newPerson = response.Get <Dictionary <string, object> >();
                return(person);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #28
0
        public bool ExcludeOrUnscribe(string email)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = string.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.ListsExclusions);
            RawApiResponse response = RestClient.PostXwwwFormUrlEncoded(url, UserServiceContext.ApiKey, HttpUtility.UrlEncode("email" + "=" + email));

            try
            {
                var excludeUnsubscribeResponse = response.Get <Dictionary <string, bool> >();
                return(true);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #29
0
        /// <summary>
        /// Get contact details for a specific contact.
        /// </summary>
        /// <param name="contactId">Unique contact id.</param>
        /// <returns>Returns a contact.</returns>
        public Contact GetContact(string contactId)
        {
            if (string.IsNullOrEmpty(contactId))
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.ContactOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Contact, contactId));
            RawApiResponse response = RestClient.Get(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey);

            try
            {
                var contact = response.Get <Contact>();
                return(contact);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }
Пример #30
0
        public Lists UpdateList(KeyValuePair <string, string> listInfo)
        {
            if (listInfo.Equals(new KeyValuePair <string, string>()))
            {
                throw new IllegalArgumentException(Resources.Errors.GeneralId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.List);
            RawApiResponse response = RestClient.PostXwwwFormUrlEncoded(url, UserServiceContext.ApiKey, listInfo.Key + "=" + listInfo.Value);

            try
            {
                Lists list = response.Get <Lists>();
                return(list);
            }
            catch (Exception ex)
            {
                throw new KlaviyoException(ex.ToString());
            }
        }
Пример #31
0
        /// <summary>
        /// Makes a HTTP request to the Endpoint specified in urlParam and using the HTTP method specified by httpMethod.
        /// </summary>
        /// <param name="url">Url</param>
        /// <param name="method">Method</param>
        /// <param name="contentType">ContentType</param>
        /// <param name="accessToken">AccessToken</param>
        /// <param name="apiKey">ApiKey</param>
        /// <param name="data">Data if any</param>
        /// <returns>RawApiResponse</returns>
        public RawApiResponse HttpRequest(string url, HttpMethod method, IContentType contentType, string accessToken, string apiKey, byte[] data)
        {
            var address = url;

            if (!string.IsNullOrEmpty(apiKey))
            {
                address = string.Format("{0}{1}api_key={2}", url, url.Contains("?") ? "&" : "?", apiKey);
            }

            HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

            request.Method = method.ToString();
            request.Accept = JSON_CONTENT_TYPE;
            request.Headers[X_CTCT_REQUEST_SOURCE_HEADER] = "sdk.NET." + GetWrapperAssemblyVersion().ToString();
            request.ContentType = contentType.Value;

            // Add token as HTTP header
            request.Headers.Add(AUTHORIZATION_HEADER, "Bearer " + accessToken);

            if (data != null)
            {
                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }

            // Initialize the response
            HttpWebResponse response = null;
            RawApiResponse rawApiResponse = new RawApiResponse();

            // Now try to send the request
            try
            {
                response = request.GetResponse() as HttpWebResponse;
                // Expect the unexpected
                if (request.HaveResponse == true && response == null)
                {
                    throw new WebException("Response was not returned or is null");
                }
                foreach (string header in response.Headers.AllKeys)
                {
                    rawApiResponse.Headers.Add(header, response.GetResponseHeader(header));
                }

                rawApiResponse.StatusCode = response.StatusCode;

                if (response.StatusCode != HttpStatusCode.OK &&
                    response.StatusCode != HttpStatusCode.Created &&
                    response.StatusCode != HttpStatusCode.Accepted &&
                    response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new WebException("Response with status: " + response.StatusCode + " " + response.StatusDescription);
                }
            }
            catch (WebException e)
            {
                response = e.Response as HttpWebResponse;
                rawApiResponse.IsError = true;
            }
            finally
            {
                if (response != null)
                {
                    string responseText = null;

                    // Get the response content
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        responseText = reader.ReadToEnd();
                    }
                    response.Close();
                    if (rawApiResponse.IsError && responseText.Contains("error_message"))
                    {
                        rawApiResponse.Info = RawApiRequestError.FromJSON<IList<RawApiRequestError>>(responseText);
                    }
                    else
                    {
                        rawApiResponse.Body = responseText;
                    }
                }
            }

            return rawApiResponse;
        }