Exemple #1
0
        /// <summary>
        /// Update a specific file
        /// </summary>
        /// <param name="accessToken">Access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="file">File to be updated</param>
        /// <param name="includePayload">Determines if update's folder JSON payload is returned</param>
        /// <returns>Returns a MyLibraryFile object.</returns>
        public MyLibraryFile UpdateLibraryFile(string accessToken, string apiKey, MyLibraryFile file, bool?includePayload)
        {
            MyLibraryFile updatedFile = null;
            string        url         = String.Concat(Config.Endpoints.BaseUrl, string.Format(Config.Endpoints.MyLibraryFile, file.Id), GetQueryParameters(new object[] { "include_payload", includePayload }));
            string        json        = file.ToJSON();
            CUrlResponse  response    = RestClient.Put(url, accessToken, apiKey, json);

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

            if (response.HasData)
            {
                updatedFile = Component.FromJSON <MyLibraryFile>(response.Body);
            }

            return(updatedFile);
        }
        /// <summary>
        /// Update a specific file
        /// </summary>
        /// <param name="file">File to be updated</param>
        /// <param name="includePayload">Determines if update's folder JSON payload is returned</param>
        /// <returns>Returns a MyLibraryFile object.</returns>
        public MyLibraryFile UpdateLibraryFile(MyLibraryFile file, bool?includePayload)
        {
            if (file == null)
            {
                throw new IllegalArgumentException(ConstantContactClient.Resources.Errors.MyLibraryOrId);
            }

            string         url      = String.Concat(Settings.Endpoints.Default.BaseUrl, string.Format(Settings.Endpoints.Default.MyLibraryFile, file.Id), GetQueryParameters(new object[] { "include_payload", includePayload }));
            string         json     = file.ToJSON();
            RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);

            try
            {
                var updatedFile = response.Get <MyLibraryFile>();
                return(updatedFile);
            }
            catch (Exception ex)
            {
                throw new ConstantContactClientException(ex.Message, ex);
            }
        }