groupdocs 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,144 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sample30.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>sample30.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">'/sample30'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample30</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">'/sample30'</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 variables</p>
63
+
64
+ </div>
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
+ set <span class="symbol">:file_id</span>, params[<span class="symbol">:fileId</span>]
69
+
70
+ <span class="keyword">begin</span></pre></div></div>
71
+
72
+ </li>
73
+
74
+
75
+ <li id="section-4">
76
+ <div class="annotation">
77
+
78
+ <div class="pilwrap ">
79
+ <a class="pilcrow" href="#section-4">&#182;</a>
80
+ </div>
81
+ <p>check required variables</p>
82
+
83
+ </div>
84
+
85
+ <div class="content"><div class='highlight'><pre> raise <span class="string">'Please enter all required parameters'</span> <span class="keyword">if</span> settings.client_id.empty? <span class="keyword">or</span> settings.private_key.empty? <span class="keyword">or</span> settings.file_id.empty?</pre></div></div>
86
+
87
+ </li>
88
+
89
+
90
+ <li id="section-5">
91
+ <div class="annotation">
92
+
93
+ <div class="pilwrap ">
94
+ <a class="pilcrow" href="#section-5">&#182;</a>
95
+ </div>
96
+ <p>make a request to API using client_id and private_key</p>
97
+
98
+ </div>
99
+
100
+ <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})</pre></div></div>
101
+
102
+ </li>
103
+
104
+
105
+ <li id="section-6">
106
+ <div class="annotation">
107
+
108
+ <div class="pilwrap ">
109
+ <a class="pilcrow" href="#section-6">&#182;</a>
110
+ </div>
111
+ <p>delete file from GroupDocs Storage</p>
112
+
113
+ </div>
114
+
115
+ <div class="content"><div class='highlight'><pre> result = file.delete!({<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})
116
+
117
+ message = <span class="string">'File was deleted from GroupDocs Storage'</span>
118
+
119
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
120
+ err = e.message
121
+ <span class="keyword">end</span></pre></div></div>
122
+
123
+ </li>
124
+
125
+
126
+ <li id="section-7">
127
+ <div class="annotation">
128
+
129
+ <div class="pilwrap ">
130
+ <a class="pilcrow" href="#section-7">&#182;</a>
131
+ </div>
132
+ <p>set variables for template</p>
133
+
134
+ </div>
135
+
136
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample30</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">:message</span> =&gt; message, <span class="symbol">:fileId</span> =&gt; settings.file_id, <span class="symbol">:err</span> =&gt; err}
137
+ <span class="keyword">end</span></pre></div></div>
138
+
139
+ </li>
140
+
141
+ </ul>
142
+ </div>
143
+ </body>
144
+ </html>
@@ -0,0 +1,734 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sample31.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>sample31.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">'/sample31'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample31</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">'/sample31/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">'/sample31/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">'/sample31/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">'/sample31'</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">:template_guid</span>, params[<span class="symbol">:template_guid</span>]
292
+ set <span class="symbol">:name</span>, params[<span class="symbol">:name</span>]
293
+ set <span class="symbol">:country</span>, params[<span class="symbol">:country</span>]
294
+ set <span class="symbol">:city</span>, params[<span class="symbol">:city</span>]
295
+ set <span class="symbol">:street</span>, params[<span class="symbol">:street</span>]
296
+ set <span class="symbol">:email</span>, params[<span class="symbol">:email</span>]
297
+ set <span class="symbol">:callback</span>, params[<span class="symbol">:callback</span>]
298
+ set <span class="symbol">:last_name</span>, params[<span class="symbol">:last_name</span>]</pre></div></div>
299
+
300
+ </li>
301
+
302
+
303
+ <li id="section-17">
304
+ <div class="annotation">
305
+
306
+ <div class="pilwrap ">
307
+ <a class="pilcrow" href="#section-17">&#182;</a>
308
+ </div>
309
+ <p>Set download path</p>
310
+
311
+ </div>
312
+
313
+ <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>
314
+
315
+ </li>
316
+
317
+
318
+ <li id="section-18">
319
+ <div class="annotation">
320
+
321
+ <div class="pilwrap ">
322
+ <a class="pilcrow" href="#section-18">&#182;</a>
323
+ </div>
324
+ <p>Remove all files from download directory or create folder if it not there</p>
325
+
326
+ </div>
327
+
328
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="constant">File</span>.directory?(downloads_path)
329
+ <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> }
330
+ <span class="keyword">else</span>
331
+ <span class="constant">Dir::</span>mkdir(downloads_path)
332
+ <span class="keyword">end</span>
333
+
334
+ <span class="keyword">begin</span></pre></div></div>
335
+
336
+ </li>
337
+
338
+
339
+ <li id="section-19">
340
+ <div class="annotation">
341
+
342
+ <div class="pilwrap ">
343
+ <a class="pilcrow" href="#section-19">&#182;</a>
344
+ </div>
345
+ <p>check required variables</p>
346
+
347
+ </div>
348
+
349
+ <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>
350
+
351
+ </li>
352
+
353
+
354
+ <li id="section-20">
355
+ <div class="annotation">
356
+
357
+ <div class="pilwrap ">
358
+ <a class="pilcrow" href="#section-20">&#182;</a>
359
+ </div>
360
+ <p>Write client and private key to the file for callback job</p>
361
+
362
+ </div>
363
+
364
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.callback[<span class="number">0</span>]
365
+ 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>
366
+
367
+ </li>
368
+
369
+
370
+ <li id="section-21">
371
+ <div class="annotation">
372
+
373
+ <div class="pilwrap ">
374
+ <a class="pilcrow" href="#section-21">&#182;</a>
375
+ </div>
376
+ <p>white space is required</p>
377
+
378
+ </div>
379
+
380
+ <div class="content"><div class='highlight'><pre> out_file.write(<span class="string">"<span class="subst">#{settings.client_id}</span> "</span>)
381
+ out_file.write(<span class="string">"<span class="subst">#{settings.private_key}</span>"</span>)
382
+ out_file.close
383
+ <span class="keyword">end</span>
384
+
385
+ file = <span class="keyword">nil</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>Create instance of File</p>
397
+
398
+ </div>
399
+
400
+ <div class="content"><div class='highlight'><pre> file = <span class="constant">GroupDocs::Storage::File</span>.new({<span class="symbol">:guid</span> =&gt; settings.template_guid})</pre></div></div>
401
+
402
+ </li>
403
+
404
+
405
+ <li id="section-23">
406
+ <div class="annotation">
407
+
408
+ <div class="pilwrap ">
409
+ <a class="pilcrow" href="#section-23">&#182;</a>
410
+ </div>
411
+ <p>Raise exception if something went wrong</p>
412
+
413
+ </div>
414
+
415
+ <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>
416
+
417
+ </li>
418
+
419
+
420
+ <li id="section-24">
421
+ <div class="annotation">
422
+
423
+ <div class="pilwrap ">
424
+ <a class="pilcrow" href="#section-24">&#182;</a>
425
+ </div>
426
+ <p>Make GroupDocs::Storage::Document instance</p>
427
+
428
+ </div>
429
+
430
+ <div class="content"><div class='highlight'><pre> document = file.to_document</pre></div></div>
431
+
432
+ </li>
433
+
434
+
435
+ <li id="section-25">
436
+ <div class="annotation">
437
+
438
+ <div class="pilwrap ">
439
+ <a class="pilcrow" href="#section-25">&#182;</a>
440
+ </div>
441
+ <p>Create datasource with fields</p>
442
+
443
+ </div>
444
+
445
+ <div class="content"><div class='highlight'><pre> datasource = <span class="constant">GroupDocs::DataSource</span>.new</pre></div></div>
446
+
447
+ </li>
448
+
449
+
450
+ <li id="section-26">
451
+ <div class="annotation">
452
+
453
+ <div class="pilwrap ">
454
+ <a class="pilcrow" href="#section-26">&#182;</a>
455
+ </div>
456
+ <p>Get arry of document&#39;s fields</p>
457
+
458
+ </div>
459
+
460
+ <div class="content"><div class='highlight'><pre> enteredData = {<span class="string">"email"</span> =&gt; settings.email, <span class="string">"name"</span> =&gt; settings.name, <span class="string">"last_name"</span> =&gt; settings.last_name, <span class="string">"country"</span>=&gt; settings.country, <span class="string">"city"</span> =&gt; settings.city, <span class="string">"street"</span> =&gt; settings.street}</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>Create Field instance and fill the fields</p>
472
+
473
+ </div>
474
+
475
+ <div class="content"><div class='highlight'><pre> datasource.fields = enteredData.map { |key, value| <span class="constant">GroupDocs::DataSource::Field</span>.new(<span class="symbol">name:</span> key, <span class="symbol">type:</span> <span class="symbol">:text</span>, <span class="symbol">values:</span> <span class="constant">Array</span>.new() &lt;&lt; value) }</pre></div></div>
476
+
477
+ </li>
478
+
479
+
480
+ <li id="section-28">
481
+ <div class="annotation">
482
+
483
+ <div class="pilwrap ">
484
+ <a class="pilcrow" href="#section-28">&#182;</a>
485
+ </div>
486
+ <p>Adds datasource.</p>
487
+
488
+ </div>
489
+
490
+ <div class="content"><div class='highlight'><pre> datasource.add!({<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})</pre></div></div>
491
+
492
+ </li>
493
+
494
+
495
+ <li id="section-29">
496
+ <div class="annotation">
497
+
498
+ <div class="pilwrap ">
499
+ <a class="pilcrow" href="#section-29">&#182;</a>
500
+ </div>
501
+ <p>Creates new job to merge datasource into document.</p>
502
+
503
+ </div>
504
+
505
+ <div class="content"><div class='highlight'><pre> job = document.datasource!(datasource, {<span class="symbol">:new_type</span> =&gt; <span class="string">"pdf"</span>}, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})
506
+ sleep <span class="number">10</span> <span class="comment"># wait for merge and convert</span></pre></div></div>
507
+
508
+ </li>
509
+
510
+
511
+ <li id="section-30">
512
+ <div class="annotation">
513
+
514
+ <div class="pilwrap ">
515
+ <a class="pilcrow" href="#section-30">&#182;</a>
516
+ </div>
517
+ <p>Returns an hash of input and output documents associated to job.</p>
518
+
519
+ </div>
520
+
521
+ <div class="content"><div class='highlight'><pre> jobInfo = job.documents!({<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})</pre></div></div>
522
+
523
+ </li>
524
+
525
+
526
+ <li id="section-31">
527
+ <div class="annotation">
528
+
529
+ <div class="pilwrap ">
530
+ <a class="pilcrow" href="#section-31">&#182;</a>
531
+ </div>
532
+ <p>Create envelope using user id and entered by user name</p>
533
+
534
+ </div>
535
+
536
+ <div class="content"><div class='highlight'><pre> envelope = <span class="constant">GroupDocs::Signature::Envelope</span>.new
537
+ envelope.name = jobInfo[<span class="symbol">:inputs</span>][<span class="number">0</span>].outputs[<span class="number">0</span>].name
538
+ envelope.create!({}, {<span class="symbol">:client_id</span> =&gt; settings.client_id, <span class="symbol">:private_key</span> =&gt; settings.private_key})</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>Add uploaded document to envelope</p>
550
+
551
+ </div>
552
+
553
+ <div class="content"><div class='highlight'><pre> envelope.add_document!(document, {}, {<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 role list for current user</p>
565
+
566
+ </div>
567
+
568
+ <div class="content"><div class='highlight'><pre> roles = <span class="constant">GroupDocs::Signature::Role</span>.get!({}, {<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key})</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>Create new recipient</p>
580
+
581
+ </div>
582
+
583
+ <div class="content"><div class='highlight'><pre> recipient = <span class="constant">GroupDocs::Signature::Recipient</span>.new
584
+ recipient.email = <span class="string">'test@test.com'</span>
585
+ recipient.first_name = <span class="string">'test'</span>
586
+ recipient.last_name = <span class="string">'test'</span>
587
+ recipient.role_id = roles.detect { |role| role.name == <span class="string">'Signer'</span> }.id</pre></div></div>
588
+
589
+ </li>
590
+
591
+
592
+ <li id="section-35">
593
+ <div class="annotation">
594
+
595
+ <div class="pilwrap ">
596
+ <a class="pilcrow" href="#section-35">&#182;</a>
597
+ </div>
598
+ <p>Add recipient to envelope</p>
599
+
600
+ </div>
601
+
602
+ <div class="content"><div class='highlight'><pre> envelope.add_recipient!(recipient, {<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key})</pre></div></div>
603
+
604
+ </li>
605
+
606
+
607
+ <li id="section-36">
608
+ <div class="annotation">
609
+
610
+ <div class="pilwrap ">
611
+ <a class="pilcrow" href="#section-36">&#182;</a>
612
+ </div>
613
+ <p>Get field</p>
614
+
615
+ </div>
616
+
617
+ <div class="content"><div class='highlight'><pre> fieldGet = <span class="constant">GroupDocs::Signature::Field</span>.get!({},{<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key}).detect { |f| f.type == <span class="symbol">:signature</span> }
618
+ fieldGet.location = { <span class="symbol">location_x:</span> <span class="number">0</span>.<span class="number">15</span>,
619
+ <span class="symbol">location_y:</span> <span class="number">0</span>.<span class="number">73</span>,
620
+ <span class="symbol">location_width:</span> <span class="number">150</span>,
621
+ <span class="symbol">location_height:</span> <span class="number">50</span>,
622
+ <span class="symbol">page:</span> <span class="number">1</span> }</pre></div></div>
623
+
624
+ </li>
625
+
626
+
627
+ <li id="section-37">
628
+ <div class="annotation">
629
+
630
+ <div class="pilwrap ">
631
+ <a class="pilcrow" href="#section-37">&#182;</a>
632
+ </div>
633
+ <p>Get document</p>
634
+
635
+ </div>
636
+
637
+ <div class="content"><div class='highlight'><pre> documentGet = envelope.documents!({}, {<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key}).first</pre></div></div>
638
+
639
+ </li>
640
+
641
+
642
+ <li id="section-38">
643
+ <div class="annotation">
644
+
645
+ <div class="pilwrap ">
646
+ <a class="pilcrow" href="#section-38">&#182;</a>
647
+ </div>
648
+ <p>Get recipients</p>
649
+
650
+ </div>
651
+
652
+ <div class="content"><div class='highlight'><pre> recipientGet = envelope.recipients!({},{<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key}).first</pre></div></div>
653
+
654
+ </li>
655
+
656
+
657
+ <li id="section-39">
658
+ <div class="annotation">
659
+
660
+ <div class="pilwrap ">
661
+ <a class="pilcrow" href="#section-39">&#182;</a>
662
+ </div>
663
+ <p>Add field to envelope</p>
664
+
665
+ </div>
666
+
667
+ <div class="content"><div class='highlight'><pre> addField = envelope.add_field!(fieldGet, documentGet, recipientGet, {}, {<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key})</pre></div></div>
668
+
669
+ </li>
670
+
671
+
672
+ <li id="section-40">
673
+ <div class="annotation">
674
+
675
+ <div class="pilwrap ">
676
+ <a class="pilcrow" href="#section-40">&#182;</a>
677
+ </div>
678
+ <p>Send envelope</p>
679
+
680
+ </div>
681
+
682
+ <div class="content"><div class='highlight'><pre> envelope.send!(settings.callback, {<span class="symbol">client_id:</span> settings.client_id, <span class="symbol">private_key:</span> settings.private_key})</pre></div></div>
683
+
684
+ </li>
685
+
686
+
687
+ <li id="section-41">
688
+ <div class="annotation">
689
+
690
+ <div class="pilwrap ">
691
+ <a class="pilcrow" href="#section-41">&#182;</a>
692
+ </div>
693
+ <p>Make iframe</p>
694
+
695
+ </div>
696
+
697
+ <div class="content"><div class='highlight'><pre> iframe = <span class="string">"&lt;iframe src='https://apps.groupdocs.com/signature/signembed/<span class="subst">#{envelope.id}</span>/<span class="subst">#{recipientGet.id}</span>' frameborder='0' width='720' height='600'&gt;&lt;/iframe&gt;"</span>
698
+
699
+
700
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
701
+ err = e.message
702
+ <span class="keyword">end</span></pre></div></div>
703
+
704
+ </li>
705
+
706
+
707
+ <li id="section-42">
708
+ <div class="annotation">
709
+
710
+ <div class="pilwrap ">
711
+ <a class="pilcrow" href="#section-42">&#182;</a>
712
+ </div>
713
+ <p>set variables for template</p>
714
+
715
+ </div>
716
+
717
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample31</span>, <span class="symbol">:locals</span> =&gt; {<span class="symbol">:userId</span> =&gt; settings.client_id,
718
+ <span class="symbol">:privateKey</span> =&gt; settings.private_key,
719
+ <span class="symbol">:callback</span> =&gt; settings.callback,
720
+ <span class="symbol">:email</span> =&gt; settings.email,
721
+ <span class="symbol">:name</span> =&gt; settings.name,
722
+ <span class="symbol">:country</span> =&gt; settings.country,
723
+ <span class="symbol">:city</span> =&gt; settings.city,
724
+ <span class="symbol">:street</span> =&gt; settings.street,
725
+ <span class="symbol">:iframe</span> =&gt; iframe,
726
+ <span class="symbol">:err</span> =&gt; err}
727
+ <span class="keyword">end</span></pre></div></div>
728
+
729
+ </li>
730
+
731
+ </ul>
732
+ </div>
733
+ </body>
734
+ </html>