/// <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
        /// <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);
        }
示例#4
0
        /// <summary>
        /// Creates an album on imgur, if authorized with <see cref="OAuth2Authentication"/> then it will be added to the authorised.
        /// </summary>
        /// <param name="imageIds">A collection of ImageId's for valid imgur images that should be added to this album.</param>
        /// <param name="coverImageId">The ImageId of the image you want to be the cover of the album (has to be in <see cref="imageIds"/>)</param>
        /// <param name="title">The title of the album</param>
        /// <param name="description">The description of the album</param>
        /// <param name="privacy">The privacy mode of the album</param>
        /// <param name="layout">The defualt layout of the album</param>
        public async Task <ImgurResponse <Album> > CreateAlbumFromIdsAsync(string[] imageIds = null, string coverImageId = null, string title = null, string description = null, Privacy privacy = Privacy.Public, AlbumLayout layout = AlbumLayout.Blog)
        {
            if (ImgurClient.Authentication == null)
            {
                throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");
            }

            var keyPairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("privacy", privacy.ToString().ToLowerInvariant()),
                new KeyValuePair <string, string>("layout", layout.ToString().ToLowerInvariant())
            };

            if (imageIds != null)
            {
                keyPairs.Add(new KeyValuePair <string, string>("ids", String.Join(",", imageIds)));
            }
            if (coverImageId != null)
            {
                keyPairs.Add(new KeyValuePair <string, string>("cover", coverImageId));
            }
            if (title != null)
            {
                keyPairs.Add(new KeyValuePair <string, string>("title", title));
            }
            if (description != null)
            {
                keyPairs.Add(new KeyValuePair <string, string>("description", description));
            }
            var multi = new FormUrlEncodedContent(keyPairs.ToArray());

            var album = await Request.SubmitImgurRequestAsync <Album>(Request.HttpMethod.Post, CreateAlbumUrl, ImgurClient.Authentication, content : multi);

            return(await GetAlbumDetailsAsync(album.Data.Id));
        }
示例#5
0
 /// <summary>
 /// Creates an album on imgur, if authorized with <see cref="OAuth2Authentication"/> then it will be added to the authorised.
 /// </summary>
 /// <param name="images">A collection of valid Image's that should be added to this album.</param>
 /// <param name="coverImage">An Imgur Image that want to be the cover of the album (has to be in <see cref="images"/>)</param>
 /// <param name="title">The title of the album</param>
 /// <param name="description">The description of the album</param>
 /// <param name="privacy">The privacy mode of the album</param>
 /// <param name="layout">The defualt layout of the album</param>
 public async Task <ImgurResponse <Album> > CreateAlbumAsync(Image[] images = null, Image coverImage = null, string title = null, string description = null, Privacy privacy = Privacy.Public, AlbumLayout layout = AlbumLayout.Blog)
 {
     return(await CreateAlbumFromIdsAsync(images == null?null : images.Select(i => i.Id).ToArray(), (coverImage == null ? null : coverImage.Id), title, description, privacy, layout));
 }
示例#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;
            }
        }
示例#8
0
		/// <summary>
		/// Creates an album on imgur, if authorized with <see cref="OAuth2Authentication"/> then it will be added to the authorised.
		/// </summary>
		/// <param name="imageIds">A collection of ImageId's for valid imgur images that should be added to this album.</param>
		/// <param name="coverImageId">The ImageId of the image you want to be the cover of the album (has to be in <see cref="imageIds"/>)</param>
		/// <param name="title">The title of the album</param>
		/// <param name="description">The description of the album</param>
		/// <param name="privacy">The privacy mode of the album</param>
		/// <param name="layout">The defualt layout of the album</param>
		public async Task<ImgurResponse<Album>> CreateAlbumFromIdsAsync(string[] imageIds = null, string coverImageId = null, string title = null, string description = null, Privacy privacy = Privacy.Public, AlbumLayout layout = AlbumLayout.Blog)
		{
			if (ImgurClient.Authentication == null)
				throw new InvalidAuthenticationException("Authentication can not be null. Set it in the main Imgur class.");

			var keyPairs = new List<KeyValuePair<string, string>>
			{
				new KeyValuePair<string, string>("privacy", privacy.ToString().ToLowerInvariant()),
				new KeyValuePair<string, string>("layout", layout.ToString().ToLowerInvariant())
			};
			if (imageIds != null) keyPairs.Add(new KeyValuePair<string, string>("ids", String.Join(",", imageIds)));
			if (coverImageId != null) keyPairs.Add(new KeyValuePair<string, string>("cover", coverImageId));
			if (title != null) keyPairs.Add(new KeyValuePair<string, string>("title", title));
			if (description != null) keyPairs.Add(new KeyValuePair<string, string>("description", description));
			var multi = new FormUrlEncodedContent(keyPairs.ToArray());

			var album = await Request.SubmitImgurRequestAsync<Album>(Request.HttpMethod.Post, CreateAlbumUrl, ImgurClient.Authentication, content: multi);
			return await GetAlbumDetailsAsync(album.Data.Id);
		}
示例#9
0
		/// <summary>
		/// Creates an album on imgur, if authorized with <see cref="OAuth2Authentication"/> then it will be added to the authorised.
		/// </summary>
		/// <param name="images">A collection of valid Image's that should be added to this album.</param>
		/// <param name="coverImage">An Imgur Image that want to be the cover of the album (has to be in <see cref="images"/>)</param>
		/// <param name="title">The title of the album</param>
		/// <param name="description">The description of the album</param>
		/// <param name="privacy">The privacy mode of the album</param>
		/// <param name="layout">The defualt layout of the album</param>
		public async Task<ImgurResponse<Album>> CreateAlbumAsync(Image[] images = null, Image coverImage = null, string title = null, string description = null, Privacy privacy = Privacy.Public, AlbumLayout layout = AlbumLayout.Blog)
		{
			return await CreateAlbumFromIdsAsync(images == null ? null : images.Select(i => i.Id).ToArray(), (coverImage == null ? null : coverImage.Id), title, description, privacy, layout);
		}