-
Notifications
You must be signed in to change notification settings - Fork 0
/
PexelsApi.cs
65 lines (57 loc) · 1.88 KB
/
PexelsApi.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
using RestSharp;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace WpfLazyLoadImages
{
public class PexelsApi
{
IRestClient client;
public PexelsApi(string key)
{
client = new RestClient("https://api.pexels.com");
client.AddDefaultHeader("Authorization", key);
}
public async Task<List<PexelsPhoto>> GetCurated(int count = 15, int page = 1)
{
var req = new RestRequest("/v1/curated");
req.AddParameter("per_page", count);
req.AddParameter("page", page);
var resp = await client.ExecuteTaskAsync<PexelsCurated>(req);
return resp.Data.Photos;
}
public async Task<byte[]> DownloadImage(string url)
{
var req = new RestRequest(url);
var res = await client.ExecuteTaskAsync(req);
return res.RawBytes;
}
}
public partial class PexelsCurated
{
public long Page { get; set; }
public long PerPage { get; set; }
public List<PexelsPhoto> Photos { get; set; }
public string NextPage { get; set; }
}
public partial class PexelsPhoto
{
public long Id { get; set; }
public long Width { get; set; }
public long Height { get; set; }
public string Url { get; set; }
public string Photographer { get; set; }
public string PhotographerUrl { get; set; }
public PexelsSrc Src { get; set; }
}
public partial class PexelsSrc
{
public string Original { get; set; }
public string Large2X { get; set; }
public string Large { get; set; }
public string Medium { get; set; }
public string Small { get; set; }
public string Portrait { get; set; }
public string Landscape { get; set; }
public string Tiny { get; set; }
}
}