document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net;
  4. using Newtonsoft.Json;
  5.  
  6. namespace MoneyConverter.Factory
  7. {
  8.     public class CurrencyFactory
  9.     {
  10.         private readonly String BASE_URL = "https://free.currconv.com/api/v7/";
  11.         private WebClient webClient = new WebClient();
  12.  
  13.         public CurrencyFactory()
  14.         {
  15.         }
  16.  
  17.         public List<String> GetCurrency()
  18.         {
  19.             String url = BASE_URL + "currencies?apiKey={ganti dengan apikey}";
  20.             String jsonData = String.Empty;
  21.  
  22.             List<String> currencies = new List<String>();
  23.  
  24.             try
  25.             {
  26.                 jsonData = webClient.DownloadString(url);
  27.  
  28.                 Dictionary<string, Dictionary<string, Dictionary<string, string>>> result = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Dictionary<string, string>>>> (jsonData);
  29.  
  30.                 foreach (KeyValuePair<string, Dictionary<string, string>> entry in result["results"])
  31.                 {
  32.                     currencies.Add(entry.Key);
  33.                     // Console.WriteLine(entry.Key);
  34.                 }
  35.                 currencies.Sort();
  36.             }
  37.             catch (Exception e)
  38.             {
  39.                 Console.WriteLine(e);
  40.             }
  41.  
  42.             return currencies;
  43.         }
  44.  
  45.         public String ConvertCurrency(String from, String to)
  46.         {
  47.             String query = from + "_" + to;
  48.             String url = BASE_URL + "convert?q=" + query + "&compact=ultra&apiKey={ganti dengan apikey}";
  49.             String jsonData = String.Empty;
  50.             //Console.WriteLine(url);
  51.  
  52.             try
  53.             {
  54.                 jsonData = webClient.DownloadString(url);
  55.  
  56.                 Dictionary<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonData);
  57.  
  58.                 return result[query];
  59.             }
  60.             catch (Exception e)
  61.             {
  62.                 Console.WriteLine(e);
  63.                 return "";
  64.             }
  65.         }
  66.     }
  67. }
  68.  
');