-
Notifications
You must be signed in to change notification settings - Fork 16
/
GalleryEndpoint.Memes.cs
70 lines (63 loc) · 2.97 KB
/
GalleryEndpoint.Memes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Imgur.API.Enums;
using Imgur.API.Models;
using Imgur.API.Models.Impl;
namespace Imgur.API.Endpoints.Impl
{
public partial class GalleryEndpoint
{
/// <summary>
/// View images for memes subgallery.
/// </summary>
/// <param name="sort">The order that the gallery should be sorted by. Default: Viral</param>
/// <param name="window">The time period that should be used in filtering requests. Default: Week</param>
/// <param name="page">The data paging number. Default: null</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<IEnumerable<IGalleryItem>> GetMemesSubGalleryAsync(
MemesGallerySortOrder? sort = MemesGallerySortOrder.Viral,
TimeWindow? window = TimeWindow.Week, int? page = null)
{
sort = sort ?? MemesGallerySortOrder.Viral;
window = window ?? TimeWindow.Week;
var sortValue = $"{sort}".ToLower();
var windowValue = $"{window}".ToLower();
var url = $"g/memes/{sortValue}/{windowValue}/{page}";
using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
{
var gallery = await SendRequestAsync<IEnumerable<GalleryItem>>(request);
return gallery;
}
}
/// <summary>
/// View a single image in the memes gallery.
/// </summary>
/// <param name="imageId">The image id.</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<IGalleryImage> GetMemesSubGalleryImageAsync(string imageId)
{
if (string.IsNullOrWhiteSpace(imageId))
throw new ArgumentNullException(nameof(imageId));
var url = $"gallery/image/{imageId}";
using (var request = RequestBuilder.CreateRequest(HttpMethod.Get, url))
{
var image = await SendRequestAsync<GalleryImage>(request);
return image;
}
}
}
}