public HttpWebRequest EditDocument(string documentId, string projectCode, int projectId, int issueId)
        {
            InMemoryTokenManager t = GetTokenManager(_user);

            var lucid = new WebConsumer(ServiceDescription, t);

            return(lucid.PrepareAuthorizedRequest(new MessageReceivingEndpoint(string.Format(lucidBaseChartUrl + "documents/edit/{0}?callback={4}apps/lucidchart/editdocument/{1}/{2}/{3}", documentId, projectCode, projectId, issueId, _geminiUrl), HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), _user.Token));
        }
        public LucidDocument GetDocumentDescription(string documentId)
        {
            InMemoryTokenManager t = GetTokenManager(_user);

            var lucid = new WebConsumer(ServiceDescription, t);

            string url = lucidBaseChartUrl + "documents/describe/" + documentId;

            HttpWebRequest req = lucid.PrepareAuthorizedRequest(new MessageReceivingEndpoint(url, HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), _user.Token);

            req.ContentType = "application/xml";

            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

            string xml = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            LucidDocument document = new LucidDocument();

            XmlElement elm = doc.DocumentElement;

            foreach (XmlElement n in elm.ChildNodes[0])
            {
                switch (n.Name.ToLower())
                {
                case "documentid":
                    document.Id = n.InnerText;
                    break;

                case "title":
                    document.Name = n.InnerText;
                    break;

                case "editurl":
                    document.EditUrl = n.InnerText;
                    break;

                case "viewurl":
                    document.ViewUrl = n.InnerText;
                    break;

                case "version":
                    document.Version = n.InnerText;
                    break;

                case "pagecount":
                    document.PageCount = n.InnerText.ToInt();
                    break;
                }
            }

            return(document);
        }
        internal static InMemoryTokenManager GetTokenManager(LucidChartUser user)
        {
            /*InMemoryTokenManager t = new InMemoryTokenManager("2f5f3b5ff6f0cf6ed2e36541d9fa6939", "0c709b00d02237168e5bd840a817f1b7");
             * t.SetToken("533ccd4b7bb82abd7cbfc6909892604d58e37f2d", "eb803f21bc177b3e40c02294faeeebd5a0e68d5b");*/

            //InMemoryTokenManager t = new InMemoryTokenManager("890e6c36a8f93100532ddd262d172726", "75e16f21d1bbdd6f978ea03426d3df70");
            InMemoryTokenManager t = new InMemoryTokenManager(consumerKey, consumerSecret);

            t.SetToken(user.Token, user.Secret);

            return(t);
        }
        public byte[] GetDocumentImage(string documentId, int page, int width, bool square)
        {
            InMemoryTokenManager t = GetTokenManager(_user);

            var lucid = new WebConsumer(ServiceDescription, t);

            HttpWebRequest req = lucid.PrepareAuthorizedRequest(new MessageReceivingEndpoint(string.Format("{4}documents/image/{0}/{1}/{2}/{3}", documentId, page, width, square ? 1 : 0, lucidBaseChartUrl), HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest), _user.Token);

            byte[] buffer = new byte[1024 * 32];

            using (Stream s = req.GetResponse().GetResponseStream())
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    int read;
                    while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    return(ms.ToArray());
                }
            }
        }