Created
March 29, 2021 10:02
-
-
Save azidanit/551251b1dc60894dc5f0e3ae1368b04c 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.Text; | |
using System.Diagnostics; | |
using System.Net; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace CurrencyExchange | |
{ | |
class ApiConn | |
{ | |
private string all_curr_url = "https://free.currconv.com/api/v7/currencies?apiKey=a0cc285385352baf9649"; | |
IDictionary<string, string> numberNames = new Dictionary<string, string>(); | |
//<id,currencySymbol | |
public ApiConn() | |
{ | |
Debug.WriteLine("Api conn created"); | |
getAllCurrency(); | |
getCurrencyRate("USD", "PHP"); | |
} | |
public JToken getAllCurrency() | |
{ | |
string json_str = new WebClient().DownloadString(all_curr_url); | |
Debug.WriteLine(json_str); | |
JObject o = JObject.Parse(json_str); | |
Debug.WriteLine(o["results"]["ALL"]); | |
JToken res_o = o["results"]; | |
string coba = "IDR - I Dont know"; | |
Debug.WriteLine(coba.Substring(0,3)); | |
Debug.WriteLine(res_o[coba.Substring(0, 3)]); | |
return res_o; | |
} | |
public Double getCurrencyRate(string from_, string to_) | |
{ | |
string url_api = "https://free.currconv.com/api/v7/convert?q=" + from_ + "_" + to_ + | |
"&compact=ultra&apiKey=a0cc285385352baf9649"; | |
string json_str = new WebClient().DownloadString(url_api); | |
var id_convert = from_ + "_" + to_; | |
JToken j_o = JToken.Parse(json_str); | |
Debug.WriteLine(j_o[id_convert]); | |
return j_o[id_convert].ToObject<double>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment