Imgur.API.Endpoints.Impl.NotificationEndpoint.GetNotificationsAsync C# (CSharp) Method

GetNotificationsAsync() public method

Returns all of the notifications for the user. 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 GetNotificationsAsync ( bool newNotifications = true ) : Task
newNotifications bool false for all notifications, true for only non-viewed notification. Default is true.
return Task
        public async Task<INotifications> GetNotificationsAsync(bool newNotifications = true)
        {
            if (ApiClient.OAuth2Token == null)
                throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);

            var newNotificationsValue = $"{newNotifications}".ToLower();
            var url = $"notification?new={newNotificationsValue}";

            using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
            {
                var notifications = await SendRequestAsync<Notifications>(request).ConfigureAwait(false);
                return notifications;
            }
        }

Usage Example

コード例 #1
0
        public async Task GetNotificationsAsync_NotNull()
        {
            var mockUrl = "https://api.imgur.com/3/notification?new=false";
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MockNotificationEndpointResponses.GetNotifications)
            };

            var client = new ImgurClient("123", "1234", MockOAuth2Token);
            var endpoint = new NotificationEndpoint(client,
                new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)));
            var notifications = await endpoint.GetNotificationsAsync(false).ConfigureAwait(false);

            Assert.NotNull(notifications);
            Assert.NotNull(notifications.Messages);
            Assert.NotNull(notifications.Replies);
        }
All Usage Examples Of Imgur.API.Endpoints.Impl.NotificationEndpoint::GetNotificationsAsync