예제 #1
0
        /// <summary>
        /// Create a new btc address with label.
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>
        public Models.IAddress CreateAddress(String label)
        {
            Uri url = new Uri("https://api.coinjar.io/v1/bitcoin_addresses.json");

            String      postData = String.Format("label={0}", label);
            WebResponse response = base.Post(url, postData);

            //Get the stream containing content returned by the server.
            using (Stream responseStream = response.GetResponseStream())
            {
                // Open the stream using a StreamReader for easy access.
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    // Read the content.
                    string responseFromServer = reader.ReadToEnd();

                    // Clean up the streams.
                    reader.Close();
                    response.Close();

                    Providers.JsonSerializer <Models.CoinJar.AddressResponse> serializer = new JsonSerializer <Models.CoinJar.AddressResponse>();
                    Models.CoinJar.AddressResponse addressResponse = serializer.GetObjectFromString(responseFromServer);
                    return(addressResponse.BitcoinAddress);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Get single address
        /// </summary>
        /// <param name="bitcoinAddress"></param>
        /// <returns></returns>
        public Models.IAddress GetAddress(String bitcoinAddress)
        {
            if (!String.IsNullOrEmpty(bitcoinAddress))
            {
                Match match = Regex.Match(bitcoinAddress, ADDRESS_REG_EX);

                if (match.Success == true)
                {
                    Uri url = new Uri(String.Format("https://api.coinjar.io/v1/bitcoin_addresses/{0}.json", bitcoinAddress));

                    Providers.JsonSerializer <Models.CoinJar.AddressResponse> serializer = new JsonSerializer <Models.CoinJar.AddressResponse>();
                    serializer.Proxy       = base.Proxy;
                    serializer.Credentials = new NetworkCredential(base.ApiKey, "");

                    Models.CoinJar.AddressResponse response = serializer.GetObject(url);
                    return(response.BitcoinAddress);
                }
                else
                {
                    throw new ArgumentException("Address does not appear to be valid");
                }
            }
            else
            {
                throw new ArgumentNullException("Address cannot be null or empty");
            }
        }