Example #1
0
        //GetUserEmail function
        public void GetUserEmail()
        {
            if (User_Token != "")
            {
                HttpsClient         MyHttpsConnection = new HttpsClient();
                HttpsClientRequest  MyHttpsRequest    = new HttpsClientRequest();
                HttpsClientResponse MyHttpsResponse;
                string   HttpsUrl;
                string   MyTempString;
                string[] words;
                string   commandstring = "";
                bool     FoundEmail    = false;

                MyHttpsConnection.PeerVerification = false;
                MyHttpsConnection.HostVerification = false;
                MyHttpsConnection.Verbose          = false;
                HttpsUrl = "https://api.pushbullet.com/v2/users/me";

                MyHttpsRequest.KeepAlive = true;
                MyHttpsRequest.Url.Parse(HttpsUrl);
                MyHttpsRequest.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Get;
                MyHttpsRequest.Header.SetHeaderValue("Authorization", "Bearer " + User_Token);

                PrintString2 = User_Token;

                MyHttpsRequest.ContentString = commandstring;

                // Dispatch will actually make the request with the server
                MyHttpsResponse = MyHttpsConnection.Dispatch(MyHttpsRequest);
                MyHttpsConnection.Abort();

                MyTempString = MyHttpsResponse.ContentString.ToString();
                words        = MyTempString.Split(',');

                PrintString = "";

                foreach (string word in words)
                {
                    PrintString = PrintString + '+' + word;

                    if (word.Contains("email_normalized"))
                    {
                        User_Email = word.Substring(20, word.Length - 21);

                        FoundEmail = true;
                    }
                }
                if (!FoundEmail)
                {
                    User_Email = "Email Not Found!";
                }
            }
            else
            {
                PrintString = "No Token Found";
            }
        }
Example #2
0
        //GetPush method that establish the https connection with PushBullet API and retrieves the Pushes
        public void GetPush()
        {
            if (User_Token != "")
            {
                HttpsClient         MyHttpsConnection = new HttpsClient();
                HttpsClientRequest  MyHttpsRequest    = new HttpsClientRequest();
                HttpsClientResponse MyHttpsResponse;
                string   HttpsUrl;
                string   MyTempString;
                string[] words;
                string   commandstring = "";
                bool     FoundBody     = false;

                MyHttpsConnection.PeerVerification = false;
                MyHttpsConnection.HostVerification = false;
                MyHttpsConnection.Verbose          = false;
                MyHttpsConnection.UserName         = User_Token;
                //limit the push outputs to 3
                HttpsUrl = "https://api.pushbullet.com/v2/pushes?limit=3";

                MyHttpsRequest.KeepAlive = true;
                MyHttpsRequest.Url.Parse(HttpsUrl);
                MyHttpsRequest.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Get;
                MyHttpsRequest.Header.SetHeaderValue("Content-Type", "application/json");
                MyHttpsRequest.Header.SetHeaderValue("Authorization", "Bearer " + User_Token);

                PrintString2 = User_Token;

                MyHttpsRequest.ContentString = commandstring;

                // Dispatch will actually make the request with the server
                MyHttpsResponse = MyHttpsConnection.Dispatch(MyHttpsRequest);
                MyHttpsConnection.Abort();

                MyTempString = MyHttpsResponse.ContentString.ToString();
                words        = MyTempString.Split(',');

                PrintString = "";

                foreach (string word in words)
                {
                    PrintString = PrintString + '+' + word;

                    if (word.Contains("body"))
                    {
                        PushReceived = word.Substring(8, word.Length - 10);

                        PushReceived = PushReceived.ToLower();

                        FoundBody = true;

                        break;
                    }
                }

                if (!FoundBody)
                {
                    User_Email = "Push Message Not Received";
                }
            }
            else
            {
                PrintString = "No Token Found";
            }
        }