/
GithubAPI.cs
47 lines (37 loc) · 1.29 KB
/
GithubAPI.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace TrexMinerGUI
{
public static class GithubAPI
{
private class Json
{
public class Asset
{
public string browser_download_url { get; set; }
}
public string tag_name { get; set; }
public List<Asset> assets { get; set; }
}
private static Json DownloadAndParseJson(string JsonURL)
{
string json;
using (WebClient wc = new WebClient())
{
wc.Headers.Add("user-agent", "Github does not give permission without this header, lol");
json = wc.DownloadString(JsonURL);
}
return JsonConvert.DeserializeObject<Json>(json);
}
public static (Version, string) GetLatestTrexRelease()
{
Json JsonResult = DownloadAndParseJson("https://api.github.com/repos/trexminer/T-Rex/releases/latest");
string WindowsDownloadLink = JsonResult.assets.Where(s => s.browser_download_url.Contains("win")).FirstOrDefault().browser_download_url;
return (new Version(JsonResult.tag_name), WindowsDownloadLink);
}
}
}