groupdocs 1.5.3 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +2 -0
  3. data/examples/api-samples/public/docs/annotation-sample.html +167 -57
  4. data/examples/api-samples/public/docs/docco.css +459 -151
  5. data/examples/api-samples/public/docs/envelope-sample.html +373 -131
  6. data/examples/api-samples/public/docs/sample1.html +126 -26
  7. data/examples/api-samples/public/docs/sample10.html +213 -50
  8. data/examples/api-samples/public/docs/sample11.html +319 -87
  9. data/examples/api-samples/public/docs/sample12.html +165 -40
  10. data/examples/api-samples/public/docs/sample13.html +166 -41
  11. data/examples/api-samples/public/docs/sample14.html +142 -30
  12. data/examples/api-samples/public/docs/sample15.html +127 -27
  13. data/examples/api-samples/public/docs/sample16.html +125 -25
  14. data/examples/api-samples/public/docs/sample17.html +188 -37
  15. data/examples/api-samples/public/docs/sample18.html +614 -157
  16. data/examples/api-samples/public/docs/sample19.html +221 -59
  17. data/examples/api-samples/public/docs/sample2.html +142 -30
  18. data/examples/api-samples/public/docs/sample20.html +176 -51
  19. data/examples/api-samples/public/docs/sample21.html +287 -66
  20. data/examples/api-samples/public/docs/sample22.html +224 -53
  21. data/examples/api-samples/public/docs/sample23.html +256 -0
  22. data/examples/api-samples/public/docs/sample24.html +143 -0
  23. data/examples/api-samples/public/docs/sample25.html +429 -0
  24. data/examples/api-samples/public/docs/sample26.html +113 -0
  25. data/examples/api-samples/public/docs/sample27.html +433 -0
  26. data/examples/api-samples/public/docs/sample28.html +185 -0
  27. data/examples/api-samples/public/docs/sample29.html +175 -0
  28. data/examples/api-samples/public/docs/sample3.html +172 -34
  29. data/examples/api-samples/public/docs/sample30.html +144 -0
  30. data/examples/api-samples/public/docs/sample31.html +734 -0
  31. data/examples/api-samples/public/docs/sample4.html +204 -52
  32. data/examples/api-samples/public/docs/sample5.html +241 -63
  33. data/examples/api-samples/public/docs/sample6.html +209 -48
  34. data/examples/api-samples/public/docs/sample7.html +155 -43
  35. data/examples/api-samples/public/docs/sample8.html +235 -62
  36. data/examples/api-samples/public/docs/sample9.html +200 -49
  37. data/examples/api-samples/public/templates/merge_field1_doc.docx +0 -0
  38. data/examples/api-samples/public/templates/merge_field2_doc.docx +0 -0
  39. data/examples/api-samples/samples/sample23.rb +54 -0
  40. data/examples/api-samples/samples/sample24.rb +30 -0
  41. data/examples/api-samples/samples/sample25.rb +4 -4
  42. data/examples/api-samples/samples/sample26.rb +25 -0
  43. data/examples/api-samples/samples/sample27.rb +100 -0
  44. data/examples/api-samples/samples/sample28.rb +47 -0
  45. data/examples/api-samples/samples/sample29.rb +52 -0
  46. data/examples/api-samples/samples/sample30.rb +39 -0
  47. data/examples/api-samples/samples/sample31.rb +204 -0
  48. data/examples/api-samples/samples/sample5.rb +5 -3
  49. data/examples/api-samples/samples/sample6.rb +2 -0
  50. data/examples/api-samples/views/_others_samples.haml +12 -0
  51. data/examples/api-samples/views/index.haml +12 -0
  52. data/examples/api-samples/views/layout.haml +1 -0
  53. data/examples/api-samples/views/sample1.haml +3 -2
  54. data/examples/api-samples/views/sample10.haml +3 -2
  55. data/examples/api-samples/views/sample11.haml +4 -0
  56. data/examples/api-samples/views/sample12.haml +4 -0
  57. data/examples/api-samples/views/sample13.haml +4 -0
  58. data/examples/api-samples/views/sample14.haml +4 -0
  59. data/examples/api-samples/views/sample15.haml +4 -0
  60. data/examples/api-samples/views/sample16.haml +4 -0
  61. data/examples/api-samples/views/sample17.haml +4 -0
  62. data/examples/api-samples/views/sample19.haml +4 -0
  63. data/examples/api-samples/views/sample2.haml +3 -2
  64. data/examples/api-samples/views/sample20.haml +4 -0
  65. data/examples/api-samples/views/sample21.haml +4 -0
  66. data/examples/api-samples/views/sample22.haml +4 -0
  67. data/examples/api-samples/views/sample23.haml +87 -0
  68. data/examples/api-samples/views/sample24.haml +44 -0
  69. data/examples/api-samples/views/sample26.haml +54 -0
  70. data/examples/api-samples/views/sample27.haml +122 -0
  71. data/examples/api-samples/views/sample28.haml +47 -0
  72. data/examples/api-samples/views/sample29.haml +70 -0
  73. data/examples/api-samples/views/sample3.haml +3 -2
  74. data/examples/api-samples/views/sample30.haml +46 -0
  75. data/examples/api-samples/views/sample31.haml +114 -0
  76. data/examples/api-samples/views/sample4.haml +3 -2
  77. data/examples/api-samples/views/sample5.haml +3 -2
  78. data/examples/api-samples/views/sample6.haml +3 -2
  79. data/examples/api-samples/views/sample7.haml +3 -2
  80. data/examples/api-samples/views/sample8.haml +3 -2
  81. data/examples/api-samples/views/sample9.haml +3 -2
  82. data/examples/viewer/Gemfile +1 -1
  83. data/groupdocs.gemspec +3 -3
  84. data/lib/groupdocs/datasource.rb +22 -0
  85. data/lib/groupdocs/document.rb +493 -43
  86. data/lib/groupdocs/document/annotation.rb +73 -0
  87. data/lib/groupdocs/job.rb +82 -1
  88. data/lib/groupdocs/post.rb +83 -0
  89. data/lib/groupdocs/questionnaire.rb +41 -0
  90. data/lib/groupdocs/signature.rb +342 -0
  91. data/lib/groupdocs/signature/envelope.rb +56 -0
  92. data/lib/groupdocs/signature/form.rb +47 -5
  93. data/lib/groupdocs/signature/shared/field_methods.rb +37 -0
  94. data/lib/groupdocs/storage/file.rb +83 -0
  95. data/lib/groupdocs/subscription.rb +218 -0
  96. data/lib/groupdocs/user.rb +422 -1
  97. data/lib/groupdocs/version.rb +1 -1
  98. data/spec/groupdocs/job_spec.rb +4 -5
  99. data/spec/groupdocs/user_spec.rb +157 -0
  100. data/spec/support/json/annotation_resize.json +11 -0
  101. data/spec/support/json/annotation_text_color.json +10 -0
  102. data/spec/support/json/annotation_text_info.json +11 -0
  103. data/spec/support/json/document_content_get.json +8 -0
  104. data/spec/support/json/document_edit_lock_get.json +10 -0
  105. data/spec/support/json/document_editlock_remove.json +8 -0
  106. data/spec/support/json/document_page_html_urls_get.json +14 -0
  107. data/spec/support/json/document_password_set.json +19 -0
  108. data/spec/support/json/document_representations.json +25 -0
  109. data/spec/support/json/document_shared_documents_get.json +32 -0
  110. data/spec/support/json/document_tags_get.json +9 -0
  111. data/spec/support/json/document_tags_remove.json +8 -0
  112. data/spec/support/json/document_tags_set.json +8 -0
  113. data/spec/support/json/document_user_status_set.json +12 -0
  114. data/spec/support/json/job_documents.json +103 -35
  115. data/spec/support/json/job_xml_get.json +30 -0
  116. data/spec/support/json/jobs_documents.json +40 -0
  117. data/spec/support/json/user_get_profile.json +73 -0
  118. metadata +49 -177
@@ -1,157 +1,614 @@
1
- <!DOCTYPE html> <html> <head> <title>sample18.rb</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="annotation-sample.html"> annotation-sample.rb </a> <a class="source" href="envelope-sample.html"> envelope-sample.rb </a> <a class="source" href="sample1.html"> sample1.rb </a> <a class="source" href="sample10.html"> sample10.rb </a> <a class="source" href="sample11.html"> sample11.rb </a> <a class="source" href="sample12.html"> sample12.rb </a> <a class="source" href="sample13.html"> sample13.rb </a> <a class="source" href="sample14.html"> sample14.rb </a> <a class="source" href="sample15.html"> sample15.rb </a> <a class="source" href="sample16.html"> sample16.rb </a> <a class="source" href="sample17.html"> sample17.rb </a> <a class="source" href="sample18.html"> sample18.rb </a> <a class="source" href="sample19.html"> sample19.rb </a> <a class="source" href="sample2.html"> sample2.rb </a> <a class="source" href="sample20.html"> sample20.rb </a> <a class="source" href="sample21.html"> sample21.rb </a> <a class="source" href="sample22.html"> sample22.rb </a> <a class="source" href="sample3.html"> sample3.rb </a> <a class="source" href="sample4.html"> sample4.rb </a> <a class="source" href="sample5.html"> sample5.rb </a> <a class="source" href="sample6.html"> sample6.rb </a> <a class="source" href="sample7.html"> sample7.rb </a> <a class="source" href="sample8.html"> sample8.rb </a> <a class="source" href="sample9.html"> sample9.rb </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> sample18.rb </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>GET request</p> </td> <td class="code"> <div class="highlight"><pre><span class="n">get</span> <span class="s1">&#39;/sample18&#39;</span> <span class="k">do</span>
2
- <span class="n">haml</span> <span class="ss">:sample18</span>
3
- <span class="k">end</span>
4
-
5
-
6
- <span class="n">post</span> <span class="s1">&#39;/sample18/convert_callback&#39;</span> <span class="k">do</span>
7
-
8
- <span class="n">downloads_path</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/downloads&quot;</span>
9
-
10
-
11
- <span class="n">data</span> <span class="o">=</span> <span class="no">JSON</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">read</span><span class="p">)</span>
12
- <span class="k">begin</span>
13
- <span class="k">raise</span> <span class="s1">&#39;Empty params!&#39;</span> <span class="k">if</span> <span class="n">data</span><span class="o">.</span><span class="n">empty?</span>
14
- <span class="n">source_id</span> <span class="o">=</span> <span class="kp">nil</span>
15
- <span class="n">client_key</span> <span class="o">=</span> <span class="kp">nil</span>
16
- <span class="n">private_key</span> <span class="o">=</span> <span class="kp">nil</span>
17
-
18
-
19
- <span class="n">data</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="o">|</span>
20
- <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s1">&#39;SourceId&#39;</span>
21
- <span class="n">source_id</span> <span class="o">=</span> <span class="n">value</span>
22
- <span class="k">end</span>
23
- <span class="k">end</span>
24
-
25
-
26
- <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exist?</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/user_info.txt&quot;</span><span class="p">)</span>
27
- <span class="n">contents</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/user_info.txt&quot;</span><span class="p">)</span>
28
- <span class="n">contents</span> <span class="o">=</span> <span class="n">contents</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
29
- <span class="n">client_key</span> <span class="o">=</span> <span class="n">contents</span><span class="o">.</span><span class="n">first</span>
30
- <span class="n">private_key</span> <span class="o">=</span> <span class="n">contents</span><span class="o">.</span><span class="n">last</span>
31
- <span class="k">end</span>
32
-
33
-
34
- <span class="n">job</span> <span class="o">=</span> <span class="ss">GroupDocs</span><span class="p">:</span><span class="ss">:Job</span><span class="o">.</span><span class="n">new</span><span class="p">({</span><span class="ss">:id</span> <span class="o">=&gt;</span> <span class="n">source_id</span><span class="p">})</span>
35
-
36
-
37
- <span class="n">documents</span> <span class="o">=</span> <span class="n">job</span><span class="o">.</span><span class="n">documents!</span><span class="p">({</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="n">client_key</span><span class="p">,</span> <span class="ss">:private_key</span> <span class="o">=&gt;</span> <span class="n">private_key</span><span class="p">})</span>
38
-
39
-
40
- <span class="n">documents</span><span class="o">[</span><span class="ss">:inputs</span><span class="o">].</span><span class="n">first</span><span class="o">.</span><span class="n">outputs</span><span class="o">.</span><span class="n">first</span><span class="o">.</span><span class="n">download!</span><span class="p">(</span><span class="n">downloads_path</span><span class="p">,</span> <span class="p">{</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="n">client_key</span><span class="p">,</span> <span class="ss">:private_key</span> <span class="o">=&gt;</span> <span class="n">private_key</span><span class="p">})</span>
41
-
42
- <span class="k">rescue</span> <span class="no">Exception</span> <span class="o">=&gt;</span> <span class="n">e</span>
43
- <span class="n">err</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span>
44
- <span class="k">end</span>
45
- <span class="k">end</span>
46
-
47
-
48
-
49
- <span class="n">get</span> <span class="s1">&#39;/sample18/check&#39;</span> <span class="k">do</span>
50
-
51
-
52
- <span class="k">unless</span> <span class="no">File</span><span class="o">.</span><span class="n">directory?</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/downloads&quot;</span><span class="p">)</span>
53
- <span class="k">return</span> <span class="s1">&#39;Directory was not found.&#39;</span>
54
- <span class="k">end</span>
55
-
56
-
57
- <span class="nb">name</span> <span class="o">=</span> <span class="kp">nil</span>
58
- <span class="no">Dir</span><span class="o">.</span><span class="n">entries</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/downloads&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">file</span><span class="o">|</span>
59
- <span class="nb">name</span> <span class="o">=</span> <span class="n">file</span> <span class="k">if</span> <span class="n">file</span> <span class="o">!=</span> <span class="s1">&#39;.&#39;</span> <span class="o">&amp;&amp;</span> <span class="n">file</span> <span class="o">!=</span> <span class="s1">&#39;..&#39;</span>
60
- <span class="k">end</span>
61
-
62
- <span class="nb">name</span>
63
- <span class="k">end</span>
64
-
65
-
66
- <span class="n">get</span> <span class="s1">&#39;/sample18/downloads/:filename&#39;</span> <span class="k">do</span> <span class="o">|</span><span class="n">filename</span><span class="o">|</span>
67
-
68
- <span class="n">send_file</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/downloads/</span><span class="si">#{</span><span class="n">filename</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="ss">:filename</span> <span class="o">=&gt;</span> <span class="n">filename</span><span class="p">,</span> <span class="ss">:type</span> <span class="o">=&gt;</span> <span class="s1">&#39;Application/octet-stream&#39;</span>
69
- <span class="k">end</span>
70
-
71
-
72
-
73
- <span class="n">post</span> <span class="s1">&#39;/sample18&#39;</span> <span class="k">do</span>
74
-
75
- <span class="n">set</span> <span class="ss">:client_id</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:client_id</span><span class="o">]</span>
76
- <span class="n">set</span> <span class="ss">:private_key</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:private_key</span><span class="o">]</span>
77
- <span class="n">set</span> <span class="ss">:source</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:source</span><span class="o">]</span>
78
- <span class="n">set</span> <span class="ss">:file_id</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:fileId</span><span class="o">]</span>
79
- <span class="n">set</span> <span class="ss">:url</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:url</span><span class="o">]</span>
80
- <span class="n">set</span> <span class="ss">:convert_type</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:convert_type</span><span class="o">]</span>
81
- <span class="n">set</span> <span class="ss">:callback</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:callback</span><span class="o">]</span>
82
-
83
-
84
- <span class="n">downloads_path</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/downloads&quot;</span>
85
-
86
-
87
- <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">directory?</span><span class="p">(</span><span class="n">downloads_path</span><span class="p">)</span>
88
- <span class="no">Dir</span><span class="o">.</span><span class="n">foreach</span><span class="p">(</span><span class="n">downloads_path</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="n">fn</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">downloads_path</span><span class="p">,</span> <span class="n">f</span><span class="p">);</span> <span class="no">File</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span> <span class="k">if</span> <span class="n">f</span> <span class="o">!=</span> <span class="s1">&#39;.&#39;</span> <span class="o">&amp;&amp;</span> <span class="n">f</span> <span class="o">!=</span> <span class="s1">&#39;..&#39;</span> <span class="p">}</span>
89
- <span class="k">else</span>
90
- <span class="ss">Dir</span><span class="p">:</span><span class="ss">:mkdir</span><span class="p">(</span><span class="n">downloads_path</span><span class="p">)</span>
91
- <span class="k">end</span>
92
-
93
- <span class="k">begin</span>
94
-
95
- <span class="k">raise</span> <span class="s1">&#39;Please enter all required parameters&#39;</span> <span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="o">.</span><span class="n">empty?</span> <span class="ow">or</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="o">.</span><span class="n">empty?</span>
96
-
97
-
98
- <span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">callback</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span>
99
- <span class="n">out_file</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="bp">__FILE__</span><span class="p">)</span><span class="si">}</span><span class="s2">/../public/user_info.txt&quot;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
100
- <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
101
- <span class="n">out_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
102
- <span class="n">out_file</span><span class="o">.</span><span class="n">close</span>
103
- <span class="k">end</span>
104
-
105
- <span class="n">file</span> <span class="o">=</span> <span class="kp">nil</span>
106
-
107
-
108
- <span class="k">case</span> <span class="n">settings</span><span class="o">.</span><span class="n">source</span>
109
- <span class="k">when</span> <span class="s1">&#39;guid&#39;</span>
110
-
111
- <span class="n">file</span> <span class="o">=</span> <span class="ss">GroupDocs</span><span class="p">:</span><span class="ss">:Storage</span><span class="o">::</span><span class="no">File</span><span class="o">.</span><span class="n">new</span><span class="p">({</span><span class="ss">:guid</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">file_id</span><span class="p">})</span>
112
- <span class="k">when</span> <span class="s1">&#39;local&#39;</span>
113
-
114
- <span class="n">file_path</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="no">Dir</span><span class="o">.</span><span class="n">tmpdir</span><span class="si">}</span><span class="s2">/</span><span class="si">#{</span><span class="n">params</span><span class="o">[</span><span class="ss">:file</span><span class="o">][</span><span class="ss">:filename</span><span class="o">]</span><span class="si">}</span><span class="s2">&quot;</span>
115
-
116
- <span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:file</span><span class="o">][</span><span class="ss">:tempfile</span><span class="o">].</span><span class="n">read</span><span class="p">)</span> <span class="p">}</span>
117
-
118
- <span class="n">file</span> <span class="o">=</span> <span class="ss">GroupDocs</span><span class="p">:</span><span class="ss">:Storage</span><span class="o">::</span><span class="no">File</span><span class="o">.</span><span class="n">upload!</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="p">{},</span> <span class="p">{</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="ss">:private_key</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">})</span>
119
- <span class="k">when</span> <span class="s1">&#39;url&#39;</span>
120
-
121
- <span class="n">file</span> <span class="o">=</span> <span class="ss">GroupDocs</span><span class="p">:</span><span class="ss">:Storage</span><span class="o">::</span><span class="no">File</span><span class="o">.</span><span class="n">upload_web!</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">url</span><span class="p">,</span> <span class="p">{</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="ss">:private_key</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">})</span>
122
- <span class="k">else</span>
123
- <span class="k">raise</span> <span class="s1">&#39;Wrong GUID source.&#39;</span>
124
- <span class="k">end</span>
125
-
126
-
127
- <span class="k">raise</span> <span class="s1">&#39;No such file&#39;</span> <span class="k">unless</span> <span class="n">file</span><span class="o">.</span><span class="n">is_a?</span><span class="p">(</span><span class="ss">GroupDocs</span><span class="p">:</span><span class="ss">:Storage</span><span class="o">::</span><span class="no">File</span><span class="p">)</span>
128
-
129
-
130
- <span class="n">document</span> <span class="o">=</span> <span class="n">file</span><span class="o">.</span><span class="n">to_document</span>
131
-
132
- <span class="n">convert</span> <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="n">convert!</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">convert_type</span><span class="p">,</span> <span class="p">{</span><span class="ss">:callback</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">callback</span><span class="p">},</span> <span class="p">{</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="ss">:private_key</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">})</span>
133
-
134
- <span class="nb">sleep</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
135
-
136
-
137
- <span class="n">original_document</span> <span class="o">=</span> <span class="n">convert</span><span class="o">.</span><span class="n">documents!</span><span class="p">({</span><span class="ss">:client_id</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="ss">:private_key</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">})</span>
138
-
139
-
140
- <span class="n">guid</span> <span class="o">=</span> <span class="n">original_document</span><span class="o">[</span><span class="ss">:inputs</span><span class="o">].</span><span class="n">first</span><span class="o">.</span><span class="n">outputs</span><span class="o">.</span><span class="n">first</span><span class="o">.</span><span class="n">guid</span>
141
-
142
-
143
- <span class="k">if</span> <span class="n">guid</span>
144
- <span class="n">iframe</span> <span class="o">=</span> <span class="s2">&quot;&lt;iframe width=&#39;100%&#39; height=&#39;600&#39; frameborder=&#39;0&#39; src=&#39;https://apps.groupdocs.com/document-viewer/embed/</span><span class="si">#{</span><span class="n">guid</span><span class="si">}</span><span class="s2">&#39;&gt;&lt;/iframe&gt;&quot;</span>
145
- <span class="k">else</span>
146
- <span class="k">raise</span> <span class="s1">&#39;File was not converted&#39;</span>
147
- <span class="k">end</span>
148
-
149
- <span class="k">rescue</span> <span class="no">Exception</span> <span class="o">=&gt;</span> <span class="n">e</span>
150
- <span class="n">err</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span>
151
- <span class="k">end</span>
152
-
153
-
154
- <span class="n">haml</span> <span class="ss">:sample18</span><span class="p">,</span> <span class="ss">:locals</span> <span class="o">=&gt;</span> <span class="p">{</span><span class="ss">:userId</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="ss">:privateKey</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">,</span> <span class="ss">:callback</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">callback</span><span class="p">,</span> <span class="ss">:fileId</span> <span class="o">=&gt;</span> <span class="n">file</span><span class="p">,</span> <span class="ss">:converted</span> <span class="o">=&gt;</span> <span class="n">guid</span><span class="p">,</span> <span class="ss">:iframe</span> <span class="o">=&gt;</span> <span class="n">iframe</span><span class="p">,</span> <span class="ss">:err</span> <span class="o">=&gt;</span> <span class="n">err</span><span class="p">}</span>
155
- <span class="k">end</span>
156
-
157
- </pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sample18.rb</title>
6
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
7
+ <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
8
+ <link rel="stylesheet" media="all" href="docco.css" />
9
+ </head>
10
+ <body>
11
+ <div id="container">
12
+ <div id="background"></div>
13
+
14
+ <ul class="sections">
15
+
16
+ <li id="title">
17
+ <div class="annotation">
18
+ <h1>sample18.rb</h1>
19
+ </div>
20
+ </li>
21
+
22
+
23
+
24
+ <li id="section-1">
25
+ <div class="annotation">
26
+
27
+ <div class="pilwrap ">
28
+ <a class="pilcrow" href="#section-1">&#182;</a>
29
+ </div>
30
+ <p>GET request</p>
31
+
32
+ </div>
33
+
34
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample18'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample18</span>
36
+ <span class="keyword">end</span></pre></div></div>
37
+
38
+ </li>
39
+
40
+
41
+ <li id="section-2">
42
+ <div class="annotation">
43
+
44
+ <div class="pilwrap ">
45
+ <a class="pilcrow" href="#section-2">&#182;</a>
46
+ </div>
47
+ <p>POST request</p>
48
+
49
+ </div>
50
+
51
+ <div class="content"><div class='highlight'><pre>post <span class="string">'/sample18/convert_callback'</span> <span class="keyword">do</span></pre></div></div>
52
+
53
+ </li>
54
+
55
+
56
+ <li id="section-3">
57
+ <div class="annotation">
58
+
59
+ <div class="pilwrap ">
60
+ <a class="pilcrow" href="#section-3">&#182;</a>
61
+ </div>
62
+ <p>Set download path</p>
63
+
64
+ </div>
65
+
66
+ <div class="content"><div class='highlight'><pre> downloads_path = <span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/downloads"</span></pre></div></div>
67
+
68
+ </li>
69
+
70
+
71
+ <li id="section-4">
72
+ <div class="annotation">
73
+
74
+ <div class="pilwrap ">
75
+ <a class="pilcrow" href="#section-4">&#182;</a>
76
+ </div>
77
+ <p>Get callback request</p>
78
+
79
+ </div>
80
+
81
+ <div class="content"><div class='highlight'><pre> data = <span class="constant">JSON</span>.parse(request.body.read)
82
+ <span class="keyword">begin</span>
83
+ raise <span class="string">'Empty params!'</span> <span class="keyword">if</span> data.empty?
84
+ source_id = <span class="keyword">nil</span>
85
+ client_id = <span class="keyword">nil</span>
86
+ private_key = <span class="keyword">nil</span></pre></div></div>
87
+
88
+ </li>
89
+
90
+
91
+ <li id="section-5">
92
+ <div class="annotation">
93
+
94
+ <div class="pilwrap ">
95
+ <a class="pilcrow" href="#section-5">&#182;</a>
96
+ </div>
97
+ <p>Get value of SourceId</p>
98
+
99
+ </div>
100
+
101
+ <div class="content"><div class='highlight'><pre> data.each <span class="keyword">do</span> |key, value|
102
+ <span class="keyword">if</span> key == <span class="string">'SourceId'</span>
103
+ source_id = value
104
+ <span class="keyword">end</span>
105
+ <span class="keyword">end</span></pre></div></div>
106
+
107
+ </li>
108
+
109
+
110
+ <li id="section-6">
111
+ <div class="annotation">
112
+
113
+ <div class="pilwrap ">
114
+ <a class="pilcrow" href="#section-6">&#182;</a>
115
+ </div>
116
+ <p>Get private key and client_id from file user_info.txt</p>
117
+
118
+ </div>
119
+
120
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="constant">File</span>.exist?(<span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/user_info.txt"</span>)
121
+ contents = <span class="constant">File</span>.read(<span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/user_info.txt"</span>)
122
+ contents = contents.split(<span class="string">' '</span>)
123
+ client_id = contents.first
124
+ private_key = contents.last
125
+ <span class="keyword">end</span></pre></div></div>
126
+
127
+ </li>
128
+
129
+
130
+ <li id="section-7">
131
+ <div class="annotation">
132
+
133
+ <div class="pilwrap ">
134
+ <a class="pilcrow" href="#section-7">&#182;</a>
135
+ </div>
136
+ <p>Create Job instance</p>
137
+
138
+ </div>
139
+
140
+ <div class="content"><div class='highlight'><pre> job = <span class="constant">GroupDocs::Job</span>.new({<span class="symbol">:id</span> =&gt; source_id})</pre></div></div>
141
+
142
+ </li>
143
+
144
+
145
+ <li id="section-8">
146
+ <div class="annotation">
147
+
148
+ <div class="pilwrap ">
149
+ <a class="pilcrow" href="#section-8">&#182;</a>
150
+ </div>
151
+ <p>Get document by job id</p>
152
+
153
+ </div>
154
+
155
+ <div class="content"><div class='highlight'><pre> documents = job.documents!({<span class="symbol">:client_id</span> =&gt; client_id, <span class="symbol">:private_key</span> =&gt; private_key})</pre></div></div>
156
+
157
+ </li>
158
+
159
+
160
+ <li id="section-9">
161
+ <div class="annotation">
162
+
163
+ <div class="pilwrap ">
164
+ <a class="pilcrow" href="#section-9">&#182;</a>
165
+ </div>
166
+ <p>Download converted file</p>
167
+
168
+ </div>
169
+
170
+ <div class="content"><div class='highlight'><pre> documents[<span class="symbol">:inputs</span>].first.outputs.first.download!(downloads_path, {<span class="symbol">:client_id</span> =&gt; client_id, <span class="symbol">:private_key</span> =&gt; private_key})
171
+
172
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
173
+ err = e.message
174
+ <span class="keyword">end</span>
175
+ <span class="keyword">end</span></pre></div></div>
176
+
177
+ </li>
178
+
179
+
180
+ <li id="section-10">
181
+ <div class="annotation">
182
+
183
+ <div class="pilwrap ">
184
+ <a class="pilcrow" href="#section-10">&#182;</a>
185
+ </div>
186
+ <p>GET request</p>
187
+
188
+ </div>
189
+
190
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample18/check'</span> <span class="keyword">do</span></pre></div></div>
191
+
192
+ </li>
193
+
194
+
195
+ <li id="section-11">
196
+ <div class="annotation">
197
+
198
+ <div class="pilwrap ">
199
+ <a class="pilcrow" href="#section-11">&#182;</a>
200
+ </div>
201
+ <p>Check is there download directory</p>
202
+
203
+ </div>
204
+
205
+ <div class="content"><div class='highlight'><pre> <span class="keyword">unless</span> <span class="constant">File</span>.directory?(<span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/downloads"</span>)
206
+ <span class="keyword">return</span> <span class="string">'Directory was not found.'</span>
207
+ <span class="keyword">end</span></pre></div></div>
208
+
209
+ </li>
210
+
211
+
212
+ <li id="section-12">
213
+ <div class="annotation">
214
+
215
+ <div class="pilwrap ">
216
+ <a class="pilcrow" href="#section-12">&#182;</a>
217
+ </div>
218
+ <p>Get file name from download directory</p>
219
+
220
+ </div>
221
+
222
+ <div class="content"><div class='highlight'><pre> name = <span class="keyword">nil</span>
223
+ <span class="constant">Dir</span>.entries(<span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/downloads"</span>).each <span class="keyword">do</span> |file|
224
+ name = file <span class="keyword">if</span> file != <span class="string">'.'</span> &amp;&amp; file != <span class="string">'..'</span>
225
+ <span class="keyword">end</span>
226
+
227
+ name
228
+ <span class="keyword">end</span></pre></div></div>
229
+
230
+ </li>
231
+
232
+
233
+ <li id="section-13">
234
+ <div class="annotation">
235
+
236
+ <div class="pilwrap ">
237
+ <a class="pilcrow" href="#section-13">&#182;</a>
238
+ </div>
239
+ <p>GET request</p>
240
+
241
+ </div>
242
+
243
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample18/downloads/:filename'</span> <span class="keyword">do</span> |filename|</pre></div></div>
244
+
245
+ </li>
246
+
247
+
248
+ <li id="section-14">
249
+ <div class="annotation">
250
+
251
+ <div class="pilwrap ">
252
+ <a class="pilcrow" href="#section-14">&#182;</a>
253
+ </div>
254
+ <p>Send file with header to download it</p>
255
+
256
+ </div>
257
+
258
+ <div class="content"><div class='highlight'><pre> send_file <span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/downloads/<span class="subst">#{filename}</span>"</span>, <span class="symbol">:filename</span> =&gt; filename, <span class="symbol">:type</span> =&gt; <span class="string">'Application/octet-stream'</span>
259
+ <span class="keyword">end</span></pre></div></div>
260
+
261
+ </li>
262
+
263
+
264
+ <li id="section-15">
265
+ <div class="annotation">
266
+
267
+ <div class="pilwrap ">
268
+ <a class="pilcrow" href="#section-15">&#182;</a>
269
+ </div>
270
+ <p>POST request</p>
271
+
272
+ </div>
273
+
274
+ <div class="content"><div class='highlight'><pre>post <span class="string">'/sample18'</span> <span class="keyword">do</span></pre></div></div>
275
+
276
+ </li>
277
+
278
+
279
+ <li id="section-16">
280
+ <div class="annotation">
281
+
282
+ <div class="pilwrap ">
283
+ <a class="pilcrow" href="#section-16">&#182;</a>
284
+ </div>
285
+ <p>set variables</p>
286
+
287
+ </div>
288
+
289
+ <div class="content"><div class='highlight'><pre> set <span class="symbol">:client_id</span>, params[<span class="symbol">:client_id</span>]
290
+ set <span class="symbol">:private_key</span>, params[<span class="symbol">:private_key</span>]
291
+ set <span class="symbol">:source</span>, params[<span class="symbol">:source</span>]
292
+ set <span class="symbol">:file_id</span>, params[<span class="symbol">:fileId</span>]
293
+ set <span class="symbol">:url</span>, params[<span class="symbol">:url</span>]
294
+ set <span class="symbol">:convert_type</span>, params[<span class="symbol">:convert_type</span>]
295
+ set <span class="symbol">:callback</span>, params[<span class="symbol">:callback</span>]</pre></div></div>
296
+
297
+ </li>
298
+
299
+
300
+ <li id="section-17">
301
+ <div class="annotation">
302
+
303
+ <div class="pilwrap ">
304
+ <a class="pilcrow" href="#section-17">&#182;</a>
305
+ </div>
306
+ <p>Set download path</p>
307
+
308
+ </div>
309
+
310
+ <div class="content"><div class='highlight'><pre> downloads_path = <span class="string">"<span class="subst">#{<span class="constant">File</span>.dirname(__FILE_<span class="number">_</span>)}</span>/../public/downloads"</span></pre></div></div>
311
+
312
+ </li>
313
+
314
+
315
+ <li id="section-18">
316
+ <div class="annotation">
317
+
318
+ <div class="pilwrap ">
319
+ <a class="pilcrow" href="#section-18">&#182;</a>
320
+ </div>
321
+ <p>Remove all files from download directory or create folder if it not there</p>
322
+
323
+ </div>
324
+
325
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="constant">File</span>.directory?(downloads_path)
326
+ <span class="constant">Dir</span>.foreach(downloads_path) { |f| fn = <span class="constant">File</span>.join(downloads_path, f); <span class="constant">File</span>.delete(fn) <span class="keyword">if</span> f != <span class="string">'.'</span> &amp;&amp; f != <span class="string">'..'</span> }
327
+ <span class="keyword">else</span>
328
+ <span class="constant">Dir::</span>mkdir(downloads_path)
329
+ <span class="keyword">end</span>
330
+
331
+ <span class="keyword">begin</span></pre></div></div>
332
+
333
+ </li>
334
+
335
+
336
+ <li id="section-19">
337
+ <div class="annotation">
338
+
339
+ <div class="pilwrap ">
340
+ <a class="pilcrow" href="#section-19">&#182;</a>
341
+ </div>
342
+ <p>check required variables</p>
343
+
344
+ </div>
345
+
346
+ <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>
347
+
348
+ </li>
349
+
350
+
351
+ <li id="section-20">
352
+ <div class="annotation">
353
+
354
+ <div class="pilwrap ">
355
+ <a class="pilcrow" href="#section-20">&#182;</a>
356
+ </div>
357
+ <p>Write client and private key to the file for callback job</p>
358
+
359
+ </div>
360
+
361
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.callback[<span class="number">0</span>]
362
+ 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>
363
+
364
+ </li>
365
+
366
+
367
+ <li id="section-21">
368
+ <div class="annotation">
369
+
370
+ <div class="pilwrap ">
371
+ <a class="pilcrow" href="#section-21">&#182;</a>
372
+ </div>
373
+ <p>white space is required</p>
374
+
375
+ </div>
376
+
377
+ <div class="content"><div class='highlight'><pre> out_file.write(<span class="string">"<span class="subst">#{settings.client_id}</span> "</span>)
378
+ out_file.write(<span class="string">"<span class="subst">#{settings.private_key}</span>"</span>)
379
+ out_file.close
380
+ <span class="keyword">end</span>
381
+
382
+ file = <span class="keyword">nil</span></pre></div></div>
383
+
384
+ </li>
385
+
386
+
387
+ <li id="section-22">
388
+ <div class="annotation">
389
+
390
+ <div class="pilwrap ">
391
+ <a class="pilcrow" href="#section-22">&#182;</a>
392
+ </div>
393
+ <p>get document by file GUID</p>
394
+
395
+ </div>
396
+
397
+ <div class="content"><div class='highlight'><pre> <span class="keyword">case</span> settings.source
398
+ <span class="keyword">when</span> <span class="string">'guid'</span></pre></div></div>
399
+
400
+ </li>
401
+
402
+
403
+ <li id="section-23">
404
+ <div class="annotation">
405
+
406
+ <div class="pilwrap ">
407
+ <a class="pilcrow" href="#section-23">&#182;</a>
408
+ </div>
409
+ <p>Create instance of File</p>
410
+
411
+ </div>
412
+
413
+ <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.new({<span class="symbol">:guid</span> =&gt; settings.file_id})
414
+ <span class="keyword">when</span> <span class="string">'local'</span></pre></div></div>
415
+
416
+ </li>
417
+
418
+
419
+ <li id="section-24">
420
+ <div class="annotation">
421
+
422
+ <div class="pilwrap ">
423
+ <a class="pilcrow" href="#section-24">&#182;</a>
424
+ </div>
425
+ <p>construct path</p>
426
+
427
+ </div>
428
+
429
+ <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>
430
+
431
+ </li>
432
+
433
+
434
+ <li id="section-25">
435
+ <div class="annotation">
436
+
437
+ <div class="pilwrap ">
438
+ <a class="pilcrow" href="#section-25">&#182;</a>
439
+ </div>
440
+ <p>open file</p>
441
+
442
+ </div>
443
+
444
+ <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>
445
+
446
+ </li>
447
+
448
+
449
+ <li id="section-26">
450
+ <div class="annotation">
451
+
452
+ <div class="pilwrap ">
453
+ <a class="pilcrow" href="#section-26">&#182;</a>
454
+ </div>
455
+ <p>make a request to API using client_id and private_key</p>
456
+
457
+ </div>
458
+
459
+ <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})
460
+ <span class="keyword">when</span> <span class="string">'url'</span></pre></div></div>
461
+
462
+ </li>
463
+
464
+
465
+ <li id="section-27">
466
+ <div class="annotation">
467
+
468
+ <div class="pilwrap ">
469
+ <a class="pilcrow" href="#section-27">&#182;</a>
470
+ </div>
471
+ <p>Upload file from defined url</p>
472
+
473
+ </div>
474
+
475
+ <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})
476
+ <span class="keyword">else</span>
477
+ raise <span class="string">'Wrong GUID source.'</span>
478
+ <span class="keyword">end</span></pre></div></div>
479
+
480
+ </li>
481
+
482
+
483
+ <li id="section-28">
484
+ <div class="annotation">
485
+
486
+ <div class="pilwrap ">
487
+ <a class="pilcrow" href="#section-28">&#182;</a>
488
+ </div>
489
+ <p>Raise exception if something went wrong</p>
490
+
491
+ </div>
492
+
493
+ <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>
494
+
495
+ </li>
496
+
497
+
498
+ <li id="section-29">
499
+ <div class="annotation">
500
+
501
+ <div class="pilwrap ">
502
+ <a class="pilcrow" href="#section-29">&#182;</a>
503
+ </div>
504
+ <p>Make document from file</p>
505
+
506
+ </div>
507
+
508
+ <div class="content"><div class='highlight'><pre> document = file.to_document</pre></div></div>
509
+
510
+ </li>
511
+
512
+
513
+ <li id="section-30">
514
+ <div class="annotation">
515
+
516
+ <div class="pilwrap ">
517
+ <a class="pilcrow" href="#section-30">&#182;</a>
518
+ </div>
519
+ <p>convert document</p>
520
+
521
+ </div>
522
+
523
+ <div class="content"><div class='highlight'><pre> convert = document.convert!(settings.convert_type, {<span class="symbol">:callback</span> =&gt; settings.callback}, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})</pre></div></div>
524
+
525
+ </li>
526
+
527
+
528
+ <li id="section-31">
529
+ <div class="annotation">
530
+
531
+ <div class="pilwrap ">
532
+ <a class="pilcrow" href="#section-31">&#182;</a>
533
+ </div>
534
+ <p>waite 10 seconds for while file converting</p>
535
+
536
+ </div>
537
+
538
+ <div class="content"><div class='highlight'><pre> sleep(<span class="number">10</span>)</pre></div></div>
539
+
540
+ </li>
541
+
542
+
543
+ <li id="section-32">
544
+ <div class="annotation">
545
+
546
+ <div class="pilwrap ">
547
+ <a class="pilcrow" href="#section-32">&#182;</a>
548
+ </div>
549
+ <p>Get array of changes in document from job</p>
550
+
551
+ </div>
552
+
553
+ <div class="content"><div class='highlight'><pre> original_document = convert.documents!({<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})</pre></div></div>
554
+
555
+ </li>
556
+
557
+
558
+ <li id="section-33">
559
+ <div class="annotation">
560
+
561
+ <div class="pilwrap ">
562
+ <a class="pilcrow" href="#section-33">&#182;</a>
563
+ </div>
564
+ <p>Get converted document GUID</p>
565
+
566
+ </div>
567
+
568
+ <div class="content"><div class='highlight'><pre> guid = original_document[<span class="symbol">:inputs</span>].first.outputs.first.guid</pre></div></div>
569
+
570
+ </li>
571
+
572
+
573
+ <li id="section-34">
574
+ <div class="annotation">
575
+
576
+ <div class="pilwrap ">
577
+ <a class="pilcrow" href="#section-34">&#182;</a>
578
+ </div>
579
+ <p>Set iframe with document GUID or raise an error</p>
580
+
581
+ </div>
582
+
583
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> guid
584
+ iframe = <span class="string">"&lt;iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/<span class="subst">#{guid}</span>'&gt;&lt;/iframe&gt;"</span>
585
+ <span class="keyword">else</span>
586
+ raise <span class="string">'File was not converted'</span>
587
+ <span class="keyword">end</span>
588
+
589
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
590
+ err = e.message
591
+ <span class="keyword">end</span></pre></div></div>
592
+
593
+ </li>
594
+
595
+
596
+ <li id="section-35">
597
+ <div class="annotation">
598
+
599
+ <div class="pilwrap ">
600
+ <a class="pilcrow" href="#section-35">&#182;</a>
601
+ </div>
602
+ <p>set variables for template</p>
603
+
604
+ </div>
605
+
606
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample18</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, <span class="symbol">:callback</span> =&gt; settings.callback, <span class="symbol">:fileId</span> =&gt; file, <span class="symbol">:converted</span> =&gt; guid, <span class="symbol">:iframe</span> =&gt; iframe, <span class="symbol">:err</span> =&gt; err}
607
+ <span class="keyword">end</span></pre></div></div>
608
+
609
+ </li>
610
+
611
+ </ul>
612
+ </div>
613
+ </body>
614
+ </html>