examples/api-samples/public/docs/sample23.html in groupdocs-1.5.7 vs examples/api-samples/public/docs/sample23.html in groupdocs-1.5.8

- old
+ new

@@ -62,15 +62,16 @@ <p>set variables</p> </div> <div class="content"><div class='highlight'><pre> - set <span class="symbol">:client_id</span>, params[<span class="symbol">:client_id</span>] - set <span class="symbol">:private_key</span>, params[<span class="symbol">:private_key</span>] + 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">:source</span>, params[<span class="symbol">:source</span>] set <span class="symbol">:file_id</span>, params[<span class="symbol">:fileId</span>] set <span class="symbol">:url</span>, params[<span class="symbol">:url</span>] + set <span class="symbol">:base_path</span>, params[<span class="symbol">:basePath</span>] <span class="keyword">begin</span></pre></div></div> </li> @@ -83,36 +84,71 @@ </div> <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?</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? + + <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> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-5">&#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</pre></div></div> + + </li> + + + <li id="section-6"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-6">&#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> + <span class="keyword">end</span></pre></div></div> + + </li> + + + <li id="section-7"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-7">&#182;</a> + </div> <p>get document by file GUID</p> </div> <div class="content"><div class='highlight'><pre> <span class="keyword">case</span> settings.source <span class="keyword">when</span> <span class="string">'guid'</span></pre></div></div> </li> - <li id="section-6"> + <li id="section-8"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-6">&#182;</a> + <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Create instance of File</p> </div> @@ -120,127 +156,127 @@ <span class="keyword">when</span> <span class="string">'local'</span></pre></div></div> </li> - <li id="section-7"> + <li id="section-9"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-7">&#182;</a> + <a class="pilcrow" href="#section-9">&#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-8"> + <li id="section-10"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-8">&#182;</a> + <a class="pilcrow" href="#section-10">&#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-9"> + <li id="section-11"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-9">&#182;</a> + <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Make a request to API using client_id and private_key</p> </div> - <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.upload!(file_path, {}, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key}) + <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.upload!(file_path, {}) <span class="keyword">when</span> <span class="string">'url'</span></pre></div></div> </li> - <li id="section-10"> + <li id="section-12"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-10">&#182;</a> + <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Upload file from defined url</p> </div> - <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.upload_web!(settings.url, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key}) + <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.upload_web!(settings.url) <span class="keyword">else</span> raise <span class="string">'Wrong GUID source.'</span> <span class="keyword">end</span></pre></div></div> </li> - <li id="section-11"> + <li id="section-13"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-11">&#182;</a> + <a class="pilcrow" href="#section-13">&#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-12"> + <li id="section-14"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-12">&#182;</a> + <a class="pilcrow" href="#section-14">&#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-13"> + <li id="section-15"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-13">&#182;</a> + <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Create new page</p> </div> - <div class="content"><div class='highlight'><pre> page_image = document.page_images!(<span class="number">700</span>, <span class="number">700</span>, {<span class="symbol">first_page:</span> <span class="number">0</span>, <span class="symbol">page_count:</span> <span class="number">2</span>}, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key}) - pp page_image + <div class="content"><div class='highlight'><pre> page_image = document.page_images!(<span class="number">700</span>, <span class="number">700</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-14"> + <li id="section-16"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-14">&#182;</a> + <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>set variables for template</p> </div>