/// <summary> /// Creates a new comment, returns the ID of the comment. /// OAuth authentication required. /// </summary> /// <param name="comment">The comment text, this is what will be displayed.</param> /// <param name="galleryItemId">The ID of the item in the gallery that you wish to comment on.</param> /// <param name="parentId">The ID of the parent comment, this is an alternative method to create a reply.</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 <int> CreateCommentAsync(string comment, string galleryItemId, string parentId = null) { if (string.IsNullOrWhiteSpace(comment)) { throw new ArgumentNullException(nameof(comment)); } if (string.IsNullOrWhiteSpace(galleryItemId)) { throw new ArgumentNullException(nameof(galleryItemId)); } if (ApiClient.OAuth2Token == null) { throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage); } const string url = nameof(comment); using (var request = CommentRequestBuilder.CreateCommentRequest(url, comment, galleryItemId, parentId)) { var returnComment = await SendRequestAsync <Comment>(request).ConfigureAwait(false); return(returnComment.Id); } }
/// <summary> /// Creates a new comment, returns the ID of the comment. /// OAuth authentication required. /// </summary> /// <param name="comment">The comment text, this is what will be displayed.</param> /// <param name="galleryItemId">The ID of the item in the gallery that you wish to comment on.</param> /// <param name="parentId">The ID of the parent comment, this is an alternative method to create a reply.</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 int CreateComment(string comment, string galleryItemId, string parentId = null) { if (string.IsNullOrWhiteSpace(comment)) { throw new ArgumentNullException(nameof(comment)); } if (string.IsNullOrWhiteSpace(galleryItemId)) { throw new ArgumentNullException(nameof(galleryItemId)); } if (ApiClient.OAuth2Token == null) { throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage); } const string url = nameof(comment); using (var request = CommentRequestBuilder.CreateCommentRequest(url, comment, galleryItemId, parentId)) { var httpResponse = HttpClient.SendAsync(request).Result; var jsonString = httpResponse.Content.ReadAsStringAsync().Result; var output = Newtonsoft.Json.JsonConvert.DeserializeObject <Basic <Comment> >(httpResponse.Content.ReadAsStringAsync().Result.ToString()); return(output.Data.Id); } }
public void CreateCommentRequest_WithImageIdNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new CommentRequestBuilder(); var url = $"{client.EndpointUrl}comment"; requestBuilder.CreateCommentRequest(url, "Hello World", null, "ABCdef"); }
public void CreateCommentRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new CommentRequestBuilder(); var exception = Record.Exception(() => CommentRequestBuilder.CreateCommentRequest(null, "Hello World!", "xYxAbcD", "ABCdef")); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal(argNullException.ParamName, "url"); }
public async Task CreateCommentRequest_Equal() { var client = new ImgurClient("123", "1234"); var requestBuilder = new CommentRequestBuilder(); var mockUrl = $"{client.EndpointUrl}comment/XysioD"; var request = CommentRequestBuilder.CreateCommentRequest(mockUrl, "Hello World!", "xYxAbcD", "ABCdef"); Assert.NotNull(request); var expected = "image_id=xYxAbcD&comment=Hello+World%21&parent_id=ABCdef"; Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false)); Assert.Equal("https://api.imgur.com/3/comment/XysioD", request.RequestUri.ToString()); Assert.Equal(HttpMethod.Post, request.Method); }
public void CreateCommentRequest_WithImageIdNull_ThrowsArgumentNullException() { var client = new ImgurClient("123", "1234"); var requestBuilder = new CommentRequestBuilder(); var mockUrl = $"{client.EndpointUrl}comment"; var exception = Record.Exception(() => CommentRequestBuilder.CreateCommentRequest(mockUrl, "Hello World", null, "ABCdef")); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal(argNullException.ParamName, "galleryItemId"); }
public void CreateCommentRequest_WithUrlNull_ThrowsArgumentNullException() { var requestBuilder = new CommentRequestBuilder(); requestBuilder.CreateCommentRequest(null, "Hello World!", "xYxAbcD", "ABCdef"); }