public GetCustomGalleryAsync ( CustomGallerySortOrder sort = CustomGallerySortOrder.Viral, TimeWindow window = TimeWindow.Week, int page = null ) : Task |
||
sort | CustomGallerySortOrder | The order that the gallery should be sorted by. Default: Viral |
window | TimeWindow | The time period that should be used in filtering requests. Default: Week |
page | int | Set the page number so you don't have to retrieve all the data at once. Default: null |
return | Task |
public async Task<ICustomGallery> GetCustomGalleryAsync(
CustomGallerySortOrder? sort = CustomGallerySortOrder.Viral, TimeWindow? window = TimeWindow.Week,
int? page = null)
{
if (ApiClient.OAuth2Token == null)
throw new ArgumentNullException(nameof(ApiClient.OAuth2Token), OAuth2RequiredExceptionMessage);
sort = sort ?? CustomGallerySortOrder.Viral;
window = window ?? TimeWindow.Week;
var sortValue = $"{sort}".ToLower();
var windowValue = $"{window}".ToLower();
var url = $"g/custom/{sortValue}/{windowValue}/{page}";
using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
{
var gallery = await SendRequestAsync<CustomGallery>(request).ConfigureAwait(false);
return gallery;
}
}
public async Task GetCustomGalleryAsync_WithOAuth2TokenNull_ThrowsArgumentNullException() { var mockUrl = "https://api.imgur.com/3/g/custom/top/month/1"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockCustomGalleryEndpointResponses.GetCustomGallery) }; var client = new ImgurClient("123", "1234"); var endpoint = new CustomGalleryEndpoint(client, new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse))); var exception = await Record.ExceptionAsync( async () => await endpoint.GetCustomGalleryAsync(CustomGallerySortOrder.Top, TimeWindow.Month, 1) .ConfigureAwait(false)) .ConfigureAwait(false); Assert.NotNull(exception); Assert.IsType<ArgumentNullException>(exception); }