Imgur.API.Endpoints.Impl.AlbumEndpoint.FavoriteAlbumAsync C# (CSharp) Method

FavoriteAlbumAsync() public method

Favorite an album with a 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 FavoriteAlbumAsync ( string albumId ) : Task
albumId string The album id.
return Task
        public async Task<bool> FavoriteAlbumAsync(string albumId)
        {
            if (string.IsNullOrWhiteSpace(albumId))
                throw new ArgumentNullException(nameof(albumId));

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

            var url = $"album/{albumId}/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

        public async Task FavoriteAlbumAsync_WithMashapeClient_True()
        {
            var mockUrl = "https://imgur-apiv3.p.mashape.com/3/album/zVpyzhW/favorite";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockAlbumEndpointResponses.Imgur.FavoriteAlbumTrue)
            };

            var client = new MashapeClient("123", "1234", "xyz", MockOAuth2Token);
            var endpoint = new AlbumEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var favorited = await endpoint.FavoriteAlbumAsync("zVpyzhW").ConfigureAwait(false);

            Assert.True(favorited);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.AlbumEndpoint::FavoriteAlbumAsync