Esempio n. 1
0
        public void doPost(string username, string password)
        {
            string userdefault = Txt.read(Txt.path);

            if (userdefault != "")
            {
                JObject obj = JObject.Parse(userdefault);

                string expire = obj["expires_in"].ToString();
                expire = expire.Substring(1, expire.Length - 2);
                DateTime exp = DateTime.Parse(expire);
                if (exp.CompareTo(DateTime.Now) > 0)
                {
                    handleLogin(userdefault);
                    return;
                }
            }

            string url = "https://home.nest.com/user/login";

            url = url + "?username="******"&password="******"Https Data: " + s);
                        handleLogin(s);
                    }
                }
                catch (Exception f)
                {
                    CrestronConsole.PrintLine("Connection error:" + f.ToString());
                }
            });
        }
Esempio n. 2
0
        public void doRequest(string param, string nestID, string action)
        {
            string userdefault = Txt.read(Txt.path);
            string url         = "";
            string token       = "";

            if (userdefault != "")
            {
                JObject obj = JObject.Parse(userdefault);
                url   = obj["urls"]["transport_url"].ToString();
                token = obj["access_token"].ToString();
            }


            HttpsClient client = new HttpsClient();

            client.Verbose          = false;
            client.PeerVerification = false;
            client.HostVerification = false;
            HttpsClientRequest request = new HttpsClientRequest();

            request.KeepAlive = true;
            request.Url.Parse(url + "/v2/put/" + action + "." + nestID);

            request.Header.SetHeaderValue("X-nl-protocol-version", "1");
            request.Header.SetHeaderValue("Authorization", "Basic " + token);

            request.ContentString = param;
            request.RequestType   = RequestType.Post;

            client.DispatchAsync(request, (hscrs, e) =>
            {
                try
                {
                    if (hscrs.Code >= 200 && hscrs.Code < 300)
                    {
                        // success
                        CrestronConsole.PrintLine("success.");
                    }
                }
                catch (Exception f)
                {
                    CrestronConsole.PrintLine("Connection error:" + f.ToString());
                }
            });
        }