/// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        internal HttpRequestMessage CreateAlbumRequest(string url,
            string title = null, string description = null,
            AlbumPrivacy? privacy = null, AlbumLayout? layout = null,
            string coverId = null, IEnumerable<string> imageIds = null)
        {
            if (string.IsNullOrWhiteSpace(url))
                throw new ArgumentNullException(nameof(url));

            var parameters = new Dictionary<string, string>();

            if (privacy != null)
                parameters.Add(nameof(privacy), $"{privacy}".ToLower());

            if (layout != null)
                parameters.Add(nameof(layout), $"{layout}".ToLower());

            if (coverId != null)
                parameters.Add("cover", coverId);

            if (title != null)
                parameters.Add(nameof(title), title);

            if (description != null)
                parameters.Add(nameof(description), description);

            if (imageIds != null)
                parameters.Add("ids", string.Join(",", imageIds));

            var request = new HttpRequestMessage(HttpMethod.Post, url)
            {
                Content = new FormUrlEncodedContent(parameters.ToArray())
            };

            return request;
        }
예제 #2
0
        /// <summary>
        ///     Create a new album.
        /// </summary>
        /// <param name="title">The title of the album.</param>
        /// <param name="description">The description of the album.</param>
        /// <param name="privacy">Sets the privacy level of the album.</param>
        /// <param name="layout">Sets the layout to display the album.</param>
        /// <param name="coverId">The Id of an image that you want to be the cover of the album.</param>
        /// <param name="imageIds">The imageIds that you want to be included in the album.</param>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task<IAlbum> CreateAlbumAsync(string title = null, string description = null,
            AlbumPrivacy? privacy = null, AlbumLayout? layout = null, string coverId = null,
            IEnumerable<string> imageIds = null)
        {
            var url = "album";

            using (var request = RequestBuilder.CreateAlbumRequest(url, title, description,
                privacy, layout, coverId, imageIds))
            {
                var album = await SendRequestAsync<Album>(request).ConfigureAwait(false);
                return album;
            }
        }
예제 #3
0
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        internal HttpRequestMessage UpdateAccountSettingsRequest(
            string url,
            string bio = null,
            bool? publicImages = null,
            bool? messagingEnabled = null,
            AlbumPrivacy? albumPrivacy = null,
            bool? acceptedGalleryTerms = null,
            string username = null,
            bool? showMature = null,
            bool? newsletterSubscribed = null)
        {
            if (string.IsNullOrEmpty(url))
                throw new ArgumentNullException(nameof(url));

            var parameters = new Dictionary<string, string>();

            if (publicImages != null)
                parameters.Add("public_images", $"{publicImages}".ToLower());

            if (messagingEnabled != null)
                parameters.Add("messaging_enabled", $"{messagingEnabled}".ToLower());

            if (albumPrivacy != null)
                parameters.Add("album_privacy", $"{albumPrivacy}".ToLower());

            if (acceptedGalleryTerms != null)
                parameters.Add("accepted_gallery_terms", $"{acceptedGalleryTerms}".ToLower());

            if (showMature != null)
                parameters.Add("show_mature", $"{showMature}".ToLower());

            if (newsletterSubscribed != null)
                parameters.Add("newsletter_subscribed", $"{newsletterSubscribed}".ToLower());

            if (!string.IsNullOrWhiteSpace(username))
                parameters.Add(nameof(username), username);

            if (!string.IsNullOrWhiteSpace(bio))
                parameters.Add(nameof(bio), bio);

            var request = new HttpRequestMessage(HttpMethod.Post, url)
            {
                Content = new FormUrlEncodedContent(parameters.ToArray())
            };

            return request;
        }
예제 #4
0
        /// <summary>
        ///     Updates the account settings for a given user. OAuth authentication required.
        /// </summary>
        /// <param name="bio">The biography of the user, is displayed in the gallery profile page.</param>
        /// <param name="publicImages">Set the users images to private or public by default.</param>
        /// <param name="messagingEnabled">Allows the user to enable / disable private messages.</param>
        /// <param name="albumPrivacy">Sets the default privacy level of albums the users creates.</param>
        /// <param name="acceptedGalleryTerms">The user agreement to the Imgur Gallery terms.</param>
        /// <param name="username">A valid Imgur username (between 4 and 63 alphanumeric characters).</param>
        /// <param name="showMature">Toggle display of mature images in gallery list endpoints.</param>
        /// <param name="newsletterSubscribed">Toggle subscription to email newsletter.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ImgurException"></exception>
        /// <exception cref="MashapeException"></exception>
        /// <exception cref="OverflowException"></exception>
        /// <returns></returns>
        public async Task<bool> UpdateAccountSettingsAsync(
            string bio = null,
            bool? publicImages = null,
            bool? messagingEnabled = null,
            AlbumPrivacy? albumPrivacy = null,
            bool? acceptedGalleryTerms = null,
            string username = null,
            bool? showMature = null,
            bool? newsletterSubscribed = null)
        {
            if (ApiClient.OAuth2Token == null)
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);

            var url = "account/me/settings";

            using (
                var request = RequestBuilder.UpdateAccountSettingsRequest(url, bio, publicImages, messagingEnabled,
                    albumPrivacy, acceptedGalleryTerms, username, showMature, newsletterSubscribed))
            {
                var updated = await SendRequestAsync<bool>(request);
                return updated;
            }
        }
예제 #5
0
파일: Imgur.cs 프로젝트: klcintw/ImgurSharp
        /// <summary>
        /// Updates ImgurAlbum
        /// </summary>
        /// <param name="deleteHash">DeleteHash, obtained at creation</param>
        /// <param name="imageDeleteHashes">List image deletehashes in the album</param>
        /// <param name="title">New title</param>
        /// <param name="description">New description</param>
        /// <param name="privacy">New privacy level, use NONE for standard</param>
        /// <param name="layout">New layout, use NONE for standard</param>
        /// <param name="cover">new coverImage, imageId</param>
        /// <returns>bool of result</returns>
        public async Task <bool> UpdateAlbumAnonymous(string deleteHash, IEnumerable <string> imageDeleteHashes, string title, string description, AlbumPrivacy privacy, AlbumLayout layout, string cover)
        {
            var formContent = new FormUrlEncodedContent(new[] {
                new KeyValuePair <string, string>("deleteHashes", imageDeleteHashes.Aggregate((a, b) => a + "," + b)),
                new KeyValuePair <string, string>("title", title),
                new KeyValuePair <string, string>("description", description),
                new KeyValuePair <string, string>("privacy", GetNameFromEnum <AlbumPrivacy>((int)privacy)),
                new KeyValuePair <string, string>("layout", GetNameFromEnum <AlbumLayout>((int)layout)),
                new KeyValuePair <string, string>("cover", cover),
            });

            HttpResponseMessage response = await client.PutAsync(baseUrl + "album/" + deleteHash, formContent);

            await CheckHttpStatusCode(response);

            string content = await response.Content.ReadAsStringAsync();

            ResponseRootObject <bool> updateRoot = JsonConvert.DeserializeObject <ResponseRootObject <bool> >(content);

            return(updateRoot.Data);
        }
예제 #6
0
        /// <summary>
        ///     Update the information of an album. For anonymous albums, {albumId} should be the deletehash that is returned at
        ///     creation.
        /// </summary>
        /// <param name="albumId">The id or deletehash of the album.</param>
        /// <param name="title">The title of the album.</param>
        /// <param name="description">The description of the album.</param>
        /// <param name="privacy">Sets the privacy level of the album.</param>
        /// <param name="layout">Sets the layout to display the album.</param>
        /// <param name="coverId">The Id of an image that you want to be the cover of the album.</param>
        /// <param name="imageIds">The imageIds that you want to be included in the album.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when a null reference is passed to a method that does not accept it as a
        ///     valid argument.
        /// </exception>
        /// <exception cref="ImgurException">Thrown when an error is found in a response from an Imgur endpoint.</exception>
        /// <exception cref="MashapeException">Thrown when an error is found in a response from a Mashape endpoint.</exception>
        /// <returns></returns>
        public async Task<bool> UpdateAlbumAsync(string albumId, string title = null, string description = null,
            AlbumPrivacy? privacy = null, AlbumLayout? layout = null, string coverId = null,
            IEnumerable<string> imageIds = null)
        {
            if (string.IsNullOrWhiteSpace(albumId))
                throw new ArgumentNullException(nameof(albumId));

            var url = $"album/{albumId}";

            using (var request = RequestBuilder.UpdateAlbumRequest(url, title, description,
                privacy, layout, coverId, imageIds))
            {
                var updated = await SendRequestAsync<bool>(request).ConfigureAwait(false);
                return updated;
            }
        }
예제 #7
0
        /// <summary>
        ///     Update the information of an album. For anonymous albums, {album} should be the deletehash that is returned at
        ///     creation.
        /// </summary>
        /// <param name="album">The id or deletehash of the album.</param>
        /// <param name="title">The title of the album.</param>
        /// <param name="description">The description of the album.</param>
        /// <param name="privacy">Sets the privacy level of the album.</param>
        /// <param name="layout">Sets the layout to display the album.</param>
        /// <param name="cover">The Id of an image that you want to be the cover of the album.</param>
        /// <param name="ids">The image ids that you want to be included in the album.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ImgurException"></exception>
        /// <exception cref="MashapeException"></exception>
        /// <exception cref="OverflowException"></exception>
        /// <returns></returns>
        public async Task<bool> UpdateAlbumAsync(string album, string title = null, string description = null,
            AlbumPrivacy? privacy = null, AlbumLayout? layout = null, string cover = null,
            IEnumerable<string> ids = null)
        {
            if (string.IsNullOrEmpty(album))
                throw new ArgumentNullException(nameof(album));

            var url = $"album/{album}";

            using (var request = RequestBuilder.UpdateAlbumRequest(url, title, description, privacy, layout, cover, ids)
                )
            {
                var updated = await SendRequestAsync<bool>(request);
                return updated;
            }
        }