Skip to content

Instantly share code, notes, and snippets.

@nathandaly
Created March 6, 2018 19:50
Show Gist options
  • Save nathandaly/ad01e5ef39e42c205e794ac1b92c3180 to your computer and use it in GitHub Desktop.
Save nathandaly/ad01e5ef39e42c205e794ac1b92c3180 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using CryptoCoins;
using CryptoMarkets;
namespace CryptoMarkets
{
class Program
{
private static async Task<string> GetCoins()
=> await new WebClient().DownloadStringTaskAsync(new Uri("https://api.coinmarketcap.com/v1/ticker/"));
static void Main(string[] args)
{
var coins = Coins.FromJson(GetCoins().Result);
}
}
}
namespace CryptoCoins
{
using System;
using System.Collections.Generic;
using System.Net;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public class Coins
{
public static List<Dictionary<string, string>> FromJson(string json)
=> JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(json, CryptoCoins.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this List<Dictionary<string, string>> self)
=> JsonConvert.SerializeObject(self, CryptoCoins.Converter.Settings);
}
internal class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters = {
new IsoDateTimeConverter()
{
DateTimeStyles = DateTimeStyles.AssumeUniversal,
},
},
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment