Beispiel #1
0
        /// <summary>
        /// Add a new list.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="list">Contact list.</param>
        /// <returns>Returns the newly created list.</returns>
        public ContactList AddList(string accessToken, string apiKey, ContactList list)
        {
            ContactList newList = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Lists);
            string json = list.ToJSON();
            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);

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

            if (response.HasData)
            {
                newList = Component.FromJSON<ContactList>(response.Body);
            }

            return newList;
        }
Beispiel #2
0
        /// <summary>
        /// Add a new list.
        /// </summary>
        /// <param name="list">Contact list.</param>
        /// <returns>Returns the newly created list.</returns>
        public ContactList AddList(ContactList list)
        {
            if (list == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.ListOrId);
            }

            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.Lists);
            string json = list.ToJSON();
            RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var newList = response.Get<ContactList>();
                return newList;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }