examples/api-samples/public/docs/sample31.html in groupdocs-1.5.8 vs examples/api-samples/public/docs/sample31.html in groupdocs-1.5.9

- old
+ new

@@ -280,11 +280,11 @@ <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-16">&#182;</a> </div> - <p>set variables</p> + <p>Set variables</p> </div> <div class="content"><div class='highlight'><pre> set <span class="symbol">:client_id</span>, params[<span class="symbol">:clientId</span>] set <span class="symbol">:private_key</span>, params[<span class="symbol">:privateKey</span>] @@ -341,27 +341,46 @@ <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-19">&#182;</a> </div> - <p>check required variables</p> + <p>Check required variables</p> </div> - <div class="content"><div class='highlight'><pre> raise <span class="string">'Please enter all required parameters'</span> <span class="keyword">if</span> settings.client_id.empty? <span class="keyword">or</span> settings.private_key.empty? - - <span class="keyword">if</span> settings.base_path.empty? <span class="keyword">then</span> settings.base_path = <span class="string">'https://api.groupdocs.com'</span> <span class="keyword">end</span></pre></div></div> + <div class="content"><div class='highlight'><pre> raise <span class="string">'Please enter all required parameters'</span> <span class="keyword">if</span> settings.client_id.empty? <span class="keyword">or</span> settings.private_key.empty?</pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-20">&#182;</a> </div> + <p>Prepare base path</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.base_path.empty? + base_path = <span class="string">'https://api.groupdocs.com'</span> + <span class="keyword">elsif</span> settings.base_path.match(<span class="string">'/v2.0'</span>) + base_path = settings.base_path.split(<span class="string">'/v2.0'</span>)[<span class="number">0</span>] + <span class="keyword">else</span> + base_path = settings.base_path + <span class="keyword">end</span></pre></div></div> + + </li> + + + <li id="section-21"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-21">&#182;</a> + </div> <p>Configure your access to API server</p> </div> <div class="content"><div class='highlight'><pre> <span class="constant">GroupDocs</span>.configure <span class="keyword">do</span> |groupdocs| @@ -369,31 +388,31 @@ groupdocs.private_key = settings.private_key</pre></div></div> </li> - <li id="section-21"> + <li id="section-22"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-21">&#182;</a> + <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Optionally specify API server and version</p> </div> - <div class="content"><div class='highlight'><pre> groupdocs.api_server = settings.base_path <span class="comment"># default is 'https://api.groupdocs.com'</span> + <div class="content"><div class='highlight'><pre> groupdocs.api_server = base_path <span class="comment"># default is 'https://api.groupdocs.com'</span> <span class="keyword">end</span></pre></div></div> </li> - <li id="section-22"> + <li id="section-23"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-22">&#182;</a> + <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Write client and private key to the file for callback job</p> </div> @@ -401,142 +420,140 @@ out_file = <span class="constant">File</span>.new(<span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/user_info.txt"</span>, <span class="string">'w'</span>)</pre></div></div> </li> - <li id="section-23"> + <li id="section-24"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-23">&#182;</a> + <a class="pilcrow" href="#section-24">&#182;</a> </div> - <p>white space is required</p> + <p>White space is required</p> </div> <div class="content"><div class='highlight'><pre> out_file.write(<span class="string">"<span class="subst">#{settings.client_id}</span> "</span>) out_file.write(<span class="string">"<span class="subst">#{settings.private_key}</span>"</span>) out_file.close <span class="keyword">end</span> - <span class="keyword">if</span> settings.last_name.empty? - settings.last_name = <span class="string">'test'</span> - <span class="keyword">end</span> + file = <span class="keyword">nil</span></pre></div></div> </li> - <li id="section-24"> + <li id="section-25"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-24">&#182;</a> + <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Create instance of File</p> </div> <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.new({<span class="symbol">:guid</span> =&gt; settings.template_guid})</pre></div></div> </li> - <li id="section-25"> + <li id="section-26"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-25">&#182;</a> + <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Raise exception if something went wrong</p> </div> <div class="content"><div class='highlight'><pre> raise <span class="string">'No such file'</span> <span class="keyword">unless</span> file.is_a?(<span class="constant">GroupDocs::Storage::File</span>)</pre></div></div> </li> - <li id="section-26"> + <li id="section-27"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-26">&#182;</a> + <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Make GroupDocs::Storage::Document instance</p> </div> <div class="content"><div class='highlight'><pre> document = file.to_document</pre></div></div> </li> - <li id="section-27"> + <li id="section-28"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-27">&#182;</a> + <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Create datasource with fields</p> </div> <div class="content"><div class='highlight'><pre> datasource = <span class="constant">GroupDocs::DataSource</span>.new</pre></div></div> </li> - <li id="section-28"> + <li id="section-29"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-28">&#182;</a> + <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Get arry of document&#39;s fields</p> </div> - <div class="content"><div class='highlight'><pre> enteredData = {<span class="string">"email"</span> =&gt; settings.email, <span class="string">"name"</span> =&gt; settings.name, <span class="string">"last_name"</span> =&gt; settings.last_name, <span class="string">"country"</span>=&gt; settings.country, <span class="string">"city"</span> =&gt; settings.city, <span class="string">"street"</span> =&gt; settings.street}</pre></div></div> + <div class="content"><div class='highlight'><pre> enteredData = {<span class="string">"email"</span> =&gt; settings.email, <span class="string">"name"</span> =&gt; settings.name, <span class="string">"country"</span>=&gt; settings.country, <span class="string">"city"</span> =&gt; settings.city, <span class="string">"street"</span> =&gt; settings.street}</pre></div></div> </li> - <li id="section-29"> + <li id="section-30"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-29">&#182;</a> + <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Create Field instance and fill the fields</p> </div> <div class="content"><div class='highlight'><pre> datasource.fields = enteredData.map { |key, value| <span class="constant">GroupDocs::DataSource::Field</span>.new(<span class="symbol">name:</span> key, <span class="symbol">type:</span> <span class="symbol">:text</span>, <span class="symbol">values:</span> <span class="constant">Array</span>.new() &lt;&lt; value) }</pre></div></div> </li> - <li id="section-30"> + <li id="section-31"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-30">&#182;</a> + <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Adds datasource.</p> </div> <div class="content"><div class='highlight'><pre> datasource.add!()</pre></div></div> </li> - <li id="section-31"> + <li id="section-32"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-31">&#182;</a> + <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Creates new job to merge datasource into document.</p> </div> @@ -544,45 +561,45 @@ sleep <span class="number">10</span> <span class="comment"># wait for merge and convert</span></pre></div></div> </li> - <li id="section-32"> + <li id="section-33"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-32">&#182;</a> + <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Returns an hash of input and output documents associated to job.</p> </div> <div class="content"><div class='highlight'><pre> jobInfo = job.documents!()</pre></div></div> </li> - <li id="section-33"> + <li id="section-34"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-33">&#182;</a> + <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>Creates new document to envelope</p> </div> <div class="content"><div class='highlight'><pre> document = jobInfo[<span class="symbol">:inputs</span>][<span class="number">0</span>].outputs[<span class="number">0</span>].to_document</pre></div></div> </li> - <li id="section-34"> + <li id="section-35"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-34">&#182;</a> + <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Creates envelope using user id and entered by user name</p> </div> @@ -591,169 +608,182 @@ envelope.create!({})</pre></div></div> </li> - <li id="section-35"> + <li id="section-36"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-35">&#182;</a> + <a class="pilcrow" href="#section-36">&#182;</a> </div> <p>Adds uploaded document to envelope</p> </div> - <div class="content"><div class='highlight'><pre> envelope.add_document!(document, {})</pre></div></div> + <div class="content"><div class='highlight'><pre> envelope.add_document!(document, {<span class="symbol">parseFields:</span> <span class="keyword">true</span>})</pre></div></div> </li> - <li id="section-36"> + <li id="section-37"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-36">&#182;</a> + <a class="pilcrow" href="#section-37">&#182;</a> </div> <p>Get role list for current user</p> </div> <div class="content"><div class='highlight'><pre> roles = <span class="constant">GroupDocs::Signature::Role</span>.get!({})</pre></div></div> </li> - <li id="section-37"> + <li id="section-38"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-37">&#182;</a> + <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>Creates new recipient</p> </div> <div class="content"><div class='highlight'><pre> recipient = <span class="constant">GroupDocs::Signature::Recipient</span>.new recipient.email = settings.email recipient.first_name = settings.name - recipient.last_name = settings.last_name + recipient.last_name = <span class="string">"lastName"</span> recipient.role_id = roles.detect { |role| role.name == <span class="string">'Signer'</span> }.id</pre></div></div> </li> - <li id="section-38"> + <li id="section-39"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-38">&#182;</a> + <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>Adds recipient to envelope</p> </div> <div class="content"><div class='highlight'><pre> envelope.add_recipient!(recipient)</pre></div></div> </li> - <li id="section-39"> + <li id="section-40"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-39">&#182;</a> + <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Get recipients</p> </div> <div class="content"><div class='highlight'><pre> recipientGet = envelope.recipients!({}).first</pre></div></div> </li> - <li id="section-40"> + <li id="section-41"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-40">&#182;</a> + <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Send envelope</p> </div> <div class="content"><div class='highlight'><pre> envelope.send!({<span class="symbol">:callbackUrl</span> =&gt; settings.callback})</pre></div></div> </li> - <li id="section-41"> + <li id="section-42"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-41">&#182;</a> + <a class="pilcrow" href="#section-42">&#182;</a> </div> - <p>Get url from request</p> + <p>Prepare to sign url</p> </div> - <div class="content"><div class='highlight'><pre> <span class="keyword">case</span> settings.base_path - - <span class="keyword">when</span> <span class="string">'https://stage-api-groupdocs.dynabic.com'</span> - url = <span class="string">"http://stage-apps-groupdocs.dynabic.com/signature2/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipientGet.id}</span>"</span> - <span class="keyword">when</span> <span class="string">'https://dev-api-groupdocs.dynabic.com'</span> - url = <span class="string">"http://dev-apps-groupdocs.dynabic.com/signature2/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipientGet.id}</span>"</span> - <span class="keyword">else</span> - url = <span class="string">"https://apps.groupdocs.com/signature2/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipientGet.id}</span>"</span> - <span class="keyword">end</span></pre></div></div> + <div class="content"><div class='highlight'><pre> iframe = <span class="string">"/signature2/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipientGet.id}</span>"</span></pre></div></div> </li> - <li id="section-42"> + <li id="section-43"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-42">&#182;</a> + <a class="pilcrow" href="#section-43">&#182;</a> </div> - <p>Add the signature in url</p> + <p>Construct result string</p> </div> - <div class="content"><div class='highlight'><pre> iframe = <span class="constant">GroupDocs::Api::Request</span>.new(<span class="symbol">:path</span> =&gt; url).prepare_and_sign_url</pre></div></div> + <div class="content"><div class='highlight'><pre> url = <span class="constant">GroupDocs::Api::Request</span>.new(<span class="symbol">:path</span> =&gt; iframe).prepare_and_sign_url</pre></div></div> </li> - <li id="section-43"> + <li id="section-44"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-43">&#182;</a> + <a class="pilcrow" href="#section-44">&#182;</a> </div> + <p>Generate iframe URL</p> + + </div> + + <div class="content"><div class='highlight'><pre> <span class="keyword">case</span> base_path + <span class="keyword">when</span> <span class="string">'https://stage-api-groupdocs.dynabic.com'</span> + iframe = <span class="string">"https://stage-api-groupdocs.dynabic.com<span class="subst">#{url}</span>"</span> + <span class="keyword">when</span> <span class="string">'https://dev-api-groupdocs.dynabic.com'</span> + iframe = <span class="string">"https://dev-apps.groupdocs.com<span class="subst">#{url}</span>"</span> + <span class="keyword">else</span> + iframe = <span class="string">"https://apps.groupdocs.com<span class="subst">#{url}</span>"</span> + <span class="keyword">end</span></pre></div></div> + + </li> + + + <li id="section-45"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-45">&#182;</a> + </div> <p>Make iframe</p> </div> - <div class="content"><div class='highlight'><pre> iframe = <span class="string">"&lt;iframe src='<span class="subst">#{iframe}</span>' frameborder='0' width='720' height='600'&gt;&lt;/iframe&gt;"</span> + <div class="content"><div class='highlight'><pre> iframe = <span class="string">"&lt;iframe id='downloadframe' src='<span class="subst">#{iframe}</span>' width='800' height='1000'&gt;&lt;/iframe&gt;"</span> - <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e err = e.message <span class="keyword">end</span></pre></div></div> </li> - <li id="section-44"> + <li id="section-46"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-44">&#182;</a> + <a class="pilcrow" href="#section-46">&#182;</a> </div> - <p>set variables for template</p> + <p>Set variables for template</p> </div> <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample31</span>, <span class="symbol">:locals</span> =&gt; {<span class="symbol">:userId</span> =&gt; settings.client_id, <span class="symbol">:privateKey</span> =&gt; settings.private_key, @@ -762,9 +792,10 @@ <span class="symbol">:name</span> =&gt; settings.name, <span class="symbol">:country</span> =&gt; settings.country, <span class="symbol">:city</span> =&gt; settings.city, <span class="symbol">:street</span> =&gt; settings.street, <span class="symbol">:iframe</span> =&gt; iframe, + <span class="symbol">:templateGuid</span> =&gt; settings.template_guid, <span class="symbol">:err</span> =&gt; err} <span class="keyword">end</span></pre></div></div> </li>