Exemplo n.º 1
0
        // TODO: use base("/api");
        public ApiModule(IStatisticsManager statisticsManager, IPoolManager poolManager, IAlgorithmManager algorithmManager)
            : base("/api")
        {
            Get["/"] = _ =>
            {
                // include common data required by layout.
                ViewBag.Title      = "API";
                ViewBag.Heading    = "Public API";
                ViewBag.Pools      = poolManager;
                ViewBag.LastUpdate = statisticsManager.LastUpdate.ToString("HH:mm:ss tt zz"); // last statistics update.

                // return our view
                return(View["api", new ApiModel
                            {
                                BaseUrl = Request.Url.SiteBase,
                                Coin = poolManager.First().Config.Coin
                            }]);
            };


            Get["/pools"] = _ =>
            {
                var response = (Response)poolManager.ServiceResponse;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/pool/{slug}"] = _ =>
            {
                var pool = poolManager.Get(_.slug); // query the requested pool.

                var response = pool != null ? (Response)pool.ServiceResponse : PoolNotFound;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/algorithms"] = _ =>
            {
                var response = (Response)algorithmManager.ServiceResponse;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/algorithm/{slug}"] = _ =>
            {
                var algorithm = algorithmManager.Get(_.slug); // query the requested pool.

                var response = algorithm != null ? (Response)algorithm.ServiceResponse : AlgorithmNotFound;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/global"] = _ =>
            {
                var response = (Response)statisticsManager.ServiceResponse;
                response.ContentType = "application/json";
                return(response);
            };
        }
Exemplo n.º 2
0
        public ApiModule(IStatisticsManager statisticsManager, IPoolManager poolManager, IAlgorithmManager algorithmManager)
            : base("/api")
        {
            Get["/"] = _ =>
            {
                // include common data required by layout.
                ViewBag.Header = "Public API";

                // return our view
                return(View["api", new ApiModel
                            {
                                BaseUrl = Request.Url.SiteBase,
                                Coin = poolManager.First().Config.Coin
                            }]);
            };


            Get["/pools"] = _ =>
            {
                var response = (Response)poolManager.ServiceResponse;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/pool/{slug}"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // query the requested pool.

                var response = pool != null ? (Response)pool.ServiceResponse : PoolNotFound;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/algorithms"] = _ =>
            {
                var response = (Response)algorithmManager.ServiceResponse;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/algorithm/{slug}"] = _ =>
            {
                var algorithm = algorithmManager.Get(HttpUtility.HtmlEncode(_.slug)); // query the requested pool.

                var response = algorithm != null ? (Response)algorithm.ServiceResponse : AlgorithmNotFound;
                response.ContentType = "application/json";
                return(response);
            };

            Get["/global"] = _ =>
            {
                var response = (Response)statisticsManager.ServiceResponse;
                response.ContentType = "application/json";
                return(response);
            };
        }
Exemplo n.º 3
0
        public ApiModule(IStatisticsManager statisticsManager, IPoolManager poolManager, IAlgorithmManager algorithmManager)
            : base("/api")
        {
            Get["/"] = _ =>
            {
                // include common data required by layout.
                ViewBag.Header = "Public API";

                // return our view
                return View["api", new ApiModel
                {
                    BaseUrl = Request.Url.SiteBase,
                    Coin = poolManager.First().Config.Coin
                }];
            };

            Get["/pools"] = _ =>
            {
                var response = (Response) poolManager.ServiceResponse;
                response.ContentType = "application/json";
                return response;
            };

            Get["/pool/{slug}"] = _ =>
            {
                var pool = poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // query the requested pool.

                var response = pool != null ? (Response)pool.ServiceResponse : PoolNotFound;
                response.ContentType = "application/json";
                return response;
            };

            Get["/algorithms"] = _ =>
            {
                var response = (Response)algorithmManager.ServiceResponse;
                response.ContentType = "application/json";
                return response;
            };

            Get["/algorithm/{slug}"] = _ =>
            {
                var algorithm = algorithmManager.Get(HttpUtility.HtmlEncode(_.slug)); // query the requested pool.

                var response = algorithm != null ? (Response)algorithm.ServiceResponse : AlgorithmNotFound;
                response.ContentType = "application/json";
                return response;
            };

            Get["/global"] = _ =>
            {
                var response = (Response) statisticsManager.ServiceResponse;
                response.ContentType = "application/json";
                return response;
            };
        }