Esempio n. 1
0
        /// <summary>
        ///     Create a reply for the given 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 comment id that you are replying to.</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> CreateReplyAsync(string comment, string galleryItemId, string parentId)
        {
            if (string.IsNullOrWhiteSpace(comment))
            {
                throw new ArgumentNullException(nameof(comment));
            }

            if (string.IsNullOrWhiteSpace(galleryItemId))
            {
                throw new ArgumentNullException(nameof(galleryItemId));
            }

            if (string.IsNullOrWhiteSpace(parentId))
            {
                throw new ArgumentNullException(nameof(parentId));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{parentId}";

            using (var request = CommentRequestBuilder.CreateReplyRequest(url, comment, galleryItemId))
            {
                var returnComment = await SendRequestAsync <Comment>(request).ConfigureAwait(false);

                return(returnComment.Id);
            }
        }
        /// <summary>
        ///     Create a reply for the given 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 comment id that you are replying to.</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 CreateReply(string comment, string galleryItemId, string parentId)
        {
            if (string.IsNullOrWhiteSpace(comment))
            {
                throw new ArgumentNullException(nameof(comment));
            }

            if (string.IsNullOrWhiteSpace(galleryItemId))
            {
                throw new ArgumentNullException(nameof(galleryItemId));
            }

            if (string.IsNullOrWhiteSpace(parentId))
            {
                throw new ArgumentNullException(nameof(parentId));
            }

            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{parentId}";

            using (var request = CommentRequestBuilder.CreateReplyRequest(url, comment, galleryItemId))
            {
                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);
            }
        }
Esempio n. 3
0
        public void CreateReplyRequest_WithImageIdNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();
            var url            = $"{client.EndpointUrl}comment";

            requestBuilder.CreateReplyRequest(url, "Hello World", null);
        }
Esempio n. 4
0
        public void CreateReplyRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new CommentRequestBuilder();

            var exception = Record.Exception(() => CommentRequestBuilder.CreateReplyRequest(null, "Hello World!", "xYxAbcD"));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
Esempio n. 5
0
        public void CreateReplyRequest_WithImageIdNull_ThrowsArgumentNullException()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();
            var mockUrl        = $"{client.EndpointUrl}comment";

            var exception = Record.Exception(() => CommentRequestBuilder.CreateReplyRequest(mockUrl, "Hello World", null));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentNullException>(exception);

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "galleryItemId");
        }
Esempio n. 6
0
        public async Task CreateReplyRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}comment";
            var request = CommentRequestBuilder.CreateReplyRequest(mockUrl, "Hello World!", "xYxAbcD");

            Assert.NotNull(request);
            var expected = "image_id=xYxAbcD&comment=Hello+World%21";

            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/comment", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Esempio n. 7
0
        public void CreateReplyRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new CommentRequestBuilder();

            requestBuilder.CreateReplyRequest(null, "Hello World!", "xYxAbcD");
        }