Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created August 30, 2018 17:33
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 dcomartin/ccafba7836fd99e6e588c5286a4e9d33 to your computer and use it in GitHub Desktop.
Save dcomartin/ccafba7836fd99e6e588c5286a4e9d33 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using Newtonsoft.Json;
using static Bullseye.Targets;
namespace bulltest
{
class Program
{
private static decimal _exchangeRate;
private static HttpClient _httpClient = new HttpClient();
static void Main(string[] args)
{
Target("getexchangerate", async () => {
var response = await _httpClient.GetStringAsync("https://api.exchangeratesapi.io/latest?base=CAD&symbols=USD");
var data = JsonConvert.DeserializeObject<ApiData>(response);
_exchangeRate = data.Rates["USD"];
Console.WriteLine($"Rate: {_exchangeRate}");
});
Target("saveexchangerate", DependsOn("getexchangerate"), async () => {
File.WriteAllText("currentRate.txt", _exchangeRate.ToString());
});
RunTargets(args);
}
}
public class ApiData
{
public string Base {get;set;}
public DateTime Date {get;set;}
public Dictionary<string, decimal> Rates {get;set;}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment