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">¶</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">¶</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">¶</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">¶</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">¶</a>
+ <a class="pilcrow" href="#section-22">¶</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">¶</a>
+ <a class="pilcrow" href="#section-23">¶</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">¶</a>
+ <a class="pilcrow" href="#section-24">¶</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">¶</a>
+ <a class="pilcrow" href="#section-25">¶</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> => 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">¶</a>
+ <a class="pilcrow" href="#section-26">¶</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">¶</a>
+ <a class="pilcrow" href="#section-27">¶</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">¶</a>
+ <a class="pilcrow" href="#section-28">¶</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">¶</a>
+ <a class="pilcrow" href="#section-29">¶</a>
</div>
<p>Get arry of document's fields</p>
</div>
- <div class="content"><div class='highlight'><pre> enteredData = {<span class="string">"email"</span> => settings.email, <span class="string">"name"</span> => settings.name, <span class="string">"last_name"</span> => settings.last_name, <span class="string">"country"</span>=> settings.country, <span class="string">"city"</span> => settings.city, <span class="string">"street"</span> => settings.street}</pre></div></div>
+ <div class="content"><div class='highlight'><pre> enteredData = {<span class="string">"email"</span> => settings.email, <span class="string">"name"</span> => settings.name, <span class="string">"country"</span>=> settings.country, <span class="string">"city"</span> => settings.city, <span class="string">"street"</span> => 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">¶</a>
+ <a class="pilcrow" href="#section-30">¶</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() << 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">¶</a>
+ <a class="pilcrow" href="#section-31">¶</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">¶</a>
+ <a class="pilcrow" href="#section-32">¶</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">¶</a>
+ <a class="pilcrow" href="#section-33">¶</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">¶</a>
+ <a class="pilcrow" href="#section-34">¶</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">¶</a>
+ <a class="pilcrow" href="#section-35">¶</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">¶</a>
+ <a class="pilcrow" href="#section-36">¶</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">¶</a>
+ <a class="pilcrow" href="#section-37">¶</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">¶</a>
+ <a class="pilcrow" href="#section-38">¶</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">¶</a>
+ <a class="pilcrow" href="#section-39">¶</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">¶</a>
+ <a class="pilcrow" href="#section-40">¶</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">¶</a>
+ <a class="pilcrow" href="#section-41">¶</a>
</div>
<p>Send envelope</p>
</div>
<div class="content"><div class='highlight'><pre> envelope.send!({<span class="symbol">:callbackUrl</span> => 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">¶</a>
+ <a class="pilcrow" href="#section-42">¶</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">¶</a>
+ <a class="pilcrow" href="#section-43">¶</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> => 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> => 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">¶</a>
+ <a class="pilcrow" href="#section-44">¶</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">¶</a>
+ </div>
<p>Make iframe</p>
</div>
- <div class="content"><div class='highlight'><pre> iframe = <span class="string">"<iframe src='<span class="subst">#{iframe}</span>' frameborder='0' width='720' height='600'></iframe>"</span>
+ <div class="content"><div class='highlight'><pre> iframe = <span class="string">"<iframe id='downloadframe' src='<span class="subst">#{iframe}</span>' width='800' height='1000'></iframe>"</span>
-
<span class="keyword">rescue</span> <span class="constant">Exception</span> => 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">¶</a>
+ <a class="pilcrow" href="#section-46">¶</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> => {<span class="symbol">:userId</span> => settings.client_id,
<span class="symbol">:privateKey</span> => settings.private_key,
@@ -762,9 +792,10 @@
<span class="symbol">:name</span> => settings.name,
<span class="symbol">:country</span> => settings.country,
<span class="symbol">:city</span> => settings.city,
<span class="symbol">:street</span> => settings.street,
<span class="symbol">:iframe</span> => iframe,
+ <span class="symbol">:templateGuid</span> => settings.template_guid,
<span class="symbol">:err</span> => err}
<span class="keyword">end</span></pre></div></div>
</li>