groupdocs 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/CHANGELOG.md +51 -0
  2. data/examples/api-samples/Gemfile +1 -1
  3. data/examples/api-samples/Gemfile.lock +43 -0
  4. data/examples/api-samples/public/docs/{sample2.html → sample01.html} +39 -19
  5. data/examples/api-samples/public/docs/{sample3.html → sample02.html} +28 -22
  6. data/examples/api-samples/public/docs/sample03.html +285 -0
  7. data/examples/api-samples/public/docs/{sample4.html → sample04.html} +30 -36
  8. data/examples/api-samples/public/docs/{sample5.html → sample05.html} +68 -31
  9. data/examples/api-samples/public/docs/sample06.html +299 -0
  10. data/examples/api-samples/public/docs/{sample7.html → sample07.html} +53 -18
  11. data/examples/api-samples/public/docs/{sample8.html → sample08.html} +64 -41
  12. data/examples/api-samples/public/docs/sample09.html +260 -0
  13. data/examples/api-samples/public/docs/sample10.html +67 -28
  14. data/examples/api-samples/public/docs/sample11.html +171 -55
  15. data/examples/api-samples/public/docs/sample12.html +53 -17
  16. data/examples/api-samples/public/docs/sample13.html +52 -16
  17. data/examples/api-samples/public/docs/sample14.html +51 -8
  18. data/examples/api-samples/public/docs/sample15.html +46 -10
  19. data/examples/api-samples/public/docs/sample16.html +81 -7
  20. data/examples/api-samples/public/docs/sample17.html +103 -15
  21. data/examples/api-samples/public/docs/sample18.html +117 -41
  22. data/examples/api-samples/public/docs/sample19.html +410 -36
  23. data/examples/api-samples/public/docs/sample20.html +46 -10
  24. data/examples/api-samples/public/docs/sample21.html +504 -45
  25. data/examples/api-samples/public/docs/sample22.html +166 -28
  26. data/examples/api-samples/public/docs/sample23.html +61 -25
  27. data/examples/api-samples/public/docs/sample24.html +100 -12
  28. data/examples/api-samples/public/docs/sample25.html +123 -49
  29. data/examples/api-samples/public/docs/sample26.html +41 -8
  30. data/examples/api-samples/public/docs/sample27.html +125 -50
  31. data/examples/api-samples/public/docs/sample28.html +27 -9
  32. data/examples/api-samples/public/docs/sample29.html +10 -10
  33. data/examples/api-samples/public/docs/sample30.html +70 -14
  34. data/examples/api-samples/public/docs/sample31.html +108 -67
  35. data/examples/api-samples/public/docs/sample32.html +71 -99
  36. data/examples/api-samples/public/docs/sample33.html +107 -32
  37. data/examples/api-samples/public/docs/{sample1.html → sample34.html} +58 -18
  38. data/examples/api-samples/public/docs/sample35.html +666 -0
  39. data/examples/api-samples/public/docs/{sample6.html → sample36.html} +56 -37
  40. data/examples/api-samples/public/docs/sample37.html +815 -0
  41. data/examples/api-samples/public/docs/sample38.html +508 -0
  42. data/examples/api-samples/public/docs/sample39.html +921 -0
  43. data/examples/api-samples/public/docs/sample40.html +510 -0
  44. data/examples/api-samples/public/docs/sample41.html +452 -0
  45. data/examples/api-samples/public/docs/sample42.html +311 -0
  46. data/examples/api-samples/public/templates/test_all_fields2.pdf +0 -0
  47. data/examples/api-samples/samples/sample01.rb +37 -0
  48. data/examples/api-samples/samples/sample02.rb +41 -0
  49. data/examples/api-samples/samples/sample03.rb +73 -0
  50. data/examples/api-samples/samples/sample04.rb +47 -0
  51. data/examples/api-samples/samples/{sample5.rb → sample05.rb} +26 -14
  52. data/examples/api-samples/samples/sample06.rb +80 -0
  53. data/examples/api-samples/samples/sample07.rb +52 -0
  54. data/examples/api-samples/samples/sample08.rb +69 -0
  55. data/examples/api-samples/samples/sample09.rb +83 -0
  56. data/examples/api-samples/samples/sample10.rb +29 -15
  57. data/examples/api-samples/samples/sample11.rb +89 -37
  58. data/examples/api-samples/samples/sample12.rb +22 -11
  59. data/examples/api-samples/samples/sample13.rb +22 -10
  60. data/examples/api-samples/samples/sample14.rb +23 -5
  61. data/examples/api-samples/samples/sample15.rb +18 -7
  62. data/examples/api-samples/samples/sample16.rb +28 -4
  63. data/examples/api-samples/samples/sample17.rb +31 -5
  64. data/examples/api-samples/samples/sample18.rb +36 -8
  65. data/examples/api-samples/samples/sample19.rb +138 -18
  66. data/examples/api-samples/samples/sample20.rb +14 -3
  67. data/examples/api-samples/samples/sample21.rb +162 -23
  68. data/examples/api-samples/samples/sample22.rb +73 -22
  69. data/examples/api-samples/samples/sample23.rb +17 -6
  70. data/examples/api-samples/samples/sample24.rb +34 -7
  71. data/examples/api-samples/samples/sample25.rb +37 -12
  72. data/examples/api-samples/samples/sample26.rb +12 -5
  73. data/examples/api-samples/samples/sample27.rb +38 -12
  74. data/examples/api-samples/samples/sample28.rb +25 -6
  75. data/examples/api-samples/samples/sample29.rb +12 -12
  76. data/examples/api-samples/samples/sample30.rb +27 -15
  77. data/examples/api-samples/samples/sample31.rb +44 -33
  78. data/examples/api-samples/samples/sample32.rb +43 -41
  79. data/examples/api-samples/samples/sample33.rb +42 -14
  80. data/examples/api-samples/samples/sample34.rb +40 -0
  81. data/examples/api-samples/samples/sample35.rb +224 -0
  82. data/examples/api-samples/samples/sample36.rb +58 -0
  83. data/examples/api-samples/samples/sample37.rb +229 -0
  84. data/examples/api-samples/samples/sample38.rb +128 -0
  85. data/examples/api-samples/samples/sample39.rb +252 -0
  86. data/examples/api-samples/samples/sample40.rb +164 -0
  87. data/examples/api-samples/samples/sample41.rb +118 -0
  88. data/examples/api-samples/samples/sample42.rb +97 -0
  89. data/examples/api-samples/views/_others_samples.haml +25 -11
  90. data/examples/api-samples/views/index.haml +23 -11
  91. data/examples/api-samples/views/popup.haml +32 -0
  92. data/examples/api-samples/views/{sample1.haml → sample01.haml} +12 -7
  93. data/examples/api-samples/views/{sample2.haml → sample02.haml} +20 -15
  94. data/examples/api-samples/views/sample03.haml +83 -0
  95. data/examples/api-samples/views/sample04.haml +49 -0
  96. data/examples/api-samples/views/{sample5.haml → sample05.haml} +19 -14
  97. data/examples/api-samples/views/sample06.haml +53 -0
  98. data/examples/api-samples/views/sample07.haml +47 -0
  99. data/examples/api-samples/views/{sample8.haml → sample08.haml} +17 -12
  100. data/examples/api-samples/views/{sample9.haml → sample09.haml} +19 -4
  101. data/examples/api-samples/views/sample10.haml +18 -13
  102. data/examples/api-samples/views/sample11.haml +48 -19
  103. data/examples/api-samples/views/sample12.haml +26 -21
  104. data/examples/api-samples/views/sample13.haml +18 -12
  105. data/examples/api-samples/views/sample14.haml +21 -15
  106. data/examples/api-samples/views/sample15.haml +16 -9
  107. data/examples/api-samples/views/sample16.haml +18 -5
  108. data/examples/api-samples/views/sample17.haml +14 -9
  109. data/examples/api-samples/views/sample18.haml +13 -7
  110. data/examples/api-samples/views/sample19.haml +37 -8
  111. data/examples/api-samples/views/sample20.haml +13 -8
  112. data/examples/api-samples/views/sample21.haml +71 -13
  113. data/examples/api-samples/views/sample22.haml +53 -16
  114. data/examples/api-samples/views/sample23.haml +9 -4
  115. data/examples/api-samples/views/sample24.haml +9 -4
  116. data/examples/api-samples/views/sample25.haml +18 -13
  117. data/examples/api-samples/views/sample26.haml +8 -3
  118. data/examples/api-samples/views/sample27.haml +20 -14
  119. data/examples/api-samples/views/sample28.haml +16 -10
  120. data/examples/api-samples/views/sample29.haml +4 -4
  121. data/examples/api-samples/views/sample30.haml +16 -10
  122. data/examples/api-samples/views/sample31.haml +39 -32
  123. data/examples/api-samples/views/sample32.haml +25 -36
  124. data/examples/api-samples/views/sample33.haml +14 -17
  125. data/examples/api-samples/views/sample34.haml +48 -0
  126. data/examples/api-samples/views/sample35.haml +95 -0
  127. data/examples/api-samples/views/sample36.haml +64 -0
  128. data/examples/api-samples/views/sample37.haml +124 -0
  129. data/examples/api-samples/views/sample38.haml +115 -0
  130. data/examples/api-samples/views/sample39.haml +236 -0
  131. data/examples/api-samples/views/sample40.haml +95 -0
  132. data/examples/api-samples/views/{sample4.haml → sample41.haml} +90 -72
  133. data/examples/api-samples/views/sample42.haml +59 -0
  134. data/lib/groupdocs/api/helpers/rest_helper.rb +13 -1
  135. data/lib/groupdocs/datasource.rb +2 -1
  136. data/lib/groupdocs/document.rb +101 -13
  137. data/lib/groupdocs/document/annotation.rb +28 -13
  138. data/lib/groupdocs/document/annotation/marker.rb +18 -0
  139. data/lib/groupdocs/document/annotation/reply.rb +9 -2
  140. data/lib/groupdocs/document/field.rb +5 -1
  141. data/lib/groupdocs/job.rb +12 -2
  142. data/lib/groupdocs/questionnaire.rb +174 -4
  143. data/lib/groupdocs/questionnaire/collector.rb +21 -0
  144. data/lib/groupdocs/questionnaire/question.rb +19 -0
  145. data/lib/groupdocs/questionnaire/question/answer.rb +5 -0
  146. data/lib/groupdocs/questionnaire/question/conditions.rb +20 -0
  147. data/lib/groupdocs/signature.rb +36 -308
  148. data/lib/groupdocs/signature/envelope.rb +146 -4
  149. data/lib/groupdocs/signature/field.rb +20 -1
  150. data/lib/groupdocs/signature/field/location.rb +18 -7
  151. data/lib/groupdocs/signature/form.rb +199 -10
  152. data/lib/groupdocs/signature/shared/document_methods.rb +38 -0
  153. data/lib/groupdocs/signature/shared/entity_methods.rb +0 -1
  154. data/lib/groupdocs/signature/shared/field_methods.rb +13 -38
  155. data/lib/groupdocs/signature/shared/recipient_methods.rb +8 -0
  156. data/lib/groupdocs/signature/template.rb +3 -1
  157. data/lib/groupdocs/storage.rb +4 -1
  158. data/lib/groupdocs/storage/file.rb +18 -1
  159. data/lib/groupdocs/subscription.rb +8 -3
  160. data/lib/groupdocs/user.rb +8 -0
  161. data/lib/groupdocs/version.rb +1 -1
  162. data/spec/groupdocs/document/annotation_spec.rb +1 -14
  163. data/spec/groupdocs/subscription_spec.rb +2 -2
  164. metadata +86 -32
  165. checksums.yaml +0 -15
  166. data/examples/api-samples/public/docs/sample9.html +0 -200
  167. data/examples/api-samples/samples/sample1.rb +0 -25
  168. data/examples/api-samples/samples/sample2.rb +0 -29
  169. data/examples/api-samples/samples/sample3.rb +0 -33
  170. data/examples/api-samples/samples/sample4.rb +0 -51
  171. data/examples/api-samples/samples/sample6.rb +0 -49
  172. data/examples/api-samples/samples/sample7.rb +0 -42
  173. data/examples/api-samples/samples/sample8.rb +0 -61
  174. data/examples/api-samples/samples/sample9.rb +0 -48
  175. data/examples/api-samples/views/sample3.haml +0 -44
  176. data/examples/api-samples/views/sample6.haml +0 -49
  177. data/examples/api-samples/views/sample7.haml +0 -42
@@ -2,7 +2,7 @@
2
2
 
3
3
  <html>
4
4
  <head>
5
- <title>sample6.rb</title>
5
+ <title>sample36.rb</title>
6
6
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
7
7
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
8
8
  <link rel="stylesheet" media="all" href="docco.css" />
@@ -15,7 +15,7 @@
15
15
 
16
16
  <li id="title">
17
17
  <div class="annotation">
18
- <h1>sample6.rb</h1>
18
+ <h1>sample36.rb</h1>
19
19
  </div>
20
20
  </li>
21
21
 
@@ -31,8 +31,8 @@
31
31
 
32
32
  </div>
33
33
 
34
- <div class="content"><div class='highlight'><pre>get <span class="string">'/sample6'</span> <span class="keyword">do</span>
35
- haml <span class="symbol">:sample6</span>
34
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample36'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample36</span>
36
36
  <span class="keyword">end</span></pre></div></div>
37
37
 
38
38
  </li>
@@ -48,7 +48,7 @@
48
48
 
49
49
  </div>
50
50
 
51
- <div class="content"><div class='highlight'><pre>post <span class="string">'/sample6'</span> <span class="keyword">do</span></pre></div></div>
51
+ <div class="content"><div class='highlight'><pre>post <span class="string">'/sample36'</span> <span class="keyword">do</span></pre></div></div>
52
52
 
53
53
  </li>
54
54
 
@@ -59,14 +59,14 @@
59
59
  <div class="pilwrap ">
60
60
  <a class="pilcrow" href="#section-3">&#182;</a>
61
61
  </div>
62
- <p>set variables</p>
62
+ <p>Set variables</p>
63
63
 
64
64
  </div>
65
65
 
66
- <div class="content"><div class='highlight'><pre> set <span class="symbol">:client_id</span>, params[<span class="symbol">:client_id</span>]
67
- set <span class="symbol">:private_key</span>, params[<span class="symbol">:private_key</span>]
68
-
69
- <span class="keyword">begin</span></pre></div></div>
66
+ <div class="content"><div class='highlight'><pre> set <span class="symbol">:client_id</span>, params[<span class="symbol">:clientId</span>]
67
+ set <span class="symbol">:private_key</span>, params[<span class="symbol">:privateKey</span>]
68
+ set <span class="symbol">:envelope</span>, params[<span class="symbol">:envelopeGuid</span>]
69
+ set <span class="symbol">:base_path</span>, params[<span class="symbol">:basePath</span>]</pre></div></div>
70
70
 
71
71
  </li>
72
72
 
@@ -77,11 +77,11 @@
77
77
  <div class="pilwrap ">
78
78
  <a class="pilcrow" href="#section-4">&#182;</a>
79
79
  </div>
80
- <p>check required variables</p>
80
+ <p>Set download path</p>
81
81
 
82
82
  </div>
83
83
 
84
- <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>
84
+ <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>
85
85
 
86
86
  </li>
87
87
 
@@ -92,12 +92,18 @@
92
92
  <div class="pilwrap ">
93
93
  <a class="pilcrow" href="#section-5">&#182;</a>
94
94
  </div>
95
- <p>construct file path and open file</p>
95
+ <p>Remove all files from download directory or create folder if it not there</p>
96
96
 
97
97
  </div>
98
98
 
99
- <div class="content"><div class='highlight'><pre> file_one_path = <span class="string">"<span class="subst">#{<span class="constant">Dir</span>.tmpdir}</span>/<span class="subst">#{params[<span class="symbol">:document</span>][<span class="symbol">:filename</span>]}</span>"</span>
100
- <span class="constant">File</span>.open(file_one_path, <span class="string">'wb'</span>) { |f| f.write(params[<span class="symbol">:document</span>][<span class="symbol">:tempfile</span>].read) }</pre></div></div>
99
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="constant">File</span>.directory?(downloads_path)
100
+ <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> }
101
+ <span class="keyword">else</span>
102
+ <span class="constant">Dir::</span>mkdir(downloads_path)
103
+ <span class="keyword">end</span>
104
+
105
+
106
+ <span class="keyword">begin</span></pre></div></div>
101
107
 
102
108
  </li>
103
109
 
@@ -108,12 +114,13 @@
108
114
  <div class="pilwrap ">
109
115
  <a class="pilcrow" href="#section-6">&#182;</a>
110
116
  </div>
111
- <p>create new file</p>
117
+ <p>Check required variables</p>
112
118
 
113
119
  </div>
114
120
 
115
- <div class="content"><div class='highlight'><pre> file_one = <span class="constant">GroupDocs::Storage::File</span>.new(<span class="symbol">name:</span> params[<span class="symbol">:document</span>][<span class="symbol">:filename</span>], <span class="symbol">local_path:</span> file_one_path)
116
- document_one = file_one.to_document</pre></div></div>
121
+ <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?
122
+
123
+ <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>
117
124
 
118
125
  </li>
119
126
 
@@ -124,12 +131,13 @@
124
131
  <div class="pilwrap ">
125
132
  <a class="pilcrow" href="#section-7">&#182;</a>
126
133
  </div>
127
- <p>construct signature path and open file</p>
134
+ <p>Configure your access to API server</p>
128
135
 
129
136
  </div>
130
137
 
131
- <div class="content"><div class='highlight'><pre> signature_one_path = <span class="string">"<span class="subst">#{<span class="constant">Dir</span>.tmpdir}</span>/<span class="subst">#{params[<span class="symbol">:signature</span>][<span class="symbol">:filename</span>]}</span>"</span>
132
- <span class="constant">File</span>.open(signature_one_path, <span class="string">'wb'</span>) { |f| f.write(params[<span class="symbol">:signature</span>][<span class="symbol">:tempfile</span>].read) }</pre></div></div>
138
+ <div class="content"><div class='highlight'><pre> <span class="constant">GroupDocs</span>.configure <span class="keyword">do</span> |groupdocs|
139
+ groupdocs.client_id = settings.client_id
140
+ groupdocs.private_key = settings.private_key</pre></div></div>
133
141
 
134
142
  </li>
135
143
 
@@ -140,12 +148,12 @@
140
148
  <div class="pilwrap ">
141
149
  <a class="pilcrow" href="#section-8">&#182;</a>
142
150
  </div>
143
- <p>add signature to file using API</p>
151
+ <p>Optionally specify API server and version</p>
144
152
 
145
153
  </div>
146
154
 
147
- <div class="content"><div class='highlight'><pre> signature_one = <span class="constant">GroupDocs::Signature</span>.new(<span class="symbol">name:</span> <span class="string">'Test'</span>, <span class="symbol">image_path:</span> signature_one_path)
148
- signature_one.position = {<span class="symbol">top:</span> <span class="number">0</span>.<span class="number">1</span>, <span class="symbol">left:</span> <span class="number">0</span>.<span class="number">07</span>, <span class="symbol">width:</span> <span class="number">50</span>, <span class="symbol">height:</span> <span class="number">50</span>}</pre></div></div>
155
+ <div class="content"><div class='highlight'><pre> groupdocs.api_server = settings.base_path <span class="comment"># default is 'https://api.groupdocs.com'</span>
156
+ <span class="keyword">end</span></pre></div></div>
149
157
 
150
158
  </li>
151
159
 
@@ -156,13 +164,11 @@
156
164
  <div class="pilwrap ">
157
165
  <a class="pilcrow" href="#section-9">&#182;</a>
158
166
  </div>
159
- <p>raise signature_one.to_yaml
160
- make a request to API using client_id and private_key</p>
167
+ <p>Get envelope from GroupDocs Storage</p>
161
168
 
162
169
  </div>
163
170
 
164
- <div class="content"><div class='highlight'><pre> signed_documents = <span class="constant">GroupDocs::Document</span>.sign_documents!([document_one], [signature_one], {}, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})
165
- guid = signed_documents.first.file.guid</pre></div></div>
171
+ <div class="content"><div class='highlight'><pre> envelope = <span class="constant">GroupDocs::Signature::Envelope</span>.get!(settings.envelope)</pre></div></div>
166
172
 
167
173
  </li>
168
174
 
@@ -173,17 +179,11 @@ make a request to API using client_id and private_key</p>
173
179
  <div class="pilwrap ">
174
180
  <a class="pilcrow" href="#section-10">&#182;</a>
175
181
  </div>
176
- <p>generate result</p>
182
+ <p>Download signed files</p>
177
183
 
178
184
  </div>
179
185
 
180
- <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> signed_documents
181
- iframe = <span class="string">"&lt;iframe src='https://apps.groupdocs.com/document-viewer/Embed/<span class="subst">#{guid}</span>' frameborder='0' width='720' height='600'&gt;&lt;/iframe&gt;"</span>
182
- <span class="keyword">end</span>
183
-
184
- <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
185
- err = e.message
186
- <span class="keyword">end</span></pre></div></div>
186
+ <div class="content"><div class='highlight'><pre> path = envelope.signed_documents!(downloads_path)</pre></div></div>
187
187
 
188
188
  </li>
189
189
 
@@ -194,11 +194,30 @@ make a request to API using client_id and private_key</p>
194
194
  <div class="pilwrap ">
195
195
  <a class="pilcrow" href="#section-11">&#182;</a>
196
196
  </div>
197
+ <p>Get file name</p>
198
+
199
+ </div>
200
+
201
+ <div class="content"><div class='highlight'><pre> file = path.split(<span class="string">'/'</span>).last
202
+
203
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
204
+ err = e.message
205
+ <span class="keyword">end</span></pre></div></div>
206
+
207
+ </li>
208
+
209
+
210
+ <li id="section-12">
211
+ <div class="annotation">
212
+
213
+ <div class="pilwrap ">
214
+ <a class="pilcrow" href="#section-12">&#182;</a>
215
+ </div>
197
216
  <p>set variables for template</p>
198
217
 
199
218
  </div>
200
219
 
201
- <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample6</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">:iframe</span> =&gt; iframe, <span class="symbol">:err</span> =&gt; err}
220
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample36</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">:fileName</span> =&gt; file, <span class="symbol">:err</span> =&gt; err}
202
221
  <span class="keyword">end</span></pre></div></div>
203
222
 
204
223
  </li>
@@ -0,0 +1,815 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sample37.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>sample37.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>Route the handler url &quot;/sample37&quot;</p>
31
+
32
+ </div>
33
+
34
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample37'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample37</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>GET request</p>
48
+
49
+ </div>
50
+
51
+ </li>
52
+
53
+
54
+ <li id="section-3">
55
+ <div class="annotation">
56
+
57
+ <div class="pilwrap ">
58
+ <a class="pilcrow" href="#section-3">&#182;</a>
59
+ </div>
60
+ <p>Route the handler url &quot;/sample37/signature_callback&quot;. The block function for callback with server</p>
61
+
62
+ </div>
63
+
64
+ <div class="content"><div class='highlight'><pre>post <span class="string">'/sample37/signature_callback'</span> <span class="keyword">do</span></pre></div></div>
65
+
66
+ </li>
67
+
68
+
69
+ <li id="section-4">
70
+ <div class="annotation">
71
+
72
+ <div class="pilwrap ">
73
+ <a class="pilcrow" href="#section-4">&#182;</a>
74
+ </div>
75
+ <p>Get data json from callback</p>
76
+
77
+ </div>
78
+
79
+ <div class="content"><div class='highlight'><pre> data = <span class="constant">JSON</span>.parse(request.body.read)
80
+ <span class="keyword">begin</span>
81
+
82
+ raise <span class="string">'Empty params!'</span> <span class="keyword">if</span> data.empty?</pre></div></div>
83
+
84
+ </li>
85
+
86
+
87
+ <li id="section-5">
88
+ <div class="annotation">
89
+
90
+ <div class="pilwrap ">
91
+ <a class="pilcrow" href="#section-5">&#182;</a>
92
+ </div>
93
+ <p>Set variables from data json</p>
94
+
95
+ </div>
96
+
97
+ <div class="content"><div class='highlight'><pre> source_id = data[<span class="string">'SourceId'</span>]
98
+ event_type = data[<span class="string">'EventType'</span>]</pre></div></div>
99
+
100
+ </li>
101
+
102
+
103
+ <li id="section-6">
104
+ <div class="annotation">
105
+
106
+ <div class="pilwrap ">
107
+ <a class="pilcrow" href="#section-6">&#182;</a>
108
+ </div>
109
+ <p>Set variables</p>
110
+
111
+ </div>
112
+
113
+ <div class="content"><div class='highlight'><pre> client_id = <span class="keyword">nil</span>
114
+ private_key = <span class="keyword">nil</span>
115
+
116
+ <span class="keyword">return</span> <span class="keyword">if</span> event_type != <span class="string">'JobCompleted'</span></pre></div></div>
117
+
118
+ </li>
119
+
120
+
121
+ <li id="section-7">
122
+ <div class="annotation">
123
+
124
+ <div class="pilwrap ">
125
+ <a class="pilcrow" href="#section-7">&#182;</a>
126
+ </div>
127
+ <p>Set download path</p>
128
+
129
+ </div>
130
+
131
+ <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>
132
+
133
+ </li>
134
+
135
+
136
+ <li id="section-8">
137
+ <div class="annotation">
138
+
139
+ <div class="pilwrap ">
140
+ <a class="pilcrow" href="#section-8">&#182;</a>
141
+ </div>
142
+ <p>Get private key and client_id from file user_info.txt</p>
143
+
144
+ </div>
145
+
146
+ <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>)
147
+ 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>)
148
+ contents = contents.split(<span class="string">' '</span>)
149
+ client_id = contents[<span class="number">0</span>]
150
+ private_key = contents[<span class="number">1</span>]
151
+ <span class="keyword">end</span></pre></div></div>
152
+
153
+ </li>
154
+
155
+
156
+ <li id="section-9">
157
+ <div class="annotation">
158
+
159
+ <div class="pilwrap ">
160
+ <a class="pilcrow" href="#section-9">&#182;</a>
161
+ </div>
162
+ <p>Get Envelope instance</p>
163
+
164
+ </div>
165
+
166
+ <div class="content"><div class='highlight'><pre> envelope = <span class="constant">GroupDocs::Signature::Envelope</span>.get!(source_id, {<span class="symbol">:client_id</span> =&gt; client_id, <span class="symbol">:private_key</span> =&gt; private_key})</pre></div></div>
167
+
168
+ </li>
169
+
170
+
171
+ <li id="section-10">
172
+ <div class="annotation">
173
+
174
+ <div class="pilwrap ">
175
+ <a class="pilcrow" href="#section-10">&#182;</a>
176
+ </div>
177
+ <p>Get document by envelope</p>
178
+
179
+ </div>
180
+
181
+ <div class="content"><div class='highlight'><pre> envelope.signed_documents!(downloads_path, {<span class="symbol">:client_id</span> =&gt; client_id, <span class="symbol">:private_key</span> =&gt; private_key})
182
+
183
+
184
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
185
+ err = e.message
186
+ <span class="keyword">end</span>
187
+ <span class="keyword">end</span></pre></div></div>
188
+
189
+ </li>
190
+
191
+
192
+ <li id="section-11">
193
+ <div class="annotation">
194
+
195
+ <div class="pilwrap ">
196
+ <a class="pilcrow" href="#section-11">&#182;</a>
197
+ </div>
198
+ <p>Route the handler url &quot;/sample37/check&quot;</p>
199
+
200
+ </div>
201
+
202
+ <div class="content"><div class='highlight'><pre>
203
+ get <span class="string">'/sample37/check'</span> <span class="keyword">do</span></pre></div></div>
204
+
205
+ </li>
206
+
207
+
208
+ <li id="section-12">
209
+ <div class="annotation">
210
+
211
+ <div class="pilwrap ">
212
+ <a class="pilcrow" href="#section-12">&#182;</a>
213
+ </div>
214
+ <p>Check is there download directory</p>
215
+
216
+ </div>
217
+
218
+ <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>)
219
+ <span class="keyword">return</span> <span class="string">'Directory was not found.'</span>
220
+ <span class="keyword">end</span></pre></div></div>
221
+
222
+ </li>
223
+
224
+
225
+ <li id="section-13">
226
+ <div class="annotation">
227
+
228
+ <div class="pilwrap ">
229
+ <a class="pilcrow" href="#section-13">&#182;</a>
230
+ </div>
231
+ <p>Get file name from download directory</p>
232
+
233
+ </div>
234
+
235
+ <div class="content"><div class='highlight'><pre> name = <span class="keyword">nil</span>
236
+
237
+ i = <span class="number">0</span></pre></div></div>
238
+
239
+ </li>
240
+
241
+
242
+ <li id="section-14">
243
+ <div class="annotation">
244
+
245
+ <div class="pilwrap ">
246
+ <a class="pilcrow" href="#section-14">&#182;</a>
247
+ </div>
248
+ <p>Checking, if file exist</p>
249
+
250
+ </div>
251
+
252
+ <div class="content"><div class='highlight'><pre> <span class="keyword">while</span> i&lt;<span class="number">10</span> <span class="keyword">do</span>
253
+ sleep(<span class="number">5</span>)
254
+ <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|
255
+ name = file <span class="keyword">if</span> file != <span class="string">'.'</span> &amp;&amp; file != <span class="string">'..'</span>
256
+ <span class="keyword">end</span>
257
+ <span class="keyword">break</span> <span class="keyword">if</span> name
258
+ i += <span class="number">1</span>
259
+ <span class="keyword">end</span>
260
+
261
+ name
262
+ <span class="keyword">end</span></pre></div></div>
263
+
264
+ </li>
265
+
266
+
267
+ <li id="section-15">
268
+ <div class="annotation">
269
+
270
+ <div class="pilwrap ">
271
+ <a class="pilcrow" href="#section-15">&#182;</a>
272
+ </div>
273
+ <p>Route the handler url &quot;/sample37/downloads&quot;</p>
274
+
275
+ </div>
276
+
277
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample37/downloads/:filename'</span> <span class="keyword">do</span> |filename|</pre></div></div>
278
+
279
+ </li>
280
+
281
+
282
+ <li id="section-16">
283
+ <div class="annotation">
284
+
285
+ <div class="pilwrap ">
286
+ <a class="pilcrow" href="#section-16">&#182;</a>
287
+ </div>
288
+ <p>Send file with header to download it</p>
289
+
290
+ </div>
291
+
292
+ <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>
293
+ <span class="keyword">end</span></pre></div></div>
294
+
295
+ </li>
296
+
297
+
298
+ <li id="section-17">
299
+ <div class="annotation">
300
+
301
+ <div class="pilwrap ">
302
+ <a class="pilcrow" href="#section-17">&#182;</a>
303
+ </div>
304
+ <p>Route the handler url &quot;/sample37&quot;. The function block creates new envelope</p>
305
+
306
+ </div>
307
+
308
+ <div class="content"><div class='highlight'><pre>post <span class="string">'/sample37'</span> <span class="keyword">do</span></pre></div></div>
309
+
310
+ </li>
311
+
312
+
313
+ <li id="section-18">
314
+ <div class="annotation">
315
+
316
+ <div class="pilwrap ">
317
+ <a class="pilcrow" href="#section-18">&#182;</a>
318
+ </div>
319
+ <p>Set variables from form</p>
320
+
321
+ </div>
322
+
323
+ <div class="content"><div class='highlight'><pre> set <span class="symbol">:client_id</span>, params[<span class="symbol">:clientId</span>]
324
+ set <span class="symbol">:private_key</span>, params[<span class="symbol">:privateKey</span>]
325
+ set <span class="symbol">:email</span>, params[<span class="symbol">:email</span>]
326
+ set <span class="symbol">:name</span>, params[<span class="symbol">:name</span>]
327
+ set <span class="symbol">:lastName</span>, params[<span class="symbol">:lastName</span>]
328
+ set <span class="symbol">:fileId</span>, params[<span class="symbol">:fileId</span>]
329
+ set <span class="symbol">:callback</span>, params[<span class="symbol">:callback</span>]
330
+ set <span class="symbol">:base_path</span>, params[<span class="symbol">:basePath</span>]
331
+ set <span class="symbol">:url</span>, params[<span class="symbol">:url</span>]
332
+ set <span class="symbol">:source</span>, params[<span class="symbol">:source</span>]</pre></div></div>
333
+
334
+ </li>
335
+
336
+
337
+ <li id="section-19">
338
+ <div class="annotation">
339
+
340
+ <div class="pilwrap ">
341
+ <a class="pilcrow" href="#section-19">&#182;</a>
342
+ </div>
343
+ <p>Set download path</p>
344
+
345
+ </div>
346
+
347
+ <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>
348
+
349
+ </li>
350
+
351
+
352
+ <li id="section-20">
353
+ <div class="annotation">
354
+
355
+ <div class="pilwrap ">
356
+ <a class="pilcrow" href="#section-20">&#182;</a>
357
+ </div>
358
+ <p>Remove all files from download directory or create folder if it not there</p>
359
+
360
+ </div>
361
+
362
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="constant">File</span>.directory?(downloads_path)
363
+ <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> }
364
+ <span class="keyword">else</span>
365
+ <span class="constant">Dir::</span>mkdir(downloads_path)
366
+ <span class="keyword">end</span>
367
+
368
+ <span class="keyword">begin</span></pre></div></div>
369
+
370
+ </li>
371
+
372
+
373
+ <li id="section-21">
374
+ <div class="annotation">
375
+
376
+ <div class="pilwrap ">
377
+ <a class="pilcrow" href="#section-21">&#182;</a>
378
+ </div>
379
+ <p>Check required variables</p>
380
+
381
+ </div>
382
+
383
+ <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.email.empty? <span class="keyword">or</span> settings.name.empty? <span class="keyword">or</span> settings.lastName.empty?
384
+
385
+ <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>
386
+
387
+ </li>
388
+
389
+
390
+ <li id="section-22">
391
+ <div class="annotation">
392
+
393
+ <div class="pilwrap ">
394
+ <a class="pilcrow" href="#section-22">&#182;</a>
395
+ </div>
396
+ <p>Configure your access to API server</p>
397
+
398
+ </div>
399
+
400
+ <div class="content"><div class='highlight'><pre> <span class="constant">GroupDocs</span>.configure <span class="keyword">do</span> |groupdocs|
401
+ groupdocs.client_id = settings.client_id
402
+ groupdocs.private_key = settings.private_key</pre></div></div>
403
+
404
+ </li>
405
+
406
+
407
+ <li id="section-23">
408
+ <div class="annotation">
409
+
410
+ <div class="pilwrap ">
411
+ <a class="pilcrow" href="#section-23">&#182;</a>
412
+ </div>
413
+ <p>Optionally specify API server and version</p>
414
+
415
+ </div>
416
+
417
+ <div class="content"><div class='highlight'><pre> groupdocs.api_server = settings.base_path <span class="comment"># default is 'https://api.groupdocs.com'</span>
418
+ <span class="keyword">end</span></pre></div></div>
419
+
420
+ </li>
421
+
422
+
423
+ <li id="section-24">
424
+ <div class="annotation">
425
+
426
+ <div class="pilwrap ">
427
+ <a class="pilcrow" href="#section-24">&#182;</a>
428
+ </div>
429
+ <p>Write client and private key to the file for callback job</p>
430
+
431
+ </div>
432
+
433
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.callback
434
+ 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>
435
+
436
+ </li>
437
+
438
+
439
+ <li id="section-25">
440
+ <div class="annotation">
441
+
442
+ <div class="pilwrap ">
443
+ <a class="pilcrow" href="#section-25">&#182;</a>
444
+ </div>
445
+ <p>white space is required</p>
446
+
447
+ </div>
448
+
449
+ <div class="content"><div class='highlight'><pre> out_file.write(<span class="string">"<span class="subst">#{settings.client_id}</span> "</span>)
450
+ out_file.write(<span class="string">"<span class="subst">#{settings.private_key}</span>"</span>)
451
+ out_file.close
452
+ <span class="keyword">end</span>
453
+
454
+ file = <span class="keyword">nil</span></pre></div></div>
455
+
456
+ </li>
457
+
458
+
459
+ <li id="section-26">
460
+ <div class="annotation">
461
+
462
+ <div class="pilwrap ">
463
+ <a class="pilcrow" href="#section-26">&#182;</a>
464
+ </div>
465
+ <p>get document by file GUID</p>
466
+
467
+ </div>
468
+
469
+ <div class="content"><div class='highlight'><pre> <span class="keyword">case</span> settings.source
470
+ <span class="keyword">when</span> <span class="string">'guid'</span></pre></div></div>
471
+
472
+ </li>
473
+
474
+
475
+ <li id="section-27">
476
+ <div class="annotation">
477
+
478
+ <div class="pilwrap ">
479
+ <a class="pilcrow" href="#section-27">&#182;</a>
480
+ </div>
481
+ <p>Create instance of File</p>
482
+
483
+ </div>
484
+
485
+ <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.new({<span class="symbol">:guid</span> =&gt; settings.fileId}).to_document.metadata!()
486
+ file = file.last_view.document.file.to_document
487
+ <span class="keyword">when</span> <span class="string">'local'</span></pre></div></div>
488
+
489
+ </li>
490
+
491
+
492
+ <li id="section-28">
493
+ <div class="annotation">
494
+
495
+ <div class="pilwrap ">
496
+ <a class="pilcrow" href="#section-28">&#182;</a>
497
+ </div>
498
+ <p>construct path</p>
499
+
500
+ </div>
501
+
502
+ <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>
503
+
504
+ </li>
505
+
506
+
507
+ <li id="section-29">
508
+ <div class="annotation">
509
+
510
+ <div class="pilwrap ">
511
+ <a class="pilcrow" href="#section-29">&#182;</a>
512
+ </div>
513
+ <p>open file</p>
514
+
515
+ </div>
516
+
517
+ <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>
518
+
519
+ </li>
520
+
521
+
522
+ <li id="section-30">
523
+ <div class="annotation">
524
+
525
+ <div class="pilwrap ">
526
+ <a class="pilcrow" href="#section-30">&#182;</a>
527
+ </div>
528
+ <p>make a request to API using client_id and private_key</p>
529
+
530
+ </div>
531
+
532
+ <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.upload!(file_path, {}).to_document
533
+ <span class="keyword">when</span> <span class="string">'url'</span></pre></div></div>
534
+
535
+ </li>
536
+
537
+
538
+ <li id="section-31">
539
+ <div class="annotation">
540
+
541
+ <div class="pilwrap ">
542
+ <a class="pilcrow" href="#section-31">&#182;</a>
543
+ </div>
544
+ <p>Upload file from defined url</p>
545
+
546
+ </div>
547
+
548
+ <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.upload_web!(settings.url).to_document
549
+ <span class="keyword">else</span>
550
+ raise <span class="string">'Wrong GUID source.'</span>
551
+ <span class="keyword">end</span>
552
+
553
+ name = file.name</pre></div></div>
554
+
555
+ </li>
556
+
557
+
558
+ <li id="section-32">
559
+ <div class="annotation">
560
+
561
+ <div class="pilwrap ">
562
+ <a class="pilcrow" href="#section-32">&#182;</a>
563
+ </div>
564
+ <p>create envelope using user id and entered by user name</p>
565
+
566
+ </div>
567
+
568
+ <div class="content"><div class='highlight'><pre> envelope = <span class="constant">GroupDocs::Signature::Envelope</span>.new
569
+ envelope.name = file.name
570
+ envelope.email_subject = <span class="string">'Sing this!'</span>
571
+ envelope.create!({})</pre></div></div>
572
+
573
+ </li>
574
+
575
+
576
+ <li id="section-33">
577
+ <div class="annotation">
578
+
579
+ <div class="pilwrap ">
580
+ <a class="pilcrow" href="#section-33">&#182;</a>
581
+ </div>
582
+ <p>Add uploaded document to envelope</p>
583
+
584
+ </div>
585
+
586
+ <div class="content"><div class='highlight'><pre> envelope.add_document!(file, {})</pre></div></div>
587
+
588
+ </li>
589
+
590
+
591
+ <li id="section-34">
592
+ <div class="annotation">
593
+
594
+ <div class="pilwrap ">
595
+ <a class="pilcrow" href="#section-34">&#182;</a>
596
+ </div>
597
+ <p>Get role list for current user</p>
598
+
599
+ </div>
600
+
601
+ <div class="content"><div class='highlight'><pre> roles = <span class="constant">GroupDocs::Signature::Role</span>.get!({})</pre></div></div>
602
+
603
+ </li>
604
+
605
+
606
+ <li id="section-35">
607
+ <div class="annotation">
608
+
609
+ <div class="pilwrap ">
610
+ <a class="pilcrow" href="#section-35">&#182;</a>
611
+ </div>
612
+ <p>Create new recipient</p>
613
+
614
+ </div>
615
+
616
+ <div class="content"><div class='highlight'><pre> recipient = <span class="constant">GroupDocs::Signature::Recipient</span>.new
617
+ recipient.email = settings.email
618
+ recipient.first_name = settings.name
619
+ recipient.last_name = settings.lastName
620
+ recipient.role_id = roles.detect { |role| role.name == <span class="string">'Signer'</span> }.id</pre></div></div>
621
+
622
+ </li>
623
+
624
+
625
+ <li id="section-36">
626
+ <div class="annotation">
627
+
628
+ <div class="pilwrap ">
629
+ <a class="pilcrow" href="#section-36">&#182;</a>
630
+ </div>
631
+ <p>Add recipient to envelope</p>
632
+
633
+ </div>
634
+
635
+ <div class="content"><div class='highlight'><pre> add = envelope.add_recipient!(recipient)</pre></div></div>
636
+
637
+ </li>
638
+
639
+
640
+ <li id="section-37">
641
+ <div class="annotation">
642
+
643
+ <div class="pilwrap ">
644
+ <a class="pilcrow" href="#section-37">&#182;</a>
645
+ </div>
646
+ <p>Get recipient id</p>
647
+
648
+ </div>
649
+
650
+ <div class="content"><div class='highlight'><pre> recipient.id = add.id</pre></div></div>
651
+
652
+ </li>
653
+
654
+
655
+ <li id="section-38">
656
+ <div class="annotation">
657
+
658
+ <div class="pilwrap ">
659
+ <a class="pilcrow" href="#section-38">&#182;</a>
660
+ </div>
661
+ <p>Get document id</p>
662
+
663
+ </div>
664
+
665
+ <div class="content"><div class='highlight'><pre> document = envelope.documents!</pre></div></div>
666
+
667
+ </li>
668
+
669
+
670
+ <li id="section-39">
671
+ <div class="annotation">
672
+
673
+ <div class="pilwrap ">
674
+ <a class="pilcrow" href="#section-39">&#182;</a>
675
+ </div>
676
+ <p>Get field and add the location to field</p>
677
+
678
+ </div>
679
+
680
+ <div class="content"><div class='highlight'><pre> field = <span class="constant">GroupDocs::Signature::Field</span>.get!.detect { |f| f.type == <span class="symbol">:signature</span> }
681
+ field.location = {<span class="symbol">:location_x</span> =&gt; <span class="number">0</span>.<span class="number">15</span>, <span class="symbol">:location_y</span> =&gt; <span class="number">0</span>.<span class="number">73</span>, <span class="symbol">:location_w</span> =&gt; <span class="number">150</span>, <span class="symbol">:location_h</span> =&gt; <span class="number">50</span>, <span class="symbol">:page</span> =&gt; <span class="number">1</span>}
682
+ field.name = <span class="string">'EMPLOYEE SIGNATURE'</span></pre></div></div>
683
+
684
+ </li>
685
+
686
+
687
+ <li id="section-40">
688
+ <div class="annotation">
689
+
690
+ <div class="pilwrap ">
691
+ <a class="pilcrow" href="#section-40">&#182;</a>
692
+ </div>
693
+ <p>Add field to envelope</p>
694
+
695
+ </div>
696
+
697
+ <div class="content"><div class='highlight'><pre> envelope.add_field!(field, document[<span class="number">0</span>], recipient)</pre></div></div>
698
+
699
+ </li>
700
+
701
+
702
+ <li id="section-41">
703
+ <div class="annotation">
704
+
705
+ <div class="pilwrap ">
706
+ <a class="pilcrow" href="#section-41">&#182;</a>
707
+ </div>
708
+ <p>Send envelop</p>
709
+
710
+ </div>
711
+
712
+ <div class="content"><div class='highlight'><pre> envelope.send!({<span class="symbol">:callbackUrl</span> =&gt; settings.callback})</pre></div></div>
713
+
714
+ </li>
715
+
716
+
717
+ <li id="section-42">
718
+ <div class="annotation">
719
+
720
+ <div class="pilwrap ">
721
+ <a class="pilcrow" href="#section-42">&#182;</a>
722
+ </div>
723
+ <p>Write client and private key to the file for callback job</p>
724
+
725
+ </div>
726
+
727
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.callback
728
+ 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>
729
+
730
+ </li>
731
+
732
+
733
+ <li id="section-43">
734
+ <div class="annotation">
735
+
736
+ <div class="pilwrap ">
737
+ <a class="pilcrow" href="#section-43">&#182;</a>
738
+ </div>
739
+ <p>white space is required</p>
740
+
741
+ </div>
742
+
743
+ <div class="content"><div class='highlight'><pre> out_file.write(<span class="string">"<span class="subst">#{settings.client_id}</span> "</span>)
744
+ out_file.write(<span class="string">"<span class="subst">#{settings.private_key}</span>"</span>)
745
+ out_file.write(<span class="string">"<span class="subst">#{envelope.id}</span>"</span>)
746
+ out_file.close
747
+ <span class="keyword">end</span></pre></div></div>
748
+
749
+ </li>
750
+
751
+
752
+ <li id="section-44">
753
+ <div class="annotation">
754
+
755
+ <div class="pilwrap ">
756
+ <a class="pilcrow" href="#section-44">&#182;</a>
757
+ </div>
758
+ <p>Get url from request</p>
759
+
760
+ </div>
761
+
762
+ <div class="content"><div class='highlight'><pre> <span class="keyword">case</span> settings.base_path
763
+
764
+ <span class="keyword">when</span> <span class="string">'https://stage-api-groupdocs.dynabic.com'</span>
765
+ url = <span class="string">"http://stage-apps-groupdocs.dynabic.com/signature/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipient.id}</span>"</span>
766
+ <span class="keyword">when</span> <span class="string">'https://dev-api-groupdocs.dynabic.com'</span>
767
+ url = <span class="string">"http://dev-apps-groupdocs.dynabic.com/signature/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipient.id}</span>"</span>
768
+ <span class="keyword">else</span>
769
+ url = <span class="string">"https://apps.groupdocs.com/signature/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipient.id}</span>"</span>
770
+ <span class="keyword">end</span>
771
+
772
+
773
+ iframe = <span class="constant">GroupDocs::Api::Request</span>.new(<span class="symbol">:path</span> =&gt; url).prepare_and_sign_url</pre></div></div>
774
+
775
+ </li>
776
+
777
+
778
+ <li id="section-45">
779
+ <div class="annotation">
780
+
781
+ <div class="pilwrap ">
782
+ <a class="pilcrow" href="#section-45">&#182;</a>
783
+ </div>
784
+ <p>Make iframe</p>
785
+
786
+ </div>
787
+
788
+ <div class="content"><div class='highlight'><pre> iframe = <span class="string">"&lt;iframe src='<span class="subst">#{iframe}</span>' frameborder='0' width='720' height='600'&gt;&lt;/iframe&gt;"</span>
789
+ message = <span class="string">"&lt;p&gt;File was uploaded to GroupDocs. Here you can see your &lt;strong&gt;<span class="subst">#{name}</span>&lt;/strong&gt; file in the GroupDocs Embedded Viewer.&lt;/p&gt;"</span>
790
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
791
+ err = e.message
792
+ <span class="keyword">end</span></pre></div></div>
793
+
794
+ </li>
795
+
796
+
797
+ <li id="section-46">
798
+ <div class="annotation">
799
+
800
+ <div class="pilwrap ">
801
+ <a class="pilcrow" href="#section-46">&#182;</a>
802
+ </div>
803
+ <p>Set variables for template</p>
804
+
805
+ </div>
806
+
807
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample37</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">:email</span> =&gt; settings.email, <span class="symbol">:name</span> =&gt; settings.name, <span class="symbol">:lastName</span> =&gt; settings.lastName, <span class="symbol">:iframe</span> =&gt; iframe, <span class="symbol">:massage</span> =&gt; message, <span class="symbol">:err</span> =&gt; err, <span class="symbol">:callback</span> =&gt; settings.callback,}
808
+ <span class="keyword">end</span></pre></div></div>
809
+
810
+ </li>
811
+
812
+ </ul>
813
+ </div>
814
+ </body>
815
+ </html>