Skip to content

Instantly share code, notes, and snippets.

@barncastle
Created June 18, 2019 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barncastle/85646135f4218b6baec6341cc9f6c27e to your computer and use it in GitHub Desktop.
Save barncastle/85646135f4218b6baec6341cc9f6c27e to your computer and use it in GitHub Desktop.
using DBCD.Providers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
namespace DBCD.Tests
{
class GithubDBDProvider : IDBDProvider
{
private readonly HttpClient client;
private readonly Dictionary<string, string> lookup;
private const string branch = "master";
public GithubDBDProvider()
{
client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
string data = client.GetStringAsync("https://api.github.com/repos/wowdev/WoWDBDefs/contents/definitions?ref=" + branch).Result;
var definitions = JsonConvert.DeserializeObject<ContentObject[]>(data);
lookup = definitions.ToDictionary(x => Path.GetFileNameWithoutExtension(x.name), x => x.download_url, StringComparer.OrdinalIgnoreCase);
}
public Stream StreamForTableName(string tableName, string build = null)
{
var bytes = client.GetByteArrayAsync(lookup[tableName]).Result;
return new MemoryStream(bytes);
}
class ContentObject
{
public string name { get; set; }
public string path { get; set; }
public string sha { get; set; }
public int size { get; set; }
public string url { get; set; }
public string html_url { get; set; }
public string git_url { get; set; }
public string download_url { get; set; }
public string type { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment