Skip to content

Instantly share code, notes, and snippets.

@nuitsjp
Last active March 21, 2019 14:48
Show Gist options
  • Save nuitsjp/d29be1a65ddf9e2281cee7bdf5100b4c to your computer and use it in GitHub Desktop.
Save nuitsjp/d29be1a65ddf9e2281cee7bdf5100b4c to your computer and use it in GitHub Desktop.
Count download of GitHub release module.
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Linq;
using System.Threading.Tasks;
public static class GitHubCounter
{
public static async Task CountDownload(string owner, string repository)
{
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Add("User-Agent", "C# HttpClient");
var downloadCount =
JArray
.Parse(await httpClient.GetStringAsync($"https://api.github.com/repos/{owner}/{repository}/releases"))
.SelectMany(x => JArray.FromObject(x["assets"]))
.Sum(x => int.Parse((string)x["download_count"]));
Console.WriteLine(downloadCount);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment