public void AddAlbumImagesRequest_WithIdsNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var url = $"{client.EndpointUrl}album/AbcdeF/add"; requestBuilder.AddAlbumImagesRequest(url, null); }
public void CreateAlbumRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new AlbumRequestBuilder(); var exception = Record.Exception(() => AlbumRequestBuilder.CreateAlbumRequest(null)); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal(argNullException.ParamName, "url"); }
public void AddAlbumImagesRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new AlbumRequestBuilder(); var exception = Record.Exception(() => AlbumRequestBuilder.AddAlbumImagesRequest(null, new List <string>())); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal(argNullException.ParamName, "url"); }
/// <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 = AlbumRequestBuilder.CreateAlbumRequest(url, title, description, privacy, layout, coverId, imageIds)) { var album = await SendRequestAsync <Album>(request).ConfigureAwait(false); return(album); } }
/// <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 Basic <Album> CreateAlbum(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 = AlbumRequestBuilder.CreateAlbumRequest(url, title, description, privacy, layout, coverId, imageIds)) { var httpResponse = HttpClient.SendAsync(request).Result; var jsonString = httpResponse.Content.ReadAsStringAsync().Result; var output = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <Album> >(httpResponse.Content.ReadAsStringAsync().Result.ToString()); return(output); } }
public void AddAlbumImagesRequest_WithIdsNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var mockUrl = $"{client.EndpointUrl}album/AbcdeF/add"; var exception = Record.Exception(() => AlbumRequestBuilder.AddAlbumImagesRequest(mockUrl, null)); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal(argNullException.ParamName, "imageIds"); }
public void RemoveAlbumImagesRequest_Equal() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var mockUrl = $"{client.EndpointUrl}album/AbcdeF/remove_images"; var ids = new List <string> { "Abc", "DEF", "XyZ" }; var request = AlbumRequestBuilder.RemoveAlbumImagesRequest(mockUrl, ids); var expected = "https://api.imgur.com/3/album/AbcdeF/remove_images?ids=Abc%2CDEF%2CXyZ"; Assert.NotNull(request); Assert.Equal(expected, request.RequestUri.ToString()); Assert.Equal(HttpMethod.Delete, request.Method); }
public async Task AddAlbumImagesRequest_AreEqual() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var url = $"{client.EndpointUrl}album/AbcdeF/add"; var ids = new List <string> { "Abc", "DEF", "XyZ" }; var request = requestBuilder.AddAlbumImagesRequest(url, ids); var expected = "ids=Abc%2CDEF%2CXyZ"; Assert.IsNotNull(request); Assert.AreEqual(expected, await request.Content.ReadAsStringAsync()); Assert.AreEqual("https://api.imgur.com/3/album/AbcdeF/add", request.RequestUri.ToString()); Assert.AreEqual(HttpMethod.Put, request.Method); }
public async Task SetAlbumImagesRequest_Equal() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var mockUrl = $"{client.EndpointUrl}album/AbcdeF"; var ids = new List <string> { "Abc", "DEF", "XyZ" }; var request = AlbumRequestBuilder.SetAlbumImagesRequest(mockUrl, ids); var expected = "ids=Abc%2CDEF%2CXyZ"; Assert.NotNull(request); Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false)); Assert.Equal("https://api.imgur.com/3/album/AbcdeF", request.RequestUri.ToString()); Assert.Equal(HttpMethod.Post, request.Method); }
/// <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 = AlbumRequestBuilder.UpdateAlbumRequest(url, title, description, privacy, layout, coverId, imageIds)) { var updated = await SendRequestAsync <bool>(request).ConfigureAwait(false); return(updated); } }
/// <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 Basic <bool> UpdateAlbum(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 = AlbumRequestBuilder.UpdateAlbumRequest(url, title, description, privacy, layout, coverId, imageIds)) { var httpResponse = HttpClient.SendAsync(request).Result; var jsonString = httpResponse.Content.ReadAsStringAsync().Result; var output = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <bool> >(httpResponse.Content.ReadAsStringAsync().Result.ToString()); return(output); } }
/// <summary> /// Takes a list of imageIds to add to the 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="imageIds">The imageIds that you want to be added to 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> AddAlbumImagesAsync(string albumId, IEnumerable <string> imageIds) { if (string.IsNullOrWhiteSpace(albumId)) { throw new ArgumentNullException(nameof(albumId)); } if (imageIds == null) { throw new ArgumentNullException(nameof(imageIds)); } var url = $"album/{albumId}/add"; using (var request = AlbumRequestBuilder.AddAlbumImagesRequest(url, imageIds)) { var added = await SendRequestAsync <bool>(request).ConfigureAwait(false); return(added); } }
/// <summary> /// Sets the images for an album, removes all other images and only uses the images in this request. 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="imageIds">The imageIds that you want to be added to 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 Basic <bool> SetAlbumImages(string albumId, IEnumerable <string> imageIds) { if (string.IsNullOrWhiteSpace(albumId)) { throw new ArgumentNullException(nameof(albumId)); } if (imageIds == null) { throw new ArgumentNullException(nameof(imageIds)); } var url = $"album/{albumId}"; using (var request = AlbumRequestBuilder.SetAlbumImagesRequest(url, imageIds)) { var httpResponse = HttpClient.SendAsync(request).Result; var jsonString = httpResponse.Content.ReadAsStringAsync().Result; var output = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <bool> >(httpResponse.Content.ReadAsStringAsync().Result.ToString()); return(output); } }
public async Task CreateAlbumRequest_AreEqual() { var client = new ImgurClient("123", "1234"); var requestBuilder = new AlbumRequestBuilder(); var url = $"{client.EndpointUrl}album/AbcdeF"; var ids = new List <string> { "Abc", "DEF", "XyZ" }; var request = requestBuilder.CreateAlbumRequest( url, "TheTitle", "TheDescription", AlbumPrivacy.Hidden, AlbumLayout.Horizontal, "io9XpoO", ids); var expected = "privacy=hidden&layout=horizontal&cover=io9XpoO&title=TheTitle&description=TheDescription&ids=Abc%2CDEF%2CXyZ"; Assert.IsNotNull(request); Assert.AreEqual(expected, await request.Content.ReadAsStringAsync()); Assert.AreEqual("https://api.imgur.com/3/album/AbcdeF", request.RequestUri.ToString()); Assert.AreEqual(HttpMethod.Post, request.Method); }
public void CreateAlbumRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new AlbumRequestBuilder(); requestBuilder.CreateAlbumRequest(null); }
public void AddAlbumImagesRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new AlbumRequestBuilder(); requestBuilder.AddAlbumImagesRequest(null, null); }