Imgur.API.Endpoints.Impl.ImageEndpoint.FavoriteImageAsync C# (CSharp) Method

FavoriteImageAsync() public method

Favorite an image with the given ID. OAuth authentication required.
/// Thrown when a null reference is passed to a method that does not accept it as a /// valid argument. /// Thrown when an error is found in a response from an Imgur endpoint. Thrown when an error is found in a response from a Mashape endpoint.
public FavoriteImageAsync ( string imageId ) : Task
imageId string The image id.
return Task
        public async Task<bool> FavoriteImageAsync(string imageId)
        {
            if (string.IsNullOrWhiteSpace(imageId))
                throw new ArgumentNullException(nameof(imageId));

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

            var url = $"image/{imageId}/favorite";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Post, url))
            {
                var imgurResult = await SendRequestAsync<string>(request).ConfigureAwait(false);
                return imgurResult.Equals("favorited", StringComparison.OrdinalIgnoreCase);
            }
        }

Usage Example

コード例 #1
0
        public async Task FavoriteImageAsync_WithIdNull_ThrowsArgumentNullException()
        {
            var client = new ImgurClient("123", "1234");
            var endpoint = new ImageEndpoint(client);

            var exception =
                await
                    Record.ExceptionAsync(
                        async () => await endpoint.FavoriteImageAsync(null).ConfigureAwait(false))
                        .ConfigureAwait(false);
            Assert.NotNull(exception);
            Assert.IsType<ArgumentNullException>(exception);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.ImageEndpoint::FavoriteImageAsync