Ejemplo n.º 1
0
        // TODO essayer avec event pour récupérer la réponse

        private CoinBalance JsonGetBalance(string coin, string key)
        {
            if (coin != null && key != "")
            {
                string url = "https://api.crypto-games.net/v1/balance/" + coin + "/" + key;

                WebRequest req = WebRequest.Create(url);
                try
                {
                    using (WebResponse res = req.GetResponse())
                        using (var reader = new StreamReader(res.GetResponseStream()))
                        {
                            string  responseJSON = reader.ReadToEnd();
                            dynamic json         = System.Web.Helpers.Json.Decode(responseJSON);

                            CoinBalance bal = CoinBalance.FromJSONDynamic(json, coin);
                            return(bal);
                        }
                }
                catch (Exception e)
                {
                    AddOutputLine($"EXCEPTION. Message: {e.ToString()}");
                }
            }
            else
            {
                AddOutputLine("Coin or API Key invalid.");
            }
            return(new CoinBalance());
        }
Ejemplo n.º 2
0
        public static CoinBalance FromJSONDynamic(dynamic json, string coin)
        {
            CoinBalance cs = new CoinBalance();

            cs.Balance = json.Balance;
            cs.Coin    = coin;
            return(cs);
        }
Ejemplo n.º 3
0
        private void buttonBalance_Click(object sender, EventArgs e)
        {
            string coin = GetSelectedCoin();
            string key  = GetAPIKey();

            if (coin != null && key != "")
            {
                CoinBalance bal = JsonGetBalance(coin, key);
                labelBalance.Text = bal.Balance.ToString();
                AddOutputLine(bal.ToString());
            }
            else
            {
                AddOutputLine("Coin or API Key invalid.");
            }
        }