Skip to content

Instantly share code, notes, and snippets.

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