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

- old
+ new

@@ -547,20 +547,21 @@ <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-32">&#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>] set <span class="symbol">:name</span>, params[<span class="symbol">:name</span>] set <span class="symbol">:email</span>, params[<span class="symbol">:email</span>] set <span class="symbol">:callback</span>, params[<span class="symbol">:callbackUrl</span>] - set <span class="symbol">:last_name</span>, params[<span class="symbol">:lastName</span>]</pre></div></div> + set <span class="symbol">:last_name</span>, params[<span class="symbol">:lastName</span>] + set <span class="symbol">:base_path</span>, params[<span class="symbol">:basePath</span>]</pre></div></div> </li> <li id="section-33"> @@ -603,11 +604,11 @@ <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-35">&#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">or</span> settings.name.empty? <span class="keyword">or</span> settings.email.empty? <span class="keyword">or</span> settings.last_name.empty?</pre></div></div> @@ -618,27 +619,64 @@ <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-36">&#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-37"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-37">&#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| groupdocs.client_id = settings.client_id - groupdocs.private_key = settings.private_key + groupdocs.private_key = settings.private_key</pre></div></div> + + </li> + + + <li id="section-38"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-38">&#182;</a> + </div> + <p>Optionally specify API server and version</p> + + </div> + + <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-37"> + <li id="section-39"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-37">&#182;</a> + <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>Write client and private key to the file for callback job</p> </div> @@ -646,17 +684,17 @@ 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-38"> + <li id="section-40"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-38">&#182;</a> + <a class="pilcrow" href="#section-40">&#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>) @@ -664,45 +702,45 @@ <span class="keyword">end</span></pre></div></div> </li> - <li id="section-39"> + <li id="section-41"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-39">&#182;</a> + <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Construct path</p> </div> <div class="content"><div class='highlight'><pre> file_path = <span class="string">"<span class="subst">#{<span class="constant">Dir</span>.tmpdir}</span>/<span class="subst">#{params[<span class="symbol">:file</span>][<span class="symbol">:filename</span>]}</span>"</span></pre></div></div> </li> - <li id="section-40"> + <li id="section-42"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-40">&#182;</a> + <a class="pilcrow" href="#section-42">&#182;</a> </div> <p>Open file</p> </div> <div class="content"><div class='highlight'><pre> <span class="constant">File</span>.open(file_path, <span class="string">'wb'</span>) { |f| f.write(params[<span class="symbol">:file</span>][<span class="symbol">:tempfile</span>].read) }</pre></div></div> </li> - <li id="section-41"> + <li id="section-43"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-41">&#182;</a> + <a class="pilcrow" href="#section-43">&#182;</a> </div> <p>Make a request to API using client_id and private_key</p> </div> @@ -710,17 +748,17 @@ document = file.to_document</pre></div></div> </li> - <li id="section-42"> + <li id="section-44"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-42">&#182;</a> + <a class="pilcrow" href="#section-44">&#182;</a> </div> - <p>create envelope using user id and entered by user name</p> + <p>Create envelope using user id and entered by user name</p> </div> <div class="content"><div class='highlight'><pre> envelope = <span class="constant">GroupDocs::Signature::Envelope</span>.new envelope.name = file.name @@ -728,45 +766,45 @@ envelope.create!</pre></div></div> </li> - <li id="section-43"> + <li id="section-45"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-43">&#182;</a> + <a class="pilcrow" href="#section-45">&#182;</a> </div> <p>Add uploaded document to envelope</p> </div> <div class="content"><div class='highlight'><pre> envelope.add_document!(document)</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>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-45"> + <li id="section-47"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-45">&#182;</a> + <a class="pilcrow" href="#section-47">&#182;</a> </div> <p>Create new recipient</p> </div> @@ -777,45 +815,45 @@ recipient.role_id = roles.detect { |role| role.name == <span class="string">'Signer'</span> }.id</pre></div></div> </li> - <li id="section-46"> + <li id="section-48"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-46">&#182;</a> + <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>Add recipient to envelope</p> </div> <div class="content"><div class='highlight'><pre> recipient = envelope.add_recipient!(recipient)</pre></div></div> </li> - <li id="section-47"> + <li id="section-49"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-47">&#182;</a> + <a class="pilcrow" href="#section-49">&#182;</a> </div> <p>Get document id</p> </div> <div class="content"><div class='highlight'><pre> document = envelope.documents!()</pre></div></div> </li> - <li id="section-48"> + <li id="section-50"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-48">&#182;</a> + <a class="pilcrow" href="#section-50">&#182;</a> </div> <p>Get field and add the location to field</p> </div> @@ -824,63 +862,98 @@ field.name = <span class="string">'EMPLOYEE SIGNATURE'</span></pre></div></div> </li> - <li id="section-49"> + <li id="section-51"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-49">&#182;</a> + <a class="pilcrow" href="#section-51">&#182;</a> </div> <p>Add field to envelope</p> </div> <div class="content"><div class='highlight'><pre> envelope.add_field!(field, document[<span class="number">0</span>], recipient, {})</pre></div></div> </li> - <li id="section-50"> + <li id="section-52"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-50">&#182;</a> + <a class="pilcrow" href="#section-52">&#182;</a> </div> <p>Send envelop</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-51"> + <li id="section-53"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-51">&#182;</a> + <a class="pilcrow" href="#section-53">&#182;</a> </div> - <p>Get url from request</p> + <p>Prepare to sign url</p> </div> - <div class="content"><div class='highlight'><pre> url = <span class="string">"https://apps.groupdocs.com/signature/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipient.id}</span>"</span> - - 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> iframe = <span class="string">"/signature2/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipient.id}</span>"</span></pre></div></div> </li> - <li id="section-52"> + <li id="section-54"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-52">&#182;</a> + <a class="pilcrow" href="#section-54">&#182;</a> </div> + <p>Construct result string</p> + + </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-55"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-55">&#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-56"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-56">&#182;</a> + </div> <p>Make iframe</p> </div> <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> @@ -891,16 +964,16 @@ <span class="keyword">end</span></pre></div></div> </li> - <li id="section-53"> + <li id="section-57"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-53">&#182;</a> + <a class="pilcrow" href="#section-57">&#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">:sample39</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,