Ejemplo n.º 1
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);
        }
Ejemplo n.º 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);
            }
        }