当前位置: 首页>>代码示例>>C#>>正文


C# Client.RequestBody类代码示例

本文整理汇总了C#中DocuSign.Integrations.Client.RequestBody的典型用法代码示例。如果您正苦于以下问题:C# RequestBody类的具体用法?C# RequestBody怎么用?C# RequestBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RequestBody类属于DocuSign.Integrations.Client命名空间,在下文中一共展示了RequestBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddDocument

        /// <summary>
        /// Add documents to this envelope (must be in draft state)
        /// </summary>
        /// <param name="fileBytes">new file content</param>
        /// <param name="fileName">new file name</param>
        /// <param name="index">Index for the new file</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddDocument(List<byte[]> fileBytesList, List<string> fileNames, int index = 1)
        {
            RequestBuilder builder = new RequestBuilder();
            RequestInfo req = new RequestInfo();
            List<RequestBody> requestBodies = new List<RequestBody>();

            req.RequestContentType = "multipart/form-data";
            req.BaseUrl = this.Login.BaseUrl;
            req.LoginEmail = this.Login.Email;
            //req.LoginPassword = this.Login.Password;
            req.ApiPassword = this.Login.ApiPassword;
            req.Uri = "/envelopes/" + EnvelopeId + "/documents";
            req.HttpMethod = "PUT";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;
            req.IsMultipart = true;
            req.MultipartBoundary = Guid.NewGuid().ToString();
            builder.Proxy = this.Proxy;

            RequestBody rb = new RequestBody();
            rb.Text = this.CreateJson(fileNames, index);
            rb.Headers.Add("Content-Type", "application/json");
            rb.Headers.Add("Content-Disposition", "form-data");
            requestBodies.Add(rb);

            rb = new RequestBody();

            for (int i = 0; i < fileNames.Count; i++)
            {
                var fileName = fileNames[i];
                RequestBody reqFile = new RequestBody();
                string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                reqFile.Headers.Add("Content-Type", mime);
                reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, index++));

                reqFile.FileBytes = fileBytesList[i];
                reqFile.SubstituteStrings = false;
                requestBodies.Add(reqFile);
            }

            req.RequestBody = requestBodies.ToArray();
            builder.Request = req;

            ResponseInfo response = builder.MakeRESTRequest();
            this.Trace(builder, response);

            if ((response.StatusCode == HttpStatusCode.OK) && (!response.ResponseText.Contains("FORMAT_CONVERSION_ERROR")))
            {
                this.ParseCreateResponse(response);
                return true;
            }
            else
            {
                this.ParseErrorResponse(response);
                return false;
            }
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:63,代码来源:Envelope.cs

示例2: CreateTemplate

        /// <summary>
        /// Creates a new template
        /// </summary>
        /// <param name="fileBytes">Byte arrays of the files' content - in correct order.</param>
        /// <param name="fileNames">File names - in correct order</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool CreateTemplate(List<byte[]> fileBytesList, List<string> fileNames, string templateName)
        {
            CheckAPIPreRequisites();
            if (fileNames.Count != fileBytesList.Count)
            {
                throw new ArgumentException("Mismatch between number of files names and files' bytes content - they must be the same");
            }
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                //req.LoginPassword = this.Login.Password;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/templates?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");
                rb.Text = this.CreateJson(fileNames);
                rb.Text += "  \"envelopeTemplateDefinition\": {\"name\": \"" + templateName + "\"}";
                requestBodies.Add(rb);

                for (int i = 0; i < fileNames.Count; i++)
                {
                    var fileName = fileNames[i];
                    RequestBody reqFile = new RequestBody();
                    string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                    reqFile.Headers.Add("Content-Type", mime);
                    reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, i + 1));

                    reqFile.FileBytes = fileBytesList[i];
                    reqFile.SubstituteStrings = false;
                    requestBodies.Add(reqFile);
                }

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;

                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject json = JObject.Parse(response.ResponseText);
                    this.EnvelopeId = (string)json["templateId"];
                    return this.GetSenderView(string.Empty);
                }
                else
                {
                    this.ParseErrorResponse(response);
                    return false;
                }
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:joepetrakovich,项目名称:DocuSign-.NET-Client,代码行数:80,代码来源:Template.cs

示例3: AddCustomFields

        /// <summary>
        /// Add custom fields to this envelope
        /// </summary>
        /// <param name="customFields">Dictionary of custom fields to be added</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddCustomFields(Dictionary<string, object> customFields)
        {
            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = Login.BaseUrl;
                req.LoginEmail = Login.Email;
                req.LoginPassword = Login.Password;
                req.ApiPassword = Login.ApiPassword;
                req.Uri = String.Format("/envelopes/{0}/custom_fields", EnvelopeId);
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                var customFieldsArray = EnvelopeStatus.CustomField.CreateCustomFieldsArray(customFields);
                var textCustomFields = new Dictionary<string, TextCustomField[]>(){
                    {"textCustomFields" , customFieldsArray}
                };

                rb.Text = JsonConvert.SerializeObject(textCustomFields);
                requestBodies.Add(rb);
                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:57,代码来源:Envelope.cs

示例4: AddTabs

        /// <summary>
        /// Adds tabs to the envelope for the first/default recipient 
        /// </summary>
        /// <param name="tabs">List of tabs to add</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddTabs(TabCollection tabs)
        {
            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.LoginPassword = this.Login.Password;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = string.Format("/envelopes/{0}/recipients/{1}/tabs", EnvelopeId, (string)(GetFirstRecipients().First())["recipientIdGuid"]);
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                foreach (var tab in tabs.textTabs)
                    tab.tabLabel = Guid.NewGuid().ToString();
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                rb.Text = JsonConvert.SerializeObject(tabs, settings);

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:63,代码来源:Envelope.cs

示例5: SendReminder

        /// <summary>
        /// Sends a reminder to recipient(s) that they need to sign
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool SendReminder()
        {
            RequestInfo req = new RequestInfo();
            req.RequestContentType = "application/json";
            req.AcceptContentType = "application/json";
            req.BaseUrl = Login.BaseUrl;
            req.LoginEmail = Login.Email;
            req.LoginPassword = Login.Password;
            req.ApiPassword = Login.ApiPassword;
            req.Uri = String.Format("/envelopes/{0}?resend_envelope=true", EnvelopeId);
            req.HttpMethod = "PUT";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;

            RequestBuilder builder = new RequestBuilder();
            builder.Proxy = Proxy;
            builder.Request = req;

            List<RequestBody> requestBodies = new List<RequestBody>();
            RequestBody rb = new RequestBody();
            rb.Text = "{}";
            requestBodies.Add(rb);
            req.RequestBody = requestBodies.ToArray();
            builder.Request = req;
            ResponseInfo response = builder.MakeRESTRequest();
            this.Trace(builder, response);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                this.ParseErrorResponse(response);
                return false;
            }

            return true;
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:38,代码来源:Envelope.cs

示例6: GetDraftEnvelopes

        /// <summary>
        /// Get draft envelopes for this user's account
        /// </summary>
        /// <param name="fromDate">start date to find envelopes for this user</param>
        /// <returns>List of envelopes for this account</returns>
        public AccountEnvelopes GetDraftEnvelopes(DateTime fromDate)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }


            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/search_folders/drafts?api_password=true&from_date=" + fromDate.ToString();
                req.HttpMethod = "GET";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;


                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;

                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                var envs = new List<EnvelopeInfo>();
                JObject json = JObject.Parse(response.ResponseText);
                foreach (var item in json["folderItems"])
                {
                    var ei = new EnvelopeInfo();
                    ei.EnvelopeId = (string)item["envelopeId"];
                    ei.StatusChangedDateTime = (string)item["createdDateTime"];
                    ei.Status = "created";
                    envs.Add(ei);
                }
                return new AccountEnvelopes { Envelopes = envs.ToArray() };

            }
            catch
            {
                throw;
            }

        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:71,代码来源:Envelope.cs

示例7: AddTemplates

        /// <summary>
        /// Adds a set of templates to the envelope
        /// </summary>
        /// <param name="templates">List of templates with auxiliary info such as documentStartPage etc.</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddTemplates(DocumentTemplates templates)
        {
            if (templates == null || templates.documentTemplates.Length == 0)
            {
                throw new ArgumentException("Empty set of template IDS provided");
            }
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.DistributorCode = RestSettings.Instance.DistributorCode;
                req.DistributorPassword = RestSettings.Instance.DistributorPassword;
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.Uri = string.Format("{0}/envelopes/{1}/templates", this.Login.BaseUrl, this.EnvelopeId);

                builder.Request = req;
                builder.Proxy = this.Proxy;
                
                RequestBody rb = new RequestBody();
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                rb.Text = JsonConvert.SerializeObject(templates, settings);
                requestBodies.Add(rb);
                req.RequestBody = requestBodies.ToArray();

                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:61,代码来源:Envelope.cs

示例8: AddUser

        /// <summary>
        /// Adds a new user to an existing account
        /// </summary>
        /// <param name="users">Object representing the users to add</param>
        /// <returns>List of created users</returns>
        /// <exception cref="ArgumentNullException">If email, users or accountId are missing</exception>
        public CreatedUsers AddUser(AddUsers users)
        {
            if (users == null)
            {
                throw new ArgumentNullException("NewUser");
            }

            if (string.IsNullOrEmpty(this.Email) == true)
            {
                throw new ArgumentNullException("Email");
            }

            if (string.IsNullOrEmpty(this.AccountId) == true)
            {
                throw new ArgumentNullException("AccountId");
            }

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Email;
                req.LoginPassword = string.IsNullOrEmpty(this.ApiPassword) == false ? this.ApiPassword : this.Password;
                req.DistributorCode = RestSettings.Instance.DistributorCode;
                req.DistributorPassword = RestSettings.Instance.DistributorPassword;
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                string method = string.Format("/accounts/{0}/users?api_password=true", this.AccountId);

                if (String.IsNullOrEmpty(this.BaseUrl))
                {
                    req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, method);
                }
                else
                {
                    req.Uri = string.Format("{0}{1}", this.BaseUrl, "/users?api_password=true");
                }

                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = users.Serialize();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return null;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                    return null;
                }

                return CreatedUsers.FromJson(response.ResponseText);
            }
            catch
            {
            }

            return null;
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:82,代码来源:Account.cs

示例9: AssociateSocialAccount

        /// <summary>
        /// Adds social credentials to an existing account
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        /// <exception cref="ArgumentException">If insufficient information to associate account</exception>
        public bool AssociateSocialAccount()
        {
            if (this.ValidateSocial() == false)
            {
                throw new ArgumentException("Insufficient information to associate account");
            }

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "PUT";
                req.ApiPassword = this.ApiPassword;
                req.LoginEmail = this.Email;
                req.Uri = string.Format("{0}/users/{2}/social.json", this.BaseUrl, this.AccountId, this.UserId);
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = this.ConstructAssociateJson();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.OK;
            }
            catch
            {
                return false;
            }
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:56,代码来源:Account.cs

示例10: RemoveDocument

        /// <summary>
        /// Remove documents from this envelop (must be in draft state)
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool RemoveDocument(List<string> docList)
        {
            CheckAPIPreRequisites();
            if (docList == null)
            {
                return false;
            }

            if (docList.Count == 0)
            {
                return true;
            }

            List<Document> docs = new List<Document>();

            foreach (string docId in docList)
            {
                var doc = new Document { documentId = docId };
                docs.Add(doc);
            }
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = string.Format("/envelopes/{0}/documents/", this.EnvelopeId);
                req.HttpMethod = "DELETE";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                EnvelopeCreate env = new EnvelopeCreate();
                env.documents = docs.ToArray();

                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                rb.Text = JsonConvert.SerializeObject(env, settings);
                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;

                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                return response.StatusCode == HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:Lulubul,项目名称:DocuSign-.NET-Client,代码行数:68,代码来源:Envelope.cs

示例11: Create

        /// <summary>
        /// Creates a new account based on the account information provided.
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        /// <exception cref="ArgumentNullException">If password or email are missing</exception>
        public bool Create()
        {
            if (string.IsNullOrEmpty(this.Email) == true)
            {
                throw new ArgumentNullException("Email");
            }

            if (string.IsNullOrEmpty(this.AccountName) == true && this.ValidateSocial() == false)
            {
                throw new ArgumentException("Insufficient information to create account");
            }

            // clear out any previous account information
            this.BaseUrl = string.Empty;
            this.ApiPassword = string.Empty;
            this.IsDefault = false;

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Email;
                req.LoginPassword = this.Password;
                req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, "/accounts?api_password=true&include_account_id_guid=true");
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = this.ConstructNewAccountJson();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    this.ParseCreateResponse(response);
                }
                else
                {
                    this.ParseErrorResponse(response);
                }
                return response.StatusCode == HttpStatusCode.Created;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:75,代码来源:Account.cs

示例12: AddDocument

        /// <summary>
        /// Add documents to this envelope (must be in draft state)
        /// </summary>
        /// <param name="fileBytes">new file content</param>
        /// <param name="fileName">new file name</param>
        /// <param name="index">Index for the new file</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddDocument(List<byte[]> fileBytesList, List<string> fileNames, int index = 1)
        {
            CheckAPIPreRequisites();
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = string.Format("/envelopes/{0}/documents", this.EnvelopeId);
                req.HttpMethod = "PUT";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = Guid.NewGuid().ToString();
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                rb.Text = this.CreateJson(fileNames, index);
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");
                requestBodies.Add(rb);

                rb = new RequestBody();

                for (int i = 0; i < fileNames.Count; i++)
                {
                    var fileName = fileNames[i];
                    RequestBody reqFile = new RequestBody();
                    string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                    reqFile.Headers.Add("Content-Type", mime);
                    reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, index++));

                    reqFile.FileBytes = fileBytesList[i];
                    reqFile.SubstituteStrings = false;
                    requestBodies.Add(reqFile);
                }

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;

                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if ((response.StatusCode == HttpStatusCode.OK) && (!response.ResponseText.Contains("FORMAT_CONVERSION_ERROR")))
                {
                    this.ParseCreateResponse(response);
                    return true;
                }
                else
                {
                    this.ParseErrorResponse(response);
                    return false;
                }
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:Lulubul,项目名称:DocuSign-.NET-Client,代码行数:76,代码来源:Envelope.cs

示例13: GetRecipientView

        /// <summary>
        /// Once an envelope has been created, this method obtains the URL to the recipient view
        /// </summary>
        /// <param name="returnUrl">URL to take user after signing is completed</param>
        /// <param name="signAndReturn">Optional - should new signing expereince show the "Sign and Return" dialog for self-signed envelopes</param>
        /// <param name="authMethod">Optional - the main authentication method that will be listed in the envelope's certificate of completion</param>        
        /// <returns>true if successful, false otherwise</returns>
        public bool GetRecipientView(string returnUrl, bool signAndReturn = true, string authMethod = "email")
        {
            CheckAPIPreRequisites();
            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = string.Format("/envelopes/{0}/views/recipient.json?api_password=true", this.EnvelopeId);
                if (!signAndReturn)
                {
                    req.Uri += "&disable_cc_for_selfsign=true";
                }
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                if (string.IsNullOrWhiteSpace(this.Login.SOBOUserId) == false)
                {
                    req.SOBOUserId = this.Login.SOBOUserId;
                    builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
                }

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                RecipientView rv = new RecipientView();
                rv.returnUrl = returnUrl;
                rv.email = this.Login.Email;
                rv.userName = this.Login.AccountName;
                rv.authenticationMethod = authMethod;

                rb.Text = rv.Serialize();
                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject json = JObject.Parse(response.ResponseText);

                    this.SenderViewUrl = (string)json["url"] + "&noDownloadPrint=true&appname=docusignit";
                }
                else
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:Lulubul,项目名称:DocuSign-.NET-Client,代码行数:77,代码来源:Envelope.cs

示例14: Create

        /// <summary>
        /// Creates an envelope for the user.
        /// </summary>
        /// <param name="fileBytesList">Byte arrays of the files' content - in correct order.</param>
        /// <param name="documents">Documents - in correct order</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool Create(List<byte[]> fileBytesList, List<Document> documents)
        {
            CheckAPIPreRequisites();

            if (documents.Count != fileBytesList.Count)
            {
                throw new ArgumentException("Mismatch between number of files names and files' bytes content - they must be the same");
            }
            try
            {
                var builder = new RequestBuilder();
                var req = new RequestInfo();
                var requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/envelopes?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = Proxy;

                if (string.IsNullOrWhiteSpace(Login.SOBOUserId) == false)
                {
                    req.SOBOUserId = this.Login.SOBOUserId;
                    builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
                }

                var rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");
                rb.Text = CreateJson(documents);
                requestBodies.Add(rb);

                for (var i = 0; i < documents.Count; i++)
                {
                    var reqFile = new RequestBody();
                    var mime = string.IsNullOrEmpty(MimeType) ? DefaultMimeType : MimeType;
                    reqFile.Headers.Add("Content-Type", mime);
                    reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", documents[i].name, i + 1));

                    reqFile.FileBytes = fileBytesList[i];
                    reqFile.SubstituteStrings = false;
                    requestBodies.Add(reqFile);
                }

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;

                var response = builder.MakeRESTRequest();
                Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    ParseCreateResponse(response);
                    return GetSenderView(string.Empty);
                }

                ParseErrorResponse(response);

                return response.StatusCode == HttpStatusCode.Created;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
开发者ID:Lulubul,项目名称:DocuSign-.NET-Client,代码行数:82,代码来源:Envelope.cs

示例15: RemoveDocument

        /// <summary>
        /// Remove documents from this envelop (must be in draft state)
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool RemoveDocument(List<string> docList)
        {
            if (docList == null)
            {
                return false;
            }

            if (docList.Count == 0)
            {
                return true;
            }

            List<Document> docs = new List<Document>();

            foreach (string docId in docList)
            {
                var doc = new Document { documentId = docId };
                docs.Add(doc);
            }

            RequestBuilder builder = new RequestBuilder();
            RequestInfo req = new RequestInfo();
            List<RequestBody> requestBodies = new List<RequestBody>();

            req.RequestContentType = "application/json";
            req.AcceptContentType = "application/json";
            req.BaseUrl = this.Login.BaseUrl;
            req.LoginEmail = this.Login.Email;
            //req.LoginPassword = this.Login.Password;
            req.ApiPassword = this.Login.ApiPassword;
            req.Uri = "/envelopes/" + EnvelopeId + "/documents/";
            req.HttpMethod = "DELETE";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;
            builder.Proxy = this.Proxy;

            RequestBody rb = new RequestBody();
            EnvelopeCreate env = new EnvelopeCreate();
            env.documents = docs.ToArray();

            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.NullValueHandling = NullValueHandling.Ignore;
            rb.Text = JsonConvert.SerializeObject(env, settings);
            requestBodies.Add(rb);

            req.RequestBody = requestBodies.ToArray();
            builder.Request = req;

            ResponseInfo response = builder.MakeRESTRequest();
            this.Trace(builder, response);

            return response.StatusCode == HttpStatusCode.OK;
        }
开发者ID:kvvora,项目名称:DocuSign-.NET-Client,代码行数:56,代码来源:Envelope.cs


注:本文中的DocuSign.Integrations.Client.RequestBody类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。