Skip to content

Instantly share code, notes, and snippets.

@nuitsjp nuitsjp/GitHubCounter.cs
Last active Mar 21, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.