public static Dictionary <string, Dictionary <string, decimal> > GetExchangeRates() { HttpWebRequest request = CreateRequest("currencies", "exchange_rates", null, null); try { string text = request.DownloadResponse(); string[] tokens = text.Split(new string[] { "{\"", "\",\"", "\"}" }, StringSplitOptions.RemoveEmptyEntries); var dict = new Dictionary <string, Dictionary <string, decimal> >(); foreach (string token in tokens) { string[] fields = token.Split(new string[] { "\":\"" }, StringSplitOptions.RemoveEmptyEntries); string[] isos = fields[0].Split(new string[] { "_to_" }, StringSplitOptions.RemoveEmptyEntries); decimal amount = Decimal.Parse(fields[1], NumberStyles.Any); if (!dict.ContainsKey(isos[0])) { dict[isos[0]] = new Dictionary <string, decimal>(); } dict[isos[0]][isos[1]] = amount; } return(dict); } catch (WebException) { return(null); } }
public static object GetResource( string controller, string action, IDictionary <string, string> parameters, Type type, APIKey apiKey ) { HttpWebRequest request = CreateRequest( controller, action, parameters, apiKey ); try { return(request.DownloadResponse(type)); } catch (WebException ex) { var constructor = type.GetConstructor( new Type[] { typeof(WebException) } ); return(constructor.Invoke(new object[] { ex })); } }
public static object PutResource( string controller, string subcontroller, string action, IDictionary <string, string> parameters, object postObj, Type typeOfPostObj, Type responseType, APIKey apiKey ) { HttpWebRequest request = CreateRequest( controller, subcontroller, action, parameters, apiKey ); request.Method = "PUT"; request.ContentType = "application/json"; try { request.UploadData(postObj, typeOfPostObj); return(request.DownloadResponse(responseType)); } catch (WebException ex) { var constructor = responseType.GetConstructor( new Type[] { typeof(WebException) } ); return(constructor.Invoke(new object[] { ex })); } }
public static object GetResource( string controller, string action, IDictionary <string, string> parameters, Type type ) { HttpWebRequest request = CreateRequest( controller, action, parameters ); try { return(request.DownloadResponse(type)); } catch (WebException) { // // TODO: Make a constructor of type WebException? // return(null); } }
public static List <Currency> GetCurrencies() { HttpWebRequest request = CreateRequest("currencies", null, null, null); try { string text = request.DownloadResponse(); return(text.Split(new string[] { "[[\"", "\"],[\"", "\"]]" }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries)) .Select(y => new Currency() { Name = y[0], ISO = y[1] }) .ToList()); } catch (WebException) { return(null); } }