Example #1
0
        public ActionResult getDataUsage(string routerID)
        {
            //get vars for api keys
            List <systemvar> vars = truckService.getAppVars();
            List <NDMDatum>  NDs  = new List <NDMDatum>();
            var totalBytes        = 0;

            var client = new RestClient();

            client.BaseUrl = new Uri("https://www.cradlepointecm.com/");

            var request = new RestRequest();

            request.Resource = "api/v2/net_devices/";
            request.AddParameter("router", routerID);

            // easily add HTTP Headers
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("X-CP-API-ID", vars.Where(v => v.varName == "X-CP-API-ID").Select(x => x.varVal).FirstOrDefault());
            request.AddHeader("X-CP-API-KEY", vars.Where(v => v.varName == "X-CP-API-KEY").Select(x => x.varVal).FirstOrDefault());
            request.AddHeader("X-ECM-API-ID", vars.Where(v => v.varName == "X-ECM-API-ID").Select(x => x.varVal).FirstOrDefault());
            request.AddHeader("X-ECM-API-KEY", vars.Where(v => v.varName == "X-ECM-API-KEY").Select(x => x.varVal).FirstOrDefault());

            IRestResponse        response = client.Execute(request);
            NetDevicesRootobject devices  = JsonConvert.DeserializeObject <NetDevicesRootobject>(response.Content);

            foreach (NetDevicesDatum device in devices.data)
            {
                if (device.mode == "wan" && device.service_type == "LTE")
                {
                    var client2 = new RestClient();
                    client2.BaseUrl = new Uri("https://www.cradlepointecm.com/");
                    var request2 = new RestRequest();

                    request2.AddHeader("Content-Type", "application/json");
                    request2.AddHeader("X-CP-API-ID", vars.Where(v => v.varName == "X-CP-API-ID").Select(x => x.varVal).FirstOrDefault());
                    request2.AddHeader("X-CP-API-KEY", vars.Where(v => v.varName == "X-CP-API-KEY").Select(x => x.varVal).FirstOrDefault());
                    request2.AddHeader("X-ECM-API-ID", vars.Where(v => v.varName == "X-ECM-API-ID").Select(x => x.varVal).FirstOrDefault());
                    request2.AddHeader("X-ECM-API-KEY", vars.Where(v => v.varName == "X-ECM-API-KEY").Select(x => x.varVal).FirstOrDefault());

                    request2.Resource = "api/v2/net_device_metrics/";
                    request2.AddParameter("net_device", device.id);

                    IRestResponse response2 = client2.Execute(request2);
                    NDMRootobject dms       = JsonConvert.DeserializeObject <NDMRootobject>(response2.Content);
                    NDs.Add(dms.data[0]);
                }
            }

            return(Json(NDs, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult getECMSignalStrength(string routerID)
        {
            //initialize RouterSignal
            List <RouterSignal> RSList = new List <RouterSignal>();

            //get vars for api keys
            List <systemvar> vars = truckService.getAppVars();

            var client = new RestClient();

            client.BaseUrl = new Uri("https://www.cradlepointecm.com/");

            var request = new RestRequest();

            request.Resource = "api/v2/net_devices";
            request.AddParameter("router", routerID);

            // easily add HTTP Headers
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("X-CP-API-ID", vars.Where(v => v.varName == "X-CP-API-ID").Select(x => x.varVal).FirstOrDefault());
            request.AddHeader("X-CP-API-KEY", vars.Where(v => v.varName == "X-CP-API-KEY").Select(x => x.varVal).FirstOrDefault());
            request.AddHeader("X-ECM-API-ID", vars.Where(v => v.varName == "X-ECM-API-ID").Select(x => x.varVal).FirstOrDefault());
            request.AddHeader("X-ECM-API-KEY", vars.Where(v => v.varName == "X-ECM-API-KEY").Select(x => x.varVal).FirstOrDefault());

            IRestResponse        response = client.Execute(request);
            NetDevicesRootobject devices  = JsonConvert.DeserializeObject <NetDevicesRootobject>(response.Content);

            foreach (NetDevicesDatum device in devices.data)
            {
                if (device.mode == "wan" && device.service_type == "LTE")
                {
                    RouterSignal rs = getRouterStrength(device);
                    RSList.Add(rs);
                }
            }

            return(Json(RSList, JsonRequestBehavior.AllowGet));
        }