Example #1
0
        /// <summary>
        /// Saves media async. If MediaId is specified in the query a new version of the asset
        /// will be saved. Otherwise a new asset will be saved.
        /// </summary>
        /// <param name="query">Query with necessary information to save the asset</param>
        /// <returns>Task that represents the save</returns>
        private async Task <SaveMediaResponse> SaveMediaAsync(SaveMediaQuery query)
        {
            query.Filename = Path.GetFileName(query.Filename);

            string path = null;

            if (query.MediaId == null)
            {
                path = $"/api/v4/media/save/{query.ImportId}/";
            }
            else
            {
                path = $"/api/v4/media/{query.MediaId}/save/{query.ImportId}/";
            }

            var request = new ApiRequest <SaveMediaResponse>
            {
                Path       = path,
                HTTPMethod = HttpMethod.Post,
                Query      = query
            };

            // No need to check response. It will only gets here if SaveMedia call gets a success code response
            return(await _requestSender.SendRequestAsync(request).ConfigureAwait(false));
        }
        /// <summary>
        /// Saves media async. If MediaId is specified in the query a new version of the asset
        /// will be saved. Otherwise a new asset will be saved.
        /// </summary>
        /// <param name="query">Query with necessary information to save the asset</param>
        /// <returns>Task that represents the save</returns>
        private Task SaveMediaAsync(SaveMediaQuery query)
        {
            query.Filename = Path.GetFileName(query.Filename);

            string path = null;

            if (query.MediaId == null)
            {
                path = $"/api/v4/media/save/{query.ImportId}/";
            }
            else
            {
                path = $"/api/v4/media/{query.MediaId}/save/{query.ImportId}/";
            }

            var request = new ApiRequest <string>
            {
                Path                = path,
                HTTPMethod          = HttpMethod.Post,
                Query               = query,
                DeserializeResponse = false
            };

            // No need to check response. It will only gets here if SaveMedia call gets a success code response
            return(_requestSender.SendRequestAsync(request));
        }
Example #3
0
        public UploadResult SaveMedia(SaveMediaQuery saveMediaQuery)
        {
            var postData = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("brandid", saveMediaQuery.BrandId),
                new KeyValuePair <string, string>("name", saveMediaQuery.Filename),
            };

            string uri = null;

            if (saveMediaQuery.MediaId == null)
            {
                uri = $"api/v4/media/save/{saveMediaQuery.ImportId}/";
            }
            else
            {
                uri = $"api/v4/media/{saveMediaQuery.MediaId}/save/{saveMediaQuery.ImportId}/";
            }

            string result = Post($"{_customerBynderUrl}/{uri}", postData);

            return((string.IsNullOrWhiteSpace(result)) ? null : JsonConvert.DeserializeObject <UploadResult>(result.ToString()));
        }