public void ReportItemRequest_WithUrlNull_ThrowsArgumentNullException()
        {
            var requestBuilder = new AccountRequestBuilder();

            var exception = Record.Exception(() => RequestBuilderBase.ReportItemRequest(null, ReportReason.Abusive));

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

            var argNullException = (ArgumentNullException)exception;

            Assert.Equal(argNullException.ParamName, "url");
        }
        public async Task ReportItemRequest_Equal()
        {
            var client         = new ImgurClient("123", "1234");
            var requestBuilder = new CommentRequestBuilder();

            var mockUrl = $"{client.EndpointUrl}comment/XysioD/report";
            var request = RequestBuilderBase.ReportItemRequest(mockUrl, ReportReason.Abusive);

            Assert.NotNull(request);
            var expected = "reason=3";

            Assert.Equal(expected, await request.Content.ReadAsStringAsync().ConfigureAwait(false));
            Assert.Equal("https://api.imgur.com/3/comment/XysioD/report", request.RequestUri.ToString());
            Assert.Equal(HttpMethod.Post, request.Method);
        }
Exemple #3
0
        /// <summary>
        ///     Report a comment for being inappropriate.
        ///     OAuth authentication required.
        /// </summary>
        /// <param name="commentId">The comment id.</param>
        /// <param name="reason">The reason why the comment is inappropriate.</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> ReportCommentAsync(int commentId, ReportReason reason)
        {
            if (ApiClient.OAuth2Token == null)
            {
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
            }

            var url = $"comment/{commentId}/report";

            using (var request = RequestBuilderBase.ReportItemRequest(url, reason))
            {
                var reported = await SendRequestAsync <bool?>(request).ConfigureAwait(false);

                return(reported ?? true);
            }
        }
Exemple #4
0
        /// <summary>
        ///     Report an item in the gallery. OAuth authentication required.
        /// </summary>
        /// <param name="galleryItemId">The gallery item id.</param>
        /// <param name="reason">A reason why content is inappropriate.</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> ReportGalleryItem(string galleryItemId, ReportReason reason)
        {
            if (string.IsNullOrWhiteSpace(galleryItemId))
                throw new ArgumentNullException(nameof(galleryItemId));

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

            var url = $"gallery/{galleryItemId}/report";

            using (var request = RequestBuilderBase.ReportItemRequest(url, reason))
            {
                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;
            }
        }
Exemple #5
0
        /// <summary>
        ///     Report an item in the gallery. OAuth authentication required.
        /// </summary>
        /// <param name="galleryItemId">The gallery item id.</param>
        /// <param name="reason">A reason why content is inappropriate.</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> ReportGalleryItemAsync(string galleryItemId, ReportReason reason)
        {
            if (string.IsNullOrWhiteSpace(galleryItemId))
            {
                throw new ArgumentNullException(nameof(galleryItemId));
            }

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

            var url = $"gallery/{galleryItemId}/report";

            using (var request = RequestBuilderBase.ReportItemRequest(url, reason))
            {
                var reported = await SendRequestAsync <bool>(request).ConfigureAwait(false);

                return(reported);
            }
        }