Created
August 30, 2018 17:33
-
-
Save dcomartin/ccafba7836fd99e6e588c5286a4e9d33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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