/*
         * This method is used to (POST) invite the signers to sign on  the document in the SignNow Application
         */
        public string Invite(Oauth2Token token, Invitation invitation, string id)
        {
            string result = null;
            try
            {
                string requestBody = JsonConvert.SerializeObject(invitation, Formatting.Indented);
                var client = new RestClient();
                client.BaseUrl = config.GetApiBase();

                var request = new RestRequest("/document" + "/" + id + "/invite?email=disable", Method.POST)
                        .AddHeader("Accept", "application/json")
                        .AddHeader("Content-Type", "application/json")
                        .AddHeader("Authorization", "Bearer " + token.AccessToken);
                request.RequestFormat = DataFormat.Json;
                request.AddBody(invitation);


                var httpResponse = client.Execute(request);
                string json = httpResponse.Content.ToString();
                JObject res = JObject.Parse(json);
                if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.OK))
                {
                    result = res["result"].ToString();
                }
                else if (httpResponse.StatusCode.Equals(System.Net.HttpStatusCode.BadRequest))
                {
                    result = res["error"].ToString();
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(string.Format("Exception: {0}", ex.Message));
                throw;
            }
            return result;
        }
        public void CancelInvite()
        {
            string randomEmail = "lukeskywalker" + DateTime.Now.ToBinary().ToString() + "@mailinator.com";
            User user = new User();
            user.Email = randomEmail;
            user.Password = "******";
            user.FirstName = "firstName";
            user.LastName = "LastName";

            User resultUser = cudasign.userService.Create(user);

            Assert.IsNotNull("No user id from creating user", resultUser.Id);
            resultUser.Password = "******";

            Oauth2Token requestedToken = cudasign.authenticationService.RequestToken(resultUser);
            Assert.IsNotNull("Access Token", requestedToken.AccessToken);

            Document doc = new Document();
            if (Directory.Exists(InputdirPath))
            {
                string[] DocFilePath = Directory.GetFiles(@InputdirPath);
                doc.FilePath = DocFilePath[0];
            }

            Document document = cudasign.documentService.Create(requestedToken, doc);
            Assert.IsNotNull("DocumentId", document.Id);

            string toEmail = "deepak" + DateTime.Now.ToBinary().ToString() + "@mailinator.com";
            Invitation invitation = new Invitation();
            invitation.From = resultUser.Email;
            invitation.To = toEmail;

            string resinvite = cudasign.documentService.Invite(requestedToken, invitation, document.Id);
            Assert.AreEqual("success", resinvite);

            string cancelinvite = cudasign.documentService.CancelInvite(requestedToken, document.Id);
            Assert.AreEqual("success", cancelinvite);
        }