groupdocs 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/CHANGELOG.md +6 -0
  2. data/examples/api-samples/README.md +1 -1
  3. data/examples/api-samples/public/css/style.css +2 -2
  4. data/examples/api-samples/public/docs/annotation-sample.html +57 -0
  5. data/examples/api-samples/public/docs/envelope-sample.html +32 -32
  6. data/examples/api-samples/public/docs/sample1.html +3 -3
  7. data/examples/api-samples/public/docs/sample10.html +25 -24
  8. data/examples/api-samples/public/docs/sample11.html +17 -17
  9. data/examples/api-samples/public/docs/sample12.html +4 -4
  10. data/examples/api-samples/public/docs/sample13.html +5 -5
  11. data/examples/api-samples/public/docs/sample14.html +5 -5
  12. data/examples/api-samples/public/docs/sample15.html +4 -4
  13. data/examples/api-samples/public/docs/sample16.html +3 -3
  14. data/examples/api-samples/public/docs/sample17.html +3 -3
  15. data/examples/api-samples/public/docs/sample18.html +129 -34
  16. data/examples/api-samples/public/docs/sample19.html +59 -0
  17. data/examples/api-samples/public/docs/sample2.html +5 -5
  18. data/examples/api-samples/public/docs/sample20.html +51 -0
  19. data/examples/api-samples/public/docs/sample21.html +66 -0
  20. data/examples/api-samples/public/docs/sample22.html +53 -0
  21. data/examples/api-samples/public/docs/sample3.html +4 -4
  22. data/examples/api-samples/public/docs/sample4.html +27 -16
  23. data/examples/api-samples/public/docs/sample5.html +29 -22
  24. data/examples/api-samples/public/docs/sample6.html +6 -6
  25. data/examples/api-samples/public/docs/sample7.html +8 -8
  26. data/examples/api-samples/public/docs/sample8.html +31 -23
  27. data/examples/api-samples/public/docs/sample9.html +26 -8
  28. data/examples/api-samples/public/templates/merge_feid_doc.docx +0 -0
  29. data/examples/api-samples/samples/annotation-sample.rb +22 -16
  30. data/examples/api-samples/samples/envelope-sample.rb +26 -25
  31. data/examples/api-samples/samples/sample1.rb +2 -2
  32. data/examples/api-samples/samples/sample10.rb +21 -20
  33. data/examples/api-samples/samples/sample11.rb +18 -18
  34. data/examples/api-samples/samples/sample12.rb +3 -3
  35. data/examples/api-samples/samples/sample13.rb +4 -4
  36. data/examples/api-samples/samples/sample14.rb +4 -4
  37. data/examples/api-samples/samples/sample15.rb +3 -3
  38. data/examples/api-samples/samples/sample16.rb +2 -2
  39. data/examples/api-samples/samples/sample17.rb +2 -2
  40. data/examples/api-samples/samples/sample18.rb +90 -106
  41. data/examples/api-samples/samples/sample19.rb +5 -5
  42. data/examples/api-samples/samples/sample2.rb +4 -4
  43. data/examples/api-samples/samples/sample20.rb +4 -4
  44. data/examples/api-samples/samples/sample21.rb +4 -4
  45. data/examples/api-samples/samples/sample22.rb +2 -2
  46. data/examples/api-samples/samples/sample23.rb +0 -0
  47. data/examples/api-samples/samples/sample24.rb +0 -0
  48. data/examples/api-samples/samples/sample25.rb +96 -0
  49. data/examples/api-samples/samples/sample3.rb +3 -3
  50. data/examples/api-samples/samples/sample4.rb +23 -12
  51. data/examples/api-samples/samples/sample5.rb +23 -16
  52. data/examples/api-samples/samples/sample6.rb +8 -8
  53. data/examples/api-samples/samples/sample7.rb +7 -7
  54. data/examples/api-samples/samples/sample8.rb +29 -21
  55. data/examples/api-samples/samples/sample9.rb +23 -5
  56. data/examples/api-samples/views/_others_samples.haml +57 -0
  57. data/examples/api-samples/views/annotation_sample.haml +30 -30
  58. data/examples/api-samples/views/envelope_sample.haml +31 -31
  59. data/examples/api-samples/views/index.haml +33 -25
  60. data/examples/api-samples/views/sample1.haml +22 -69
  61. data/examples/api-samples/views/sample10.haml +57 -73
  62. data/examples/api-samples/views/sample11.haml +31 -79
  63. data/examples/api-samples/views/sample12.haml +18 -66
  64. data/examples/api-samples/views/sample13.haml +21 -70
  65. data/examples/api-samples/views/sample14.haml +18 -67
  66. data/examples/api-samples/views/sample15.haml +15 -63
  67. data/examples/api-samples/views/sample16.haml +13 -61
  68. data/examples/api-samples/views/sample17.haml +19 -67
  69. data/examples/api-samples/views/sample18.haml +74 -159
  70. data/examples/api-samples/views/sample19.haml +25 -74
  71. data/examples/api-samples/views/sample2.haml +19 -66
  72. data/examples/api-samples/views/sample20.haml +19 -68
  73. data/examples/api-samples/views/sample21.haml +28 -76
  74. data/examples/api-samples/views/sample22.haml +29 -77
  75. data/examples/api-samples/views/sample23.haml +0 -0
  76. data/examples/api-samples/views/sample24.haml +0 -0
  77. data/examples/api-samples/views/sample25.haml +91 -0
  78. data/examples/api-samples/views/sample3.haml +20 -68
  79. data/examples/api-samples/views/sample4.haml +53 -68
  80. data/examples/api-samples/views/sample5.haml +54 -70
  81. data/examples/api-samples/views/sample6.haml +21 -69
  82. data/examples/api-samples/views/sample7.haml +19 -66
  83. data/examples/api-samples/views/sample8.haml +60 -75
  84. data/examples/api-samples/views/sample9.haml +54 -70
  85. data/examples/api-samples/web.rb +20 -0
  86. data/lib/groupdocs/api/request.rb +4 -2
  87. data/lib/groupdocs/version.rb +1 -1
  88. data/spec/groupdocs/api/request_spec.rb +10 -2
  89. metadata +18 -5
  90. data/examples/api-samples/app.rb +0 -15
@@ -1,21 +1,39 @@
1
- <!DOCTYPE html> <html> <head> <title>sample9.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="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="sample2.html"> sample2.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> sample9.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;/sample9&#39;</span> <span class="k">do</span>
1
+ <!DOCTYPE html> <html> <head> <title>sample9.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> sample9.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;/sample9&#39;</span> <span class="k">do</span>
2
2
  <span class="n">haml</span> <span class="ss">:sample9</span>
3
3
  <span class="k">end</span>
4
4
 
5
5
 
6
6
  <span class="n">post</span> <span class="s1">&#39;/sample9&#39;</span> <span class="k">do</span>
7
7
 
8
- <span class="n">set</span> <span class="ss">:guid</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:guid</span><span class="o">]</span>
8
+ <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>
9
9
  <span class="n">set</span> <span class="ss">:width</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:width</span><span class="o">]</span>
10
10
  <span class="n">set</span> <span class="ss">:height</span><span class="p">,</span> <span class="n">params</span><span class="o">[</span><span class="ss">:height</span><span class="o">]</span>
11
11
 
12
12
  <span class="k">begin</span>
13
13
 
14
- <span class="k">raise</span> <span class="s2">&quot;Please enter all required parameters&quot;</span> <span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">guid</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">width</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">height</span><span class="o">.</span><span class="n">empty?</span>
14
+ <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">guid</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">width</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">height</span><span class="o">.</span><span class="n">empty?</span>
15
+
16
+
17
+ <span class="n">file</span> <span class="o">=</span> <span class="kp">nil</span>
18
+ <span class="k">case</span> <span class="n">settings</span><span class="o">.</span><span class="n">source</span>
19
+ <span class="k">when</span> <span class="s1">&#39;guid&#39;</span>
20
+ <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>
21
+ <span class="k">when</span> <span class="s1">&#39;local&#39;</span>
22
+
23
+ <span class="n">filepath</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>
24
+
25
+ <span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">filepath</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>
26
+
27
+ <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">filepath</span><span class="p">,</span> <span class="p">{},</span> <span class="n">client_id</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="n">private_key</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">)</span>
28
+ <span class="k">when</span> <span class="s1">&#39;url&#39;</span>
29
+ <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="n">client_id</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">client_id</span><span class="p">,</span> <span class="n">private_key</span><span class="p">:</span> <span class="n">settings</span><span class="o">.</span><span class="n">private_key</span><span class="p">)</span>
30
+ <span class="k">else</span>
31
+ <span class="k">raise</span> <span class="s1">&#39;Wrong GUID source.&#39;</span>
32
+ <span class="k">end</span>
33
+
34
+
35
+ <span class="n">v_url</span> <span class="o">=</span> <span class="s2">&quot;https://apps.groupdocs.com/document-viewer/embed/</span><span class="si">#{</span><span class="n">file</span><span class="o">.</span><span class="n">guid</span><span class="si">}</span><span class="s2">?frameborder=&#39;0&#39; width=&#39;</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">width</span><span class="si">}</span><span class="s2">&#39; height=&#39;</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">height</span><span class="si">}</span><span class="s2">&#39;&quot;</span>
15
36
 
16
-
17
- <span class="n">v_url</span> <span class="o">=</span> <span class="s2">&quot;https://apps.groupdocs.com/document-viewer/embed/</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">guid</span><span class="si">}</span><span class="s2">?frameborder=&#39;0&#39; width=&#39;</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">width</span><span class="si">}</span><span class="s2">&#39; height=&#39;</span><span class="si">#{</span><span class="n">settings</span><span class="o">.</span><span class="n">height</span><span class="si">}</span><span class="s2">&#39;&quot;</span>
18
-
19
37
  <span class="k">if</span> <span class="n">v_url</span>
20
38
  <span class="n">v_url</span> <span class="o">=</span> <span class="n">v_url</span>
21
39
  <span class="k">end</span>
@@ -24,8 +42,8 @@
24
42
  <span class="n">err</span> <span class="o">=</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span>
25
43
  <span class="k">end</span>
26
44
 
27
-
28
- <span class="n">haml</span> <span class="ss">:sample9</span><span class="p">,</span> <span class="ss">:locals</span> <span class="o">=&gt;</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">guid</span><span class="p">,</span> <span class="ss">:width</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">width</span><span class="p">,</span> <span class="ss">:height</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">height</span><span class="p">,</span> <span class="ss">:v_url</span><span class="o">=&gt;</span><span class="n">v_url</span><span class="p">,</span> <span class="ss">:err</span> <span class="o">=&gt;</span> <span class="n">err</span> <span class="p">}</span>
45
+
46
+ <span class="n">haml</span> <span class="ss">:sample9</span><span class="p">,</span> <span class="ss">:locals</span> <span class="o">=&gt;</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">guid</span><span class="p">,</span> <span class="ss">:width</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">width</span><span class="p">,</span> <span class="ss">:height</span> <span class="o">=&gt;</span> <span class="n">settings</span><span class="o">.</span><span class="n">height</span><span class="p">,</span> <span class="ss">:v_url</span> <span class="o">=&gt;</span> <span class="n">v_url</span><span class="p">,</span> <span class="ss">:err</span> <span class="o">=&gt;</span> <span class="n">err</span><span class="p">}</span>
29
47
  <span class="k">end</span>
30
48
 
31
49
  </pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
@@ -7,10 +7,14 @@ end
7
7
  post '/annotation-sample' do
8
8
  set :client_id, params[:client_id]
9
9
  set :private_key, params[:private_key]
10
+
11
+ set :email, params[:email]
12
+ set :first_name, params[:first_name]
13
+ set :last_name, params[:last_name]
10
14
  set :file_name, params[:file_name]
11
15
 
12
16
  begin
13
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_name.empty?
17
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_name.empty?
14
18
 
15
19
  GroupDocs.configure do |groupdocs|
16
20
  groupdocs.client_id = params[:client_id]
@@ -18,33 +22,35 @@ post '/annotation-sample' do
18
22
  groupdocs.api_server = 'https://api.groupdocs.com'
19
23
  end
20
24
  # get document metadata
21
- metadata = GroupDocs::Document.metadata!('resume.pdf')
25
+ metadata = GroupDocs::Document.metadata!(settings.file_name)
22
26
  document = GroupDocs::Storage::File.new(id: metadata.id, guid: metadata.guid).to_document
23
-
27
+
24
28
  # create new user
25
29
  user = GroupDocs::User.new
26
- user.nickname = 'test_account'
27
- user.primary_email = 'test_email@email.com'
28
- user.first_name = 'First name'
29
- user.last_name = 'Last name'
30
+ user.nickname = settings.email
31
+ user.primary_email = settings.email
32
+ user.first_name = settings.first_name
33
+ user.last_name = settings.last_name
30
34
  user = GroupDocs::User.update_account!(user)
31
-
35
+
32
36
  # add collaborator
33
37
  document.add_collaborator! user unless document.collaborators!.any? { |c| c.guid == user.guid }
34
-
38
+
35
39
  # build url
36
40
  annotation = true # looks like "IsAnnotation" is some helper method so I stub it here
37
41
  url = if annotation
38
- "/document-annotation2/embed?quality=50&guid=#{document.file.guid}&uid=#{user.guid}&download=True"
39
- else
40
- "/document-viewer/embed?quality=50&guid=#{document.file.guid}&uid=#{user.guid}&download=True"
41
- end
42
+ "/document-annotation2/embed?quality=50&guid=#{document.file.guid}&uid=#{user.guid}&download=True"
43
+ else
44
+ "/document-viewer/embed?quality=50&guid=#{document.file.guid}&uid=#{user.guid}&download=True"
45
+ end
46
+
47
+ # you can sign document
48
+ #url = GroupDocs::Api::Request.new(path: url).prepare_and_sign_url
42
49
 
43
- url = GroupDocs::Api::Request.new(path: url).prepare_and_sign_url
44
- iframe_url = "https://apps.groupdocs.com#{url}"
50
+ iframe = "<iframe src='https://apps.groupdocs.com#{url}' frameborder='0' width='720' height='600'></iframe>"
45
51
  rescue Exception => e
46
52
  err = e.message
47
53
  end
48
54
 
49
- haml :annotation_sample, :locals => { :client_id => settings.client_id, :private_key => settings.private_key, :err => err, :file_name => settings.file_name, :iframe_url => iframe_url}
55
+ haml :annotation_sample, :locals => {:client_id => settings.client_id, :private_key => settings.private_key, :err => err, :file_name => settings.file_name, :email => settings.email, :first_name => settings.first_name, :last_name => settings.last_name, :iframe => iframe}
50
56
  end
@@ -8,13 +8,13 @@ post '/envelope-sample/sign' do
8
8
  # Content Type of callback is application/json
9
9
  data = JSON.parse(request.body.read)
10
10
  begin
11
- raise "Empty params!" if data.empty?
11
+ raise 'Empty params!' if data.empty?
12
12
  #create empty file and write data as "key: value" to it
13
- outFile = File.new("signed", "w")
13
+ out_file = File.new('signed', 'w')
14
14
  data.each do |key, value|
15
- outFile.write("#{key}: #{value} \n")
15
+ out_file.write("#{key}: #{value} \n")
16
16
  end
17
- outFile.close
17
+ out_file.close
18
18
  rescue Exception => e
19
19
  err = e.message
20
20
  end
@@ -24,18 +24,18 @@ end
24
24
  # POST request to handle callback and download envelop when document was signed
25
25
  post '/envelope-sample/sign-and-download' do
26
26
  data = JSON.parse(request.body.read)
27
- begin
28
- raise "Empty params!" if data.empty?
27
+ begin
28
+ raise 'Empty params!' if data.empty?
29
29
  GroupDocs.configure do |groupdocs|
30
- groupdocs.client_id = '' # Your client Client ID here
31
- groupdocs.private_key = '' # Your API Key here
32
- groupdocs.api_server = 'https://api.groupdocs.com'
30
+ groupdocs.client_id = '' # Your client Client ID here
31
+ groupdocs.private_key = '' # Your API Key here
32
+ groupdocs.api_server = 'https://api.groupdocs.com'
33
33
  end
34
34
  data.each do |key, value|
35
35
  if key == 'SourceId'
36
36
  # Create envelop with id and name as SourceId parameter from callback
37
37
  envelope = GroupDocs::Signature::Envelope.new id: value,
38
- name: value
38
+ name: value
39
39
  # download signed documents as archive
40
40
  envelope.signed_documents! '.'
41
41
  end
@@ -50,7 +50,7 @@ get '/envelope-sample/check' do
50
50
  if File.exist?('signed')
51
51
  File.readlines('signed').each do |line|
52
52
  end
53
- else
53
+ else
54
54
  'Have not signed yet'
55
55
  end
56
56
  end
@@ -61,41 +61,41 @@ post '/envelope-sample' do
61
61
  set :private_key, params[:private_key]
62
62
 
63
63
  begin
64
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
64
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
65
65
 
66
66
  GroupDocs.configure do |groupdocs|
67
67
  groupdocs.client_id = params[:client_id]
68
68
  groupdocs.private_key = params[:private_key]
69
69
  groupdocs.api_server = 'https://stage-api.groupdocs.com'
70
70
  end
71
-
71
+
72
72
  # upload document
73
73
  filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
74
74
  File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
75
75
  file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
76
76
  document = file.to_document
77
-
77
+
78
78
  # create envelope
79
79
  envelope = GroupDocs::Signature::Envelope.new
80
- envelope.name = "Envelope"
81
- envelope.email_subject = "Sing this!"
80
+ envelope.name = 'Envelope'
81
+ envelope.email_subject = 'Sing this!'
82
82
  envelope.create!
83
-
83
+
84
84
  # add document to envelope
85
85
  envelope.add_document! document
86
-
86
+
87
87
  # update document object after it's created
88
88
  document = envelope.documents!.first
89
-
89
+
90
90
  # add new recipient to envelope
91
91
  roles = GroupDocs::Signature::Role.get!
92
92
  recipient = GroupDocs::Signature::Recipient.new
93
93
  recipient.email = 'john@smith.com'
94
94
  recipient.first_name = 'John'
95
95
  recipient.last_name = 'Smith'
96
- recipient.role_id = roles.detect { |role| role.name == "Signer" }.id
96
+ recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
97
97
  envelope.add_recipient! recipient
98
-
98
+
99
99
  # update recipient object after it's created
100
100
  recipient = envelope.recipients!.first
101
101
 
@@ -108,18 +108,19 @@ post '/envelope-sample' do
108
108
  #field.name = 'City'
109
109
  #field.location = { location_x: 0.3, location_y: 0.2, page: 1 }
110
110
  #envelope.add_field! field, document, recipient
111
-
111
+
112
112
  # add signature field to envelope
113
113
  #field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
114
114
  #field.location = { location_x: 0.3, location_y: 0.3, page: 1 }
115
115
  #envelope.add_field! field, document, recipient
116
116
 
117
117
  # URL for callback
118
- webhook = 'http://groupdocs-ruby-samples.herokuapp.com/envelope-sample/sign'
118
+ #webhook = 'http://groupdocs-ruby-samples.herokuapp.com/envelope-sample/sign'
119
+ webhook = 'http://77.81.243.48/?q=groupdocs_signature/signature_callback'
119
120
 
120
121
  # send envelope
121
122
  envelope.send! webhook
122
-
123
+
123
124
  # construct embedded signature url
124
125
  url = "https://stage-apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
125
126
  iframe = "<iframe src='#{url}' frameborder='0' width='720' height='600'></iframe>"
@@ -128,5 +129,5 @@ post '/envelope-sample' do
128
129
  err = e.message
129
130
  end
130
131
 
131
- haml :envelope_sample, :locals => { :client_id => settings.client_id, :private_key => settings.private_key, :err => err, :iframe => iframe}
132
+ haml :envelope_sample, :locals => {:client_id => settings.client_id, :private_key => settings.private_key, :err => err, :iframe => iframe}
132
133
  end
@@ -11,7 +11,7 @@ post '/sample1' do
11
11
 
12
12
  begin
13
13
  # check required variables
14
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty?
14
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
15
15
 
16
16
  # make a request to API using client_id and private_key
17
17
  user = GroupDocs::User.get!({:client_id => settings.client_id, :private_key => settings.private_key})
@@ -21,5 +21,5 @@ post '/sample1' do
21
21
  end
22
22
 
23
23
  # set variables for template
24
- haml :sample1, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :user => user, :err => err }
24
+ haml :sample1, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :user => user, :err => err}
25
25
  end
@@ -8,32 +8,33 @@ post '/sample10' do
8
8
  # set variables
9
9
  set :client_id, params[:client_id]
10
10
  set :private_key, params[:private_key]
11
- set :guid, params[:guid]
11
+ set :guid, params[:fileId]
12
12
  set :email, params[:email]
13
13
 
14
14
  begin
15
15
  # check required variables
16
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.guid.empty? or settings.email.empty?
17
-
18
- # make a request to API using client_id and private_key
19
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
20
-
21
- name = nil
22
- doc = nil
23
- files_list.each do |element|
24
- if element.class.name.split('::').last == 'Folder'
25
- next
26
- end
27
-
28
- # get document and document name
29
- if element.guid == settings.guid
30
- name = element.name
31
- doc = element
32
- end
16
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.guid.empty? or settings.email.empty?
17
+
18
+ # get document by file GUID
19
+ file = nil
20
+ case settings.source
21
+ when 'guid'
22
+ file = GroupDocs::Storage::File.new({:guid => settings.guid})
23
+ when 'local'
24
+ # construct path
25
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
26
+ # open file
27
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
28
+ # make a request to API using client_id and private_key
29
+ file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
30
+ when 'url'
31
+ file = GroupDocs::Storage::File.upload_web!(settings.url, client_id: settings.client_id, private_key: settings.private_key)
32
+ else
33
+ raise 'Wrong GUID source.'
33
34
  end
34
35
 
35
36
  # Share document. Make a request to API using client_id and private_key
36
- shared = doc.to_document.sharers_set!(settings.email.split(" "), { :client_id => settings.client_id, :private_key => settings.private_key});
37
+ shared = file.to_document.sharers_set!(settings.email.split(' '), {:client_id => settings.client_id, :private_key => settings.private_key})
37
38
 
38
39
  # result
39
40
  if shared
@@ -44,5 +45,5 @@ post '/sample10' do
44
45
  end
45
46
 
46
47
  # set variables for template
47
- haml :sample10, :locals => { :client_id => settings.client_id, :private_key => settings.private_key, :guid => settings.guid, :email=>settings.email, :shared => shared_emails, :err => err }
48
+ haml :sample10, :locals => {:client_id => settings.client_id, :private_key => settings.private_key, :guid => settings.guid, :email => settings.email, :shared => shared_emails, :err => err}
48
49
  end
@@ -13,28 +13,28 @@ post '/sample11' do
13
13
 
14
14
  begin
15
15
  # check required variables
16
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.annotation_type.empty?
16
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.annotation_type.empty?
17
17
 
18
18
  # annotation types
19
- types = {'text' => 0, 'area' => 1, 'point' => 2}
19
+ types = {:text => 0, :area => 1, :point => 2}
20
20
 
21
21
  # required parameters
22
- allParams = allParams = ['annotation_type', 'box_x', 'box_y', 'text']
22
+ all_params = all_params = ['annotation_type', 'box_x', 'box_y', 'text']
23
23
 
24
24
  # added required parameters depends on annotation type ['text' or 'area']
25
- if settings.annotation_type == "text"
26
- allParams = allParams | ['box_width', 'box_height', 'annotationPosition_x', 'annotationPosition_y']
27
- elsif settings.annotation_type == "area"
28
- allParams = allParams | ['box_width', 'box_height']
25
+ if settings.annotation_type == 'text'
26
+ all_params = all_params | ['box_width', 'box_height', 'annotationPosition_x', 'annotationPosition_y']
27
+ elsif settings.annotation_type == 'area'
28
+ all_params = all_params | ['box_width', 'box_height']
29
29
  end
30
30
 
31
31
  # checking required parameters
32
- allParams.each do |param|
33
- raise "Please enter all required parameters" if params[param].empty?
32
+ all_params.each do |param|
33
+ raise 'Please enter all required parameters' if params[param].empty?
34
34
  end
35
35
 
36
36
  # make a request to API using client_id and private_key
37
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
37
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, {:client_id => settings.client_id, :private_key => settings.private_key})
38
38
  document = ''
39
39
 
40
40
  # get document by file ID
@@ -52,28 +52,28 @@ post '/sample11' do
52
52
 
53
53
  # construct requestBody depends on annotation type
54
54
  # text annotation
55
- if settings.annotation_type == "text"
55
+ if settings.annotation_type == 'text'
56
56
  annotation.box = {x: params['box_x'], y: params['box_y'], width: params['box_width'], height: params['box_height']}
57
57
  annotation.annotationPosition = {x: params['annotationPosition_x'], y: params['annotationPosition_y']}
58
58
 
59
- # area annotation
60
- elsif settings.annotation_type == "area"
59
+ # area annotation
60
+ elsif settings.annotation_type == 'area'
61
61
  annotation.box = {x: params['box_x'], y: params['box_y'], width: params['box_width'], height: params['box_height']}
62
62
  annotation.annotationPosition = {x: 0, y: 0}
63
63
 
64
- # point annotation
65
- elsif settings.annotation_type == "point"
64
+ # point annotation
65
+ elsif settings.annotation_type == 'point'
66
66
  annotation.box = {x: params['box_x'], y: params['box_y'], width: 0, height: 0}
67
67
  annotation.annotationPosition = {x: 0, y: 0}
68
68
  end
69
69
 
70
70
  # call create method
71
- annotation.create!({ :client_id => settings.client_id, :private_key => settings.private_key})
71
+ annotation.create!({:client_id => settings.client_id, :private_key => settings.private_key})
72
72
 
73
73
  # add annotation reply
74
74
  reply = GroupDocs::Document::Annotation::Reply.new(annotation: annotation)
75
75
  reply.text = params['text']
76
- reply.create!({ :client_id => settings.client_id, :private_key => settings.private_key})
76
+ reply.create!({:client_id => settings.client_id, :private_key => settings.private_key})
77
77
 
78
78
  end
79
79
 
@@ -82,5 +82,5 @@ post '/sample11' do
82
82
  end
83
83
 
84
84
  # set variables for template
85
- haml :sample11, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :annotationType => settings.annotation_type, :annotationId => (defined? annotation.id) ? annotation.id : nil, :annotationText => params['text'], :err => err }
85
+ haml :sample11, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :annotationType => settings.annotation_type, :annotationId => (defined? annotation.id) ? annotation.id : nil, :annotationText => params['text'], :err => err}
86
86
  end
@@ -12,10 +12,10 @@ post '/sample12' do
12
12
 
13
13
  begin
14
14
  # check required variables
15
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
15
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
16
16
 
17
17
  # make a request to API using client_id and private_key
18
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
18
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, {:client_id => settings.client_id, :private_key => settings.private_key})
19
19
  document = ''
20
20
 
21
21
  # get document by file ID
@@ -35,5 +35,5 @@ post '/sample12' do
35
35
  end
36
36
 
37
37
  # set variables for template
38
- haml :sample12, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :annotations => annotations, :fileId => settings.file_id, :err => err }
38
+ haml :sample12, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :annotations => annotations, :fileId => settings.file_id, :err => err}
39
39
  end
@@ -13,10 +13,10 @@ post '/sample13' do
13
13
 
14
14
  begin
15
15
  # check required variables
16
- raise "Please enter all required parameters" if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.email.empty?
16
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.email.empty?
17
17
 
18
18
  # make a request to API using client_id and private_key
19
- files_list = GroupDocs::Storage::Folder.list!('/', {}, { :client_id => settings.client_id, :private_key => settings.private_key})
19
+ files_list = GroupDocs::Storage::Folder.list!('/', {}, {:client_id => settings.client_id, :private_key => settings.private_key})
20
20
  document = ''
21
21
 
22
22
  # get document by file ID
@@ -28,7 +28,7 @@ post '/sample13' do
28
28
 
29
29
  unless document.instance_of? String
30
30
  # add collaborator to doc with annotations
31
- result = document.to_document.set_collaborators!(settings.email.split(" "), 1, {:client_id => settings.client_id, :private_key => settings.private_key})
31
+ result = document.to_document.set_collaborators!(settings.email.split(' '), 1, {:client_id => settings.client_id, :private_key => settings.private_key})
32
32
  end
33
33
 
34
34
  rescue Exception => e
@@ -36,5 +36,5 @@ post '/sample13' do
36
36
  end
37
37
 
38
38
  # set variables for template
39
- haml :sample13, :locals => { :userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :email => settings.email, :result => result, :err => err }
39
+ haml :sample13, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :email => settings.email, :result => result, :err => err}
40
40
  end