/// <summary>
        /// Utility method: GetCoinSnapshotByID - Invoke CryptoCompare.com API's CoinSnapshotFullById call to
        /// obtain the additional elements (i.e. current blocks, block reward, total coins mined, etc.) that
        /// are not provided by CryptoCompare.com API's coinlist call, given the numeric id of a coin
        /// </summary>
        /// <param name="client"></param>
        /// <param name="coinInformation"></param>
        /// <returns>void</returns>
        private void GetCoinSnapshotByID(ApiWebClient client, CoinInformation coinInformation)
        {
            string coinSnapshotIDParam = "";

            // Obtain numeric id of the coin whose full record is passed in as coinInformation parameter
            coinSnapshotIDParam = coinInformation.Id;

            // Build URL string for the CoinSnapshotFullById CryptoCompare.com API call
            string apiUrl = BuildApiUrlByID(coinSnapshotIDParam, "CoinSnapshotByID");

            // Invoke CryptoCompare.com API's CoinSnapshotFullById call URL, then deserialize result and populate
            // the additional fields provided by this API call into the coinInformation coin record
            string json = client.DownloadAsString(apiUrl);

            try
            {
                RootObjectCoinSnapshot  coinsnapshotset = JsonConvert.DeserializeObject <RootObjectCoinSnapshot>(json);
                GeneralCoinSnapshotData coinSnapshot    = new GeneralCoinSnapshotData();
                coinSnapshot = coinsnapshotset.Data.General;
                coinInformation.PopulateFromJson(coinSnapshot);
            }
            catch (Exception e)
            {
                string errorMsg = e.Message;
            }
        }
Example #2
0
        public IEnumerable <ExchangeInformation> GetExchangeInformation()
        {
            ApiWebClient webClient = new ApiWebClient();

            webClient.Encoding = Encoding.UTF8;

            string response = webClient.DownloadFlakyString(new Uri(GetApiUrl()));

            Dictionary <string, TickerEntry> tickerEntries = JsonConvert.DeserializeObject <Dictionary <string, TickerEntry> >(response);

            List <ExchangeInformation> results = new List <ExchangeInformation>();

            foreach (KeyValuePair <string, TickerEntry> keyValuePair in tickerEntries)
            {
                results.Add(new ExchangeInformation()
                {
                    SourceCurrency = "BTC",
                    TargetCurrency = keyValuePair.Key,
                    TargetSymbol   = keyValuePair.Value.Symbol,
                    ExchangeRate   = keyValuePair.Value.Last
                });
            }

            return(results);
        }
Example #3
0
        public static List <Data.RemoteCommand> GetCommands(string url, string apiKey, string emailAddress, string applicationKey, List <string> machineNames)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonData = serializer.Serialize(machineNames);

            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&apiKey={4}",
                                           url, emailAddress, applicationKey, jsonData, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                string response = ExecuteWebAction(() =>
                {
                    return(client.UploadString(fullUrl, jsonData));
                });

                return(serializer.Deserialize <List <Data.RemoteCommand> >(response));
            }
        }
Example #4
0
 internal Authenticator(ApiWebClient apiWebClient, string publicKey, string privateKey)
 {
     PublicKey     = publicKey;
     PrivateKey    = privateKey;
     _apiWebClient = apiWebClient;
     _apiWebClient.SetAuthenticator(this);
 }
Example #5
0
        public IEnumerable <CoinInformation> GetCoinInformation(string userAgent = "")
        {
            ApiWebClient client = new ApiWebClient();

            if (!string.IsNullOrEmpty(userAgent))
            {
                client.Headers.Add("user-agent", userAgent);
            }

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadFlakyString(apiUrl);

            JArray jsonArray = JArray.Parse(jsonString);

            List <CoinInformation> result = new List <CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                {
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
                }
            }

            return(result);
        }
        public ApiResponse CreateUser(string username, string password, string email, bool isApproved, DateTime createdAt, string botHavenId)
        {
            ApiResponse response;

            var url = Constants.ForumUrl + "CreateUser";
            var data = new NameValueCollection();
            data["UserName"] = username;
            data["Email"] = email;
            data["Password"] = password;
            data["IsApproved"] = isApproved.ToString().ToLower();
            data["botHavenId"] = botHavenId;
            data["createdAt"] = createdAt.Ticks.ToString();

            using (var wc = new ApiWebClient(data, url))
            {
                response = wc.GetResponse();
            }
            if (response.Success)
            {
                try
                {
                    using (var wc = new WebClient())
                    {
                        data = new NameValueCollection();
                        data["Id"] = (string)response.Value;
                        wc.UploadValues("http://forums.bothaven.com/Badge/Time", data);
                    }
                }
                catch (Exception)
                {

                }
            }
            return response;
        }
Example #7
0
        public static List <Data.RemoteCommand> SubmitMiningStatistics(string url, string apiKey, string emailAddress, string applicationKey,
                                                                       List <Data.MiningStatistics> miningStatistics, bool fetchCommands)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}MiningStatisticsInput?emailAddress={1}&applicationKey={2}&apiKey={3}&fetchCommands={4}",
                                           url, emailAddress, applicationKey, apiKey, fetchCommands);

            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                string jsonData = JsonConvert.SerializeObject(miningStatistics);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                string response = ExecuteWebAction(() =>
                {
                    return(client.UploadString(fullUrl, jsonData));
                });

                return(JsonConvert.DeserializeObject <List <Data.RemoteCommand> >(response));
            }
        }
Example #8
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadString(apiUrl);
            JArray jsonArray = JArray.Parse(jsonString);

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Example #9
0
        public static void SubmitMiningStatistics(string url, string apiKey, string emailAddress, string applicationKey, List <Data.MiningStatistics> miningStatistics)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}MiningStatisticsInput?emailAddress={1}&applicationKey={2}&apiKey={3}",
                                           url, emailAddress, applicationKey, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(miningStatistics);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";


                ExecuteWebAction(() =>
                {
                    return(client.UploadString(fullUrl, jsonData));
                });
            }
        }
Example #10
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "",
            BaseCoin profitabilityBasis = BaseCoin.Bitcoin)
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl(profitabilityBasis);

            string jsonString = client.DownloadString(apiUrl);

            JObject jsonObject = JObject.Parse(jsonString);

            if (!jsonObject.Value<bool>("Success"))
            {
                throw new CoinApiException(jsonObject.Value<string>("Message"));
            }

            JArray jsonArray = jsonObject.Value<JArray>("Data");

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Example #11
0
        public void ApiWebClient_UploadDataAsync_Throws_InvalidOprtationException_If_Url_Is_NullOrEmpty()
        {
            //Arrange
            IApiWebClient client = new ApiWebClient();

            //Act
            client.UploadStringAsync(string.Empty, string.Empty, d => { });
        }
Example #12
0
        public void Can_Dispose_ApiWebClient()
        {
            //Arrange
            IApiWebClient client = new ApiWebClient();

            //Act
            client.Dispose();
        }
Example #13
0
        public void Can_Instantiate_New_ApiWebClient()
        {
            //Act
            IApiWebClient client = new ApiWebClient();

            //Assert
            Assert.That(client, Is.Not.Null);
        }
Example #14
0
        /// <summary>Creates a new instance of Bitstamp API .NET's client service.</summary>
        /// <param name="publicApiKey">Your public API key.</param>
        /// <param name="privateApiKey">Your private API key.</param>
        private BitstampClient(string publicApiKey, string privateApiKey)
        {
            var apiWebClient = new ApiWebClient(Utilities.ApiUrlHttpsBase);

            //Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey);

            Market = new Market(apiWebClient);
        }
Example #15
0
        public void ApiWebClient_UploadData_Throws_ArgumentNullException_If_Data_Is_Null()
        {
            //Arrange
            IApiWebClient client = new ApiWebClient();

            //Act
            client.UploadString("http://agilitytest:9080/Agility/Directory", null);
        }
Example #16
0
        public static ApiWebClient GetRealWebClient()
        {
            if (_realWebClient == null)
            {
                _realWebClient = new ApiWebClient(false);
            }

            return(_realWebClient);
        }
Example #17
0
        public static ApiWebClient GetFakeWebClient()
        {
            if (_fakeWebClient == null)
            {
                _fakeWebClient = new ApiWebClient();
            }

            return(_fakeWebClient);
        }
Example #18
0
        public static Data.SellPrices GetSellPrices()
        {
            WebClient webClient = new ApiWebClient();

            string response = webClient.DownloadString(new Uri(GetApiUrl()));

            Data.SellPrices sellPrices = JsonConvert.DeserializeObject <Data.SellPrices>(response);
            return(sellPrices);
        }
Example #19
0
        public static Data.SellPrices GetSellPrices()
        {
            WebClient webClient = new ApiWebClient();

            string response = webClient.DownloadString(new Uri(GetApiUrl()));

            Data.SellPrices sellPrices = JsonConvert.DeserializeObject<Data.SellPrices>(response);
            return sellPrices;
        }
Example #20
0
        /// <summary>Creates a new instance of Poloniex API .NET's client service.</summary>
        /// <param name="publicApiKey">Your public API key.</param>
        /// <param name="privateApiKey">Your private API key.</param>
        public PoloniexApiClient(string apiAddress, string publicApiKey, string privateApiKey)
        {
            var apiWebClient = new ApiWebClient(apiAddress);

            Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey);

            //Markets = new Markets(apiWebClient);
            //Trading = new Trading(apiWebClient);
            Wallet = new Wallet.Wallet(apiWebClient);
        }
Example #21
0
 private TCotacoes CotarSemCache(string url, Dictionary <string, object> parametros)
 {
     using (var client = new ApiWebClient(timeout))
     {
         client.UseDefaultCredentials = true;
         client.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
         var resposta = client.DownloadString(GetAddressToGet(url, parametros));
         return(JsonConvert.DeserializeObject <TCotacoes>(resposta));
     }
 }
Example #22
0
        /// <summary>Creates a new instance of MintPal API .NET's client service.</summary>
        /// <param name="publicApiKey">Your public API key.</param>
        /// <param name="privateApiKey">Your private API key.</param>
        public MintPalClient(string publicApiKey, string privateApiKey)
        {
            var apiWebClient = new ApiWebClient(Helper.ApiUrlBase);

            Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey);

            Markets = new Markets(apiWebClient);
            Trading = new Trading(apiWebClient);
            Wallet = new Wallet(apiWebClient);
        }
        /// <summary>Creates a new instance of Poloniex API .NET's client service.</summary>
        /// <param name="publicApiKey">Your public API key.</param>
        /// <param name="privateApiKey">Your private API key.</param>
        public PoloniexClient(string publicApiKey, string privateApiKey)
        {
            var apiWebClient = new ApiWebClient(Helper.ApiUrlHttpsBase);

            Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey);

            Markets = new Markets(apiWebClient);
            Trading = new Trading(apiWebClient);
            Wallet = new Wallet(apiWebClient);
            Live = new Live();
        }
Example #24
0
        public void Can_Upload_Data_With_ApiWebClient()
        {
            //Arrange
            IApiWebClient client = new ApiWebClient();

            //Act
            var result = client.UploadString("http://agilitytest:9080/Agility/Directory", "req");

            //Assert
            Assert.That(result, Is.Not.Null);
        }
Example #25
0
        /// <summary>Creates a new instance of Poloniex API .NET's client service.</summary>
        /// <param name="publicApiKey">Your public API key.</param>
        /// <param name="privateApiKey">Your private API key.</param>
        public PoloniexClient(string publicApiKey, string privateApiKey)
        {
            var apiWebClient = new ApiWebClient(Helper.ApiUrlHttpsBase);

            Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey);

            Markets = new Markets(apiWebClient);
            Trading = new Trading(apiWebClient);
            Wallet  = new Wallet(apiWebClient);
            Live    = new Live();
        }
Example #26
0
 public static List<RemoteCommand> GetCommands(string url, string apiKey, string emailAddress, string applicationKey, string machineName)
 {
     if (!url.EndsWith("/"))
         url = url + "/";
     string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&apiKey={4}",
         url, emailAddress, applicationKey, machineName, apiKey);
     using (WebClient client = new ApiWebClient())
     {
         string response = client.DownloadString(fullUrl);
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         return serializer.Deserialize<List<RemoteCommand>>(response);
     }
 }
Example #27
0
 public static RemoteCommand DeleteCommand(string url, string apiKey, string emailAddress, string applicationKey, string machineName, long commandId)
 {
     if (!url.EndsWith("/"))
         url = url + "/";
     string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&commandId={4}&apiKey={5}",
         url, emailAddress, applicationKey, machineName, commandId, apiKey);
     using (WebClient client = new ApiWebClient())
     {
         string response = client.UploadString(fullUrl, "DELETE", "");
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         return serializer.Deserialize<RemoteCommand>(response);
     }
 }
Example #28
0
        public dynamic Get(string url, bool debug = false)
        {
            var requestUrl = GenerateOAuthRequestUrl(url, "GET");

            var request = new ApiWebClient(_requestTimeout);
            var response = request.DownloadString(requestUrl);

            var result = JObject.Parse(response);

            if (debug)
                DumpObject(result);

            return result;
        }
Example #29
0
        public IEnumerable <CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();

            if (!string.IsNullOrEmpty(userAgent))
            {
                client.Headers.Add("user-agent", userAgent);
            }

            string apiUrl = GetApiUrl();

            string jsonString = String.Empty;

            try
            {
                jsonString = client.DownloadString(apiUrl);
            }
            catch (WebException ex)
            {
                if ((ex.Status == WebExceptionStatus.ProtocolError) &&
                    (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadGateway))
                {
                    //try again 1 more time if error 502
                    Thread.Sleep(750);
                    jsonString = client.DownloadString(apiUrl);
                }
                else
                {
                    throw;
                }
            }

            JArray jsonArray = JArray.Parse(jsonString);

            List <CoinInformation> result = new List <CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                {
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
                }
            }

            return(result);
        }
Example #30
0
 public static void SubmitNotifications(string url, string apiKey, string emailAddress, string applicationKey, List<string> notifications)
 {
     if (!url.EndsWith("/"))
         url = url + "/";
     string fullUrl = String.Format("{0}NotificationsInput?emailAddress={1}&applicationKey={2}&apiKey={3}",
         url, emailAddress, applicationKey, apiKey);
     using (WebClient client = new ApiWebClient())
     {
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         string jsonData = serializer.Serialize(notifications);
         client.Headers[HttpRequestHeader.ContentType] = "application/json";
         string response = client.UploadString(fullUrl, jsonData);
     }
 }
Example #31
0
        public static List <AvailableMiner> GetAvailableMiners(string userAgent)
        {
            WebClient webClient = new ApiWebClient();

            webClient.Headers.Add("user-agent", userAgent);

            //include www. to avoid redirect
            string url      = "http://www.multiminerapp.com/miners";
            string response = webClient.DownloadString(new Uri(url));

            List <AvailableMiner> availableMiners = JsonConvert.DeserializeObject <List <AvailableMiner> >(response);

            return(availableMiners);
        }
        public ApiResponse ApproveUser(string userId)
        {
            ApiResponse response;

            var url = Constants.ForumUrl + "ApproveUser";
            var data = new NameValueCollection();
            data["userId"] = userId;

            using (var wc = new ApiWebClient(data, url))
            {
                response = wc.GetResponse();
            }
            return response;
        }
Example #33
0
        public dynamic Get(string url, bool debug = false)
        {
            var requestUrl = GenerateOAuthRequestUrl(url, "GET");
            var request    = new ApiWebClient(_requestTimeout);

            request.Headers.Add("user-agent", "MaxCDN dot-net API Client");
            var response = request.DownloadString(requestUrl);
            var result   = response;

            if (debug)
            {
                DumpObject(result);
            }
            return(result);
        }
        public ApiResponse ChangePassword(string userId, string password)
        {
            ApiResponse response;

            var url = Constants.WebsiteUrl + "ChangePassword";
            var data = new NameValueCollection();
            data["userId"] = userId;
            data["password"] = password;

            using (var wc = new ApiWebClient(data, url))
            {
                response = wc.GetResponse();
            }
            return response;
        }
        public PoloniexClient(string apiBaseUrl, string publicApiKey, string privateApiKey)
        {
            if (apiBaseUrl != null && apiBaseUrl.Length > 1 && apiBaseUrl[apiBaseUrl.Length - 1] != '/')
            {
                apiBaseUrl += "/";
            }

            var apiWebClient = new ApiWebClient(apiBaseUrl);

            Authenticator = new Authenticator(apiWebClient, publicApiKey, privateApiKey);

            Markets = new MarketTools.Markets(apiWebClient);
            Trading = new TradingTools.Trading(apiWebClient);
            Wallet  = new WalletTools.Wallet(apiWebClient);
            Live    = new LiveTools.LiveWebSocket();
        }
Example #36
0
        public static RemoteCommand DeleteCommand(string url, string apiKey, string emailAddress, string applicationKey, string machineName, long commandId)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&commandId={4}&apiKey={5}",
                                           url, emailAddress, applicationKey, machineName, commandId, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                string response = client.UploadString(fullUrl, "DELETE", "");
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Deserialize <RemoteCommand>(response));
            }
        }
Example #37
0
        public static List <RemoteCommand> GetCommands(string url, string apiKey, string emailAddress, string applicationKey, string machineName)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&apiKey={4}",
                                           url, emailAddress, applicationKey, machineName, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                string response = client.DownloadString(fullUrl);
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return(serializer.Deserialize <List <RemoteCommand> >(response));
            }
        }
Example #38
0
        public static void SubmitMinerStatistics(string url, Data.Machine machine)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}machines", url);
            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(machine);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                string response = client.UploadString(fullUrl, jsonData);
            }
        }
Example #39
0
        public dynamic Get(string url, bool debug = false)
        {
            var requestUrl = GenerateOAuthRequestUrl(url, "GET");

            var request  = new ApiWebClient(_requestTimeout);
            var response = request.DownloadString(requestUrl);

            var result = response;

            if (debug)
            {
                DumpObject(result);
            }

            return(result);
        }
Example #40
0
        public static void SubmitNotifications(string url, string apiKey, string emailAddress, string applicationKey, List <string> notifications)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}NotificationsInput?emailAddress={1}&applicationKey={2}&apiKey={3}",
                                           url, emailAddress, applicationKey, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(notifications);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                string response = client.UploadString(fullUrl, jsonData);
            }
        }
Example #41
0
        public static void SubmitMiningStatistics(string url, string apiKey, string emailAddress, string applicationKey, string machineName, List<MiningStatistics> miningStatistics)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}MiningStatisticsInput?emailAddress={1}&applicationKey={2}&machineName={3}&apiKey={4}",
                url, emailAddress, applicationKey, machineName, apiKey);
            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(miningStatistics);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                string response = client.UploadString(fullUrl, jsonData);
            }
        }
Example #42
0
        public static void SubmitMinerStatistics(string url, Data.Machine machine)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}machines", url);

            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                string jsonData = JsonConvert.SerializeObject(machine);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                string response = client.UploadString(fullUrl, jsonData);
            }
        }
Example #43
0
        public static void SubmitMachinePools(string url, string apiKey, string emailAddress, string applicationKey, 
            string machineName, List<string> pools)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}PoolsInput?emailAddress={1}&applicationKey={2}&apiKey={3}&machineName={4}",
                url, emailAddress, applicationKey, apiKey, machineName);
            using (WebClient client = new ApiWebClient())
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(pools);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, jsonData);
                });
            }
        }
Example #44
0
        public static Data.RemoteCommand DeleteCommand(string url, string apiKey, string emailAddress, string applicationKey, string machineName, long commandId)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&commandId={4}&apiKey={5}",
                                           url, emailAddress, applicationKey, machineName, commandId, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                string response = ExecuteWebAction(() =>
                {
                    return(client.UploadString(fullUrl, "DELETE", ""));
                });

                return(JsonConvert.DeserializeObject <Data.RemoteCommand>(response));
            }
        }
Example #45
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = String.Empty;

            try
            {
                jsonString = client.DownloadString(apiUrl);
            }
            catch (WebException ex)
            {
                if ((ex.Status == WebExceptionStatus.ProtocolError) &&
                    (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadGateway))
                {
                    //try again 1 more time if error 502
                    Thread.Sleep(750);
                    jsonString = client.DownloadString(apiUrl);
                }
                else
                    throw;
            }

            JArray jsonArray = JArray.Parse(jsonString);

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Example #46
0
        public IEnumerable <ExchangeInformation> GetExchangeInformation()
        {
            ApiWebClient webClient = new ApiWebClient();

            string response = webClient.DownloadFlakyString(new Uri(GetApiUrl()));

            Data.SellPrices sellPrices = JsonConvert.DeserializeObject <Data.SellPrices>(response);

            List <ExchangeInformation> results = new List <ExchangeInformation>();

            results.Add(new ExchangeInformation()
            {
                SourceCurrency = "BTC",
                TargetCurrency = "USD",
                TargetSymbol   = "$",
                ExchangeRate   = sellPrices.Subtotal.Amount
            });

            return(results);
        }
Example #47
0
        public static void SubmitNotifications(string url, string apiKey, string emailAddress, string applicationKey, List <Data.Notification> notifications)
        {
            if (!url.EndsWith("/"))
            {
                url = url + "/";
            }
            string fullUrl = String.Format("{0}NotificationsInput?emailAddress={1}&applicationKey={2}&apiKey={3}&detailed=true",
                                           url, emailAddress, applicationKey, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                string jsonData = JsonConvert.SerializeObject(notifications);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                ExecuteWebAction(() =>
                {
                    return(client.UploadString(fullUrl, jsonData));
                });
            }
        }
Example #48
0
 internal Authenticator(ApiWebClient apiWebClient, string publicKey, string privateKey) : this(apiWebClient)
 {
     PublicKey = publicKey;
     PrivateKey = privateKey;
     apiWebClient.Authenticator = this;
 }
Example #49
0
 internal Authenticator(ApiWebClient apiWebClient)
 {
     ApiWebClient = apiWebClient;
 }
Example #50
0
 internal Authenticator(ApiWebClient apiWebClient)
 {
     ApiWebClient = apiWebClient;
     if (!IsTimeDifferenceSet) SyncTime();
 }