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

- old
+ new

@@ -83,23 +83,42 @@ </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? <span class="keyword">or</span> settings.file_id.empty? <span class="keyword">or</span> settings.annotation_type.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? <span class="keyword">or</span> settings.file_id.empty? <span class="keyword">or</span> settings.annotation_type.empty?</pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-5">&#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-6"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-6">&#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| @@ -107,36 +126,36 @@ groupdocs.private_key = settings.private_key</pre></div></div> </li> - <li id="section-6"> + <li id="section-7"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-6">&#182;</a> + <a class="pilcrow" href="#section-7">&#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> <span class="keyword">if</span> settings.annotation_id != <span class="string">''</span> file = <span class="constant">GroupDocs::Storage::File</span>.new({<span class="symbol">:guid</span> =&gt; settings.file_id}).to_document annotation = file.annotations!()</pre></div></div> </li> - <li id="section-7"> + <li id="section-8"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-7">&#182;</a> + <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Remove annotation from document</p> </div> @@ -145,273 +164,299 @@ <span class="keyword">else</span></pre></div></div> </li> - <li id="section-8"> + <li id="section-9"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-8">&#182;</a> + <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Annotation types</p> </div> - <div class="content"><div class='highlight'><pre> types = {<span class="symbol">:text</span> =&gt; <span class="string">"0"</span>, <span class="symbol">:area</span> =&gt; <span class="string">"1"</span>, <span class="symbol">:point</span> =&gt; <span class="string">"2"</span>}</pre></div></div> + <div class="content"><div class='highlight'><pre> types = {<span class="symbol">:text</span> =&gt; <span class="string">"0"</span>, <span class="symbol">:area</span> =&gt; <span class="string">"1"</span>, <span class="symbol">:point</span> =&gt; <span class="string">"2"</span>}</pre></div></div> </li> - <li id="section-9"> + <li id="section-10"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-9">&#182;</a> + <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Required parameters</p> </div> - <div class="content"><div class='highlight'><pre> all_params = all_params = [<span class="string">'annotation_type'</span>, <span class="string">'box_x'</span>, <span class="string">'box_y'</span>, <span class="string">'text'</span>]</pre></div></div> + <div class="content"><div class='highlight'><pre> all_params = all_params = [<span class="string">'annotationType'</span>, <span class="string">'boxX'</span>, <span class="string">'boxY'</span>, <span class="string">'text'</span>]</pre></div></div> </li> - <li id="section-10"> + <li id="section-11"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-10">&#182;</a> + <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Added required parameters depends on annotation type [&#39;text&#39; or &#39;area&#39;]</p> </div> - <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.annotation_type == <span class="string">'text'</span> - all_params = all_params | [<span class="string">'box_width'</span>, <span class="string">'box_height'</span>, <span class="string">'annotationPosition_x'</span>, <span class="string">'annotationPosition_y'</span>, <span class="string">'range-position'</span>, <span class="string">'range-length'</span>] - <span class="keyword">elsif</span> settings.annotation_type == <span class="string">'area'</span> - all_params = all_params | [<span class="string">'box_width'</span>, <span class="string">'box_height'</span>] - <span class="keyword">end</span></pre></div></div> + <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.annotation_type == <span class="string">'text'</span> + all_params = all_params | [<span class="string">'boxWidth'</span>, <span class="string">'boxHeight'</span>, <span class="string">'annotationPositionX'</span>, <span class="string">'annotationPositionY'</span>, <span class="string">'rangePosition'</span>, <span class="string">'rangeLength'</span>] + <span class="keyword">elsif</span> settings.annotation_type == <span class="string">'area'</span> + all_params = all_params | [<span class="string">'boxWidth'</span>, <span class="string">'boxHeight'</span>] + <span class="keyword">end</span></pre></div></div> </li> - <li id="section-11"> + <li id="section-12"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-11">&#182;</a> + <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Checking required parameters</p> </div> - <div class="content"><div class='highlight'><pre> all_params.each <span class="keyword">do</span> |param| - raise <span class="string">'Please enter all required parameters'</span> <span class="keyword">if</span> params[param].empty? - <span class="keyword">end</span></pre></div></div> + <div class="content"><div class='highlight'><pre> all_params.each <span class="keyword">do</span> |param| + raise <span class="string">'Please enter all required parameters'</span> <span class="keyword">if</span> params[param].empty? + <span class="keyword">end</span></pre></div></div> </li> - <li id="section-12"> + <li id="section-13"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-12">&#182;</a> + <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Make a request to API using client_id and private_key</p> </div> - <div class="content"><div class='highlight'><pre> files_list = <span class="constant">GroupDocs::Storage::Folder</span>.list!(<span class="string">'/'</span>, {}) + <div class="content"><div class='highlight'><pre> files_list = <span class="constant">GroupDocs::Storage::Folder</span>.list!(<span class="string">'/'</span>, {}) - document = <span class="string">''</span></pre></div></div> + document = <span class="string">''</span></pre></div></div> </li> - <li id="section-13"> + <li id="section-14"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-13">&#182;</a> + <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Get document by file ID</p> </div> - <div class="content"><div class='highlight'><pre> files_list.each <span class="keyword">do</span> |element| - <span class="keyword">if</span> element.respond_to?(<span class="string">'guid'</span>) == <span class="keyword">true</span> <span class="keyword">and</span> element.guid == settings.file_id - document = element + <div class="content"><div class='highlight'><pre> files_list.each <span class="keyword">do</span> |element| + <span class="keyword">if</span> element.respond_to?(<span class="string">'guid'</span>) == <span class="keyword">true</span> <span class="keyword">and</span> element.guid == settings.file_id + document = element + <span class="keyword">end</span> <span class="keyword">end</span> - <span class="keyword">end</span> - <span class="keyword">unless</span> document.instance_of? <span class="constant">String</span></pre></div></div> + <span class="keyword">unless</span> document.instance_of? <span class="constant">String</span></pre></div></div> </li> - <li id="section-14"> + <li id="section-15"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-14">&#182;</a> + <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Start create new annotation</p> </div> - <div class="content"><div class='highlight'><pre> annotation = <span class="constant">GroupDocs::Document::Annotation</span>.new(<span class="symbol">document:</span> document.to_document) + <div class="content"><div class='highlight'><pre> annotation = <span class="constant">GroupDocs::Document::Annotation</span>.new(<span class="symbol">document:</span> document.to_document) - info = <span class="keyword">nil</span></pre></div></div> + info = <span class="keyword">nil</span></pre></div></div> </li> - <li id="section-15"> + <li id="section-16"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-15">&#182;</a> + <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Construct requestBody depends on annotation type Text annotation</p> </div> - <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.annotation_type == <span class="string">'text'</span> - annotation.box = <span class="constant">GroupDocs::Document::Rectangle</span>.new ({<span class="symbol">x:</span> params[<span class="string">'box_x'</span>], <span class="symbol">y:</span> params[<span class="string">'box_y'</span>], <span class="symbol">width:</span> params[<span class="string">'box_width'</span>], <span class="symbol">height:</span> params[<span class="string">'box_height'</span>]}) - annotation.annotationPosition = {<span class="symbol">x:</span> params[<span class="string">'annotationPosition_x'</span>], <span class="symbol">y:</span> params[<span class="string">'annotationPosition_y'</span>]} - range = {<span class="symbol">position:</span> params[<span class="string">'range-position'</span>], <span class="symbol">length:</span> params[<span class="string">'range-length'</span>]} - info = {<span class="symbol">:box</span> =&gt; annotation_box, <span class="symbol">:annotationPosition</span> =&gt; annotation_annotationPosition, <span class="symbol">:range</span> =&gt; range, <span class="symbol">:type</span> =&gt; types[settings.annotation_type.to_sym], <span class="symbol">:replies</span> =&gt; [{<span class="symbol">:text</span> =&gt; params[<span class="string">'text'</span>]}]}</pre></div></div> + <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.annotation_type == <span class="string">'text'</span> + annotation.box = <span class="constant">GroupDocs::Document::Rectangle</span>.new ({<span class="symbol">x:</span> params[<span class="string">'boxX'</span>], <span class="symbol">y:</span> params[<span class="string">'boxY'</span>], <span class="symbol">width:</span> params[<span class="string">'boxWidth'</span>], <span class="symbol">height:</span> params[<span class="string">'boxHeight'</span>]}) + annotation.annotationPosition = {<span class="symbol">x:</span> params[<span class="string">'annotationPositionX'</span>], <span class="symbol">y:</span> params[<span class="string">'annotationPositionY'</span>]} + range = {<span class="symbol">position:</span> params[<span class="string">'rangePosition'</span>], <span class="symbol">length:</span> params[<span class="string">'rangeLength'</span>]} + info = {<span class="symbol">:box</span> =&gt; annotation_box, <span class="symbol">:annotationPosition</span> =&gt; annotation_annotationPosition, <span class="symbol">:range</span> =&gt; range, <span class="symbol">:type</span> =&gt; types[settings.annotation_type.to_sym], <span class="symbol">:replies</span> =&gt; [{<span class="symbol">:text</span> =&gt; params[<span class="string">'text'</span>]}]}</pre></div></div> </li> - <li id="section-16"> + <li id="section-17"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-16">&#182;</a> + <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Area annotation</p> </div> - <div class="content"><div class='highlight'><pre> <span class="keyword">elsif</span> settings.annotation_type == <span class="string">'area'</span> - annotation_box = {<span class="symbol">x:</span> params[<span class="string">'box_x'</span>], <span class="symbol">y:</span> params[<span class="string">'box_y'</span>], <span class="symbol">width:</span> params[<span class="string">'box_width'</span>], <span class="symbol">height:</span> params[<span class="string">'box_height'</span>]} - annotation_annotationPosition = {<span class="symbol">x:</span> <span class="number">0</span>, <span class="symbol">y:</span> <span class="number">0</span>} - info = {<span class="symbol">:box</span> =&gt; annotation_box, <span class="symbol">:annotationPosition</span> =&gt; annotation_annotationPosition, <span class="symbol">:type</span> =&gt; types[settings.annotation_type.to_sym], <span class="symbol">:replies</span> =&gt; [{<span class="symbol">:text</span> =&gt; params[<span class="string">'text'</span>]}]}</pre></div></div> + <div class="content"><div class='highlight'><pre> <span class="keyword">elsif</span> settings.annotation_type == <span class="string">'area'</span> + annotation_box = {<span class="symbol">x:</span> params[<span class="string">'boxX'</span>], <span class="symbol">y:</span> params[<span class="string">'boxY'</span>], <span class="symbol">width:</span> params[<span class="string">'boxWidth'</span>], <span class="symbol">height:</span> params[<span class="string">'boxHeight'</span>]} + annotation_annotationPosition = {<span class="symbol">x:</span> <span class="number">0</span>, <span class="symbol">y:</span> <span class="number">0</span>} + info = {<span class="symbol">:box</span> =&gt; annotation_box, <span class="symbol">:annotationPosition</span> =&gt; annotation_annotationPosition, <span class="symbol">:type</span> =&gt; types[settings.annotation_type.to_sym], <span class="symbol">:replies</span> =&gt; [{<span class="symbol">:text</span> =&gt; params[<span class="string">'text'</span>]}]}</pre></div></div> </li> - <li id="section-17"> + <li id="section-18"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-17">&#182;</a> + <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Point annotation</p> </div> - <div class="content"><div class='highlight'><pre> <span class="keyword">elsif</span> settings.annotation_type == <span class="string">'point'</span> - annotation_box = {<span class="symbol">x:</span> params[<span class="string">'box_x'</span>], <span class="symbol">y:</span> params[<span class="string">'box_y'</span>], <span class="symbol">width:</span> <span class="number">0</span>, <span class="symbol">height:</span> <span class="number">0</span>} - annotation_annotationPosition = {<span class="symbol">x:</span> <span class="number">0</span>, <span class="symbol">y:</span> <span class="number">0</span>} + <div class="content"><div class='highlight'><pre> <span class="keyword">elsif</span> settings.annotation_type == <span class="string">'point'</span> + annotation_box = {<span class="symbol">x:</span> params[<span class="string">'boxX'</span>], <span class="symbol">y:</span> params[<span class="string">'boxY'</span>], <span class="symbol">width:</span> <span class="number">0</span>, <span class="symbol">height:</span> <span class="number">0</span>} + annotation_annotationPosition = {<span class="symbol">x:</span> <span class="number">0</span>, <span class="symbol">y:</span> <span class="number">0</span>} - info = {<span class="symbol">:box</span> =&gt; annotation_box, <span class="symbol">:annotationPosition</span> =&gt; annotation_annotationPosition, <span class="symbol">:type</span> =&gt; types[settings.annotation_type.to_sym], <span class="symbol">:replies</span> =&gt; [{<span class="symbol">:text</span> =&gt; params[<span class="string">'text'</span>]}] } - <span class="keyword">end</span></pre></div></div> + info = {<span class="symbol">:box</span> =&gt; annotation_box, <span class="symbol">:annotationPosition</span> =&gt; annotation_annotationPosition, <span class="symbol">:type</span> =&gt; types[settings.annotation_type.to_sym], <span class="symbol">:replies</span> =&gt; [{<span class="symbol">:text</span> =&gt; params[<span class="string">'text'</span>]}] } + <span class="keyword">end</span></pre></div></div> </li> - <li id="section-18"> + <li id="section-19"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-18">&#182;</a> + <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Call create method</p> </div> - <div class="content"><div class='highlight'><pre> annotation.create!(info) - id = annotation.document.file.id</pre></div></div> + <div class="content"><div class='highlight'><pre> annotation.create!(info) + id = annotation.document.file.id</pre></div></div> </li> - <li id="section-19"> + <li id="section-20"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-19">&#182;</a> + <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Get document guid</p> </div> - <div class="content"><div class='highlight'><pre> guid = annotation.document.file.guid + <div class="content"><div class='highlight'><pre> guid = annotation.document.file.guid</pre></div></div> + + </li> + + + <li id="section-21"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-21">&#182;</a> + </div> + <p>Prepare to sign url</p> - <span class="keyword">case</span> settings.base_path + </div> + + <div class="content"><div class='highlight'><pre> iframe = <span class="string">"/document-annotation2/embed/<span class="subst">#{guid}</span>"</span></pre></div></div> + + </li> + + + <li id="section-22"> + <div class="annotation"> + + <div class="pilwrap "> + <a class="pilcrow" href="#section-22">&#182;</a> + </div> + <p>Construct result string</p> - <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/document-annotation2/embed/<span class="subst">#{guid}</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/document-annotation2/embed/<span class="subst">#{guid}</span>"</span> - <span class="keyword">else</span> - url = <span class="string">"http://apps.groupdocs.com/document-annotation2/embed/<span class="subst">#{guid}</span>"</span> - <span class="keyword">end</span></pre></div></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-20"> + <li id="section-23"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-20">&#182;</a> + <a class="pilcrow" href="#section-23">&#182;</a> </div> - <p>Add the signature in url</p> + <p>Generate iframe URL</p> </div> - <div class="content"><div class='highlight'><pre> url = <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> <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-21"> + <li id="section-24"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-21">&#182;</a> + <a class="pilcrow" href="#section-24">&#182;</a> </div> - <p>Set iframe with document GUID</p> + <p>Make iframe</p> </div> - <div class="content"><div class='highlight'><pre> iframe = <span class="string">"&lt;iframe src='<span class="subst">#{url}</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">end</span> <span class="keyword">end</span> - <span class="keyword">end</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-22"> + <li id="section-25"> <div class="annotation"> <div class="pilwrap "> - <a class="pilcrow" href="#section-22">&#182;</a> + <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>set variables for template</p> </div>