groupdocs 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDQxMzhjNGEyYjliMTRmNDdhMDBkN2ZiODg4MGYwZDYxNTkxMzJmMw==
5
+ data.tar.gz: !binary |-
6
+ ODVkNmY0ODYwMTIzMWEyNzM1ZjFlNTQ2MDA0YjZhMzkyMTgwZmM3ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NjEzYzQ5YjAwMmEzNDgwMmQ0NmRlNzAwNDU0NTk5MDRlOGRiMzM1NWIxMmRk
10
+ NDk1NDE3ZGNmMmYzNTM3MWNiOTMzMDkzMmZlY2JkM2MzNzU3ZDMxMmVhODEw
11
+ OGVlMjE2MzM2NjdjNjBkNWNkYWZmM2E3ZjhjYmJhYjQ2NmFkMjg=
12
+ data.tar.gz: !binary |-
13
+ MjBmMTU5MTU1YjE4YjMwMzZlZGU4NjQzMzY4MDBlMzQyMWQxNTU0YmJiMzJi
14
+ N2UwNWJmM2Q3NDI0ZTE1MWM5ZGU5NDFmMGM0YTdjMDUxZjM2MWJiMjE4ZTkw
15
+ ZmJhYjFmODkxMDBiZTI3YTk1OTQ2OGExYThhOWMwMDFhNTdkYjY=
@@ -0,0 +1,519 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sample32.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>sample32.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">'/sample32'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample32</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">'/sample32/callback'</span> <span class="keyword">do</span>
52
+
53
+ source_id = <span class="string">''</span>
54
+ client_id = <span class="string">''</span>
55
+ private_key = <span class="string">''</span>
56
+ subscriber_email = <span class="string">''</span></pre></div></div>
57
+
58
+ </li>
59
+
60
+
61
+ <li id="section-3">
62
+ <div class="annotation">
63
+
64
+ <div class="pilwrap ">
65
+ <a class="pilcrow" href="#section-3">&#182;</a>
66
+ </div>
67
+ <p>Get callback request</p>
68
+
69
+ </div>
70
+
71
+ <div class="content"><div class='highlight'><pre> data = <span class="constant">JSON</span>.parse(request.body.read)
72
+ <span class="keyword">begin</span>
73
+ raise <span class="string">'Empty params!'</span> <span class="keyword">if</span> data.empty?</pre></div></div>
74
+
75
+ </li>
76
+
77
+
78
+ <li id="section-4">
79
+ <div class="annotation">
80
+
81
+ <div class="pilwrap ">
82
+ <a class="pilcrow" href="#section-4">&#182;</a>
83
+ </div>
84
+ <p>Get value of SourceId</p>
85
+
86
+ </div>
87
+
88
+ <div class="content"><div class='highlight'><pre> data.each <span class="keyword">do</span> |key, value|
89
+ <span class="keyword">if</span> key == <span class="string">'SourceId'</span>
90
+ source_id = value
91
+ <span class="keyword">end</span>
92
+ <span class="keyword">end</span></pre></div></div>
93
+
94
+ </li>
95
+
96
+
97
+ <li id="section-5">
98
+ <div class="annotation">
99
+
100
+ <div class="pilwrap ">
101
+ <a class="pilcrow" href="#section-5">&#182;</a>
102
+ </div>
103
+ <p>Get private key and client_id from file user_info.txt</p>
104
+
105
+ </div>
106
+
107
+ <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>)
108
+ 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>)
109
+ contents = contents.split(<span class="string">' '</span>)
110
+ client_id = contents[<span class="number">0</span>]
111
+ private_key = contents[<span class="number">1</span>]
112
+ subscriber_email = contens[<span class="number">2</span>]
113
+ <span class="keyword">end</span></pre></div></div>
114
+
115
+ </li>
116
+
117
+
118
+ <li id="section-6">
119
+ <div class="annotation">
120
+
121
+ <div class="pilwrap ">
122
+ <a class="pilcrow" href="#section-6">&#182;</a>
123
+ </div>
124
+ <p>Create new Form</p>
125
+
126
+ </div>
127
+
128
+ <div class="content"><div class='highlight'><pre> form = <span class="constant">GroupDocs::Signature::Form</span>.new({<span class="symbol">:id</span> =&gt; source_id})</pre></div></div>
129
+
130
+ </li>
131
+
132
+
133
+ <li id="section-7">
134
+ <div class="annotation">
135
+
136
+ <div class="pilwrap ">
137
+ <a class="pilcrow" href="#section-7">&#182;</a>
138
+ </div>
139
+ <p>Get document by Form id</p>
140
+
141
+ </div>
142
+
143
+ <div class="content"><div class='highlight'><pre> document = form.documents!({}, {<span class="symbol">:client_id</span> =&gt; client_id, <span class="symbol">:private_key</span> =&gt; private_key})</pre></div></div>
144
+
145
+ </li>
146
+
147
+
148
+ <li id="section-8">
149
+ <div class="annotation">
150
+
151
+ <div class="pilwrap ">
152
+ <a class="pilcrow" href="#section-8">&#182;</a>
153
+ </div>
154
+ <p>An adress recipient</p>
155
+
156
+ </div>
157
+
158
+ <div class="content"><div class='highlight'><pre> to = subscriber_email</pre></div></div>
159
+
160
+ </li>
161
+
162
+
163
+ <li id="section-9">
164
+ <div class="annotation">
165
+
166
+ <div class="pilwrap ">
167
+ <a class="pilcrow" href="#section-9">&#182;</a>
168
+ </div>
169
+ <p>The Body message</p>
170
+
171
+ </div>
172
+
173
+ <div class="content"><div class='highlight'><pre> body = <span class="string">"
174
+ &lt;html&gt;
175
+ &lt;head&gt;
176
+ &lt;title&gt;Sign form notification&lt;/title&gt;
177
+ &lt;/head&gt;
178
+ &lt;body&gt;
179
+ &lt;p&gt;Document <span class="subst">#{document.name}</span> is signed&lt;/p&gt;
180
+ &lt;/body&gt;
181
+ &lt;/html&gt;"</span></pre></div></div>
182
+
183
+ </li>
184
+
185
+
186
+ <li id="section-10">
187
+ <div class="annotation">
188
+
189
+ <div class="pilwrap ">
190
+ <a class="pilcrow" href="#section-10">&#182;</a>
191
+ </div>
192
+ <p>A method send the mail</p>
193
+
194
+ </div>
195
+
196
+ <div class="content"><div class='highlight'><pre> <span class="function"><span class="keyword">def</span> <span class="title">send_mail</span><span class="params">(to, body)</span></span></pre></div></div>
197
+
198
+ </li>
199
+
200
+
201
+ <li id="section-11">
202
+ <div class="annotation">
203
+
204
+ <div class="pilwrap ">
205
+ <a class="pilcrow" href="#section-11">&#182;</a>
206
+ </div>
207
+ <p>implement your send mail function with your SMTP server</p>
208
+
209
+ </div>
210
+
211
+ <div class="content"><div class='highlight'><pre> <span class="keyword">return</span> <span class="keyword">true</span>
212
+ <span class="keyword">end</span>
213
+
214
+ send_mail(to, body) <span class="comment">#send notification mail</span>
215
+
216
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
217
+ err = e.message
218
+ <span class="keyword">end</span>
219
+ <span class="keyword">end</span></pre></div></div>
220
+
221
+ </li>
222
+
223
+
224
+ <li id="section-12">
225
+ <div class="annotation">
226
+
227
+ <div class="pilwrap ">
228
+ <a class="pilcrow" href="#section-12">&#182;</a>
229
+ </div>
230
+ <p>GET request</p>
231
+
232
+ </div>
233
+
234
+ <div class="content"><div class='highlight'><pre>get <span class="string">'/sample32/check'</span> <span class="keyword">do</span></pre></div></div>
235
+
236
+ </li>
237
+
238
+
239
+ <li id="section-13">
240
+ <div class="annotation">
241
+
242
+ <div class="pilwrap ">
243
+ <a class="pilcrow" href="#section-13">&#182;</a>
244
+ </div>
245
+ <p>Check is there download directory</p>
246
+
247
+ </div>
248
+
249
+ <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>)
250
+ <span class="keyword">return</span> <span class="string">'Directory was not found.'</span>
251
+ <span class="keyword">end</span></pre></div></div>
252
+
253
+ </li>
254
+
255
+
256
+ <li id="section-14">
257
+ <div class="annotation">
258
+
259
+ <div class="pilwrap ">
260
+ <a class="pilcrow" href="#section-14">&#182;</a>
261
+ </div>
262
+ <p>Get file name from download directory</p>
263
+
264
+ </div>
265
+
266
+ <div class="content"><div class='highlight'><pre> name = <span class="keyword">nil</span>
267
+ <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|
268
+ name = file <span class="keyword">if</span> file != <span class="string">'.'</span> &amp;&amp; file != <span class="string">'..'</span>
269
+ <span class="keyword">end</span>
270
+
271
+ name
272
+ <span class="keyword">end</span></pre></div></div>
273
+
274
+ </li>
275
+
276
+
277
+ <li id="section-15">
278
+ <div class="annotation">
279
+
280
+ <div class="pilwrap ">
281
+ <a class="pilcrow" href="#section-15">&#182;</a>
282
+ </div>
283
+ <p>POST request</p>
284
+
285
+ </div>
286
+
287
+ <div class="content"><div class='highlight'><pre>post <span class="string">'/sample32'</span> <span class="keyword">do</span></pre></div></div>
288
+
289
+ </li>
290
+
291
+
292
+ <li id="section-16">
293
+ <div class="annotation">
294
+
295
+ <div class="pilwrap ">
296
+ <a class="pilcrow" href="#section-16">&#182;</a>
297
+ </div>
298
+ <p>set variables</p>
299
+
300
+ </div>
301
+
302
+ <div class="content"><div class='highlight'><pre> set <span class="symbol">:client_id</span>, params[<span class="symbol">:client_id</span>]
303
+ set <span class="symbol">:private_key</span>, params[<span class="symbol">:private_key</span>]
304
+ set <span class="symbol">:template_guid</span>, params[<span class="symbol">:template</span>]
305
+ set <span class="symbol">:form_guid</span>, params[<span class="symbol">:form</span>]
306
+ set <span class="symbol">:email</span>, params[<span class="symbol">:email</span>]
307
+ set <span class="symbol">:callback</span>, params[<span class="symbol">:callback</span>]
308
+ set <span class="symbol">:source</span>, params[<span class="symbol">:source</span>]</pre></div></div>
309
+
310
+ </li>
311
+
312
+
313
+ <li id="section-17">
314
+ <div class="annotation">
315
+
316
+ <div class="pilwrap ">
317
+ <a class="pilcrow" href="#section-17">&#182;</a>
318
+ </div>
319
+ <p>Set download path</p>
320
+
321
+ </div>
322
+
323
+ <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>
324
+
325
+ </li>
326
+
327
+
328
+ <li id="section-18">
329
+ <div class="annotation">
330
+
331
+ <div class="pilwrap ">
332
+ <a class="pilcrow" href="#section-18">&#182;</a>
333
+ </div>
334
+ <p>Remove all files from download directory or create folder if it not there</p>
335
+
336
+ </div>
337
+
338
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> <span class="constant">File</span>.directory?(downloads_path)
339
+ <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> }
340
+ <span class="keyword">else</span>
341
+ <span class="constant">Dir::</span>mkdir(downloads_path)
342
+ <span class="keyword">end</span>
343
+
344
+ <span class="keyword">begin</span></pre></div></div>
345
+
346
+ </li>
347
+
348
+
349
+ <li id="section-19">
350
+ <div class="annotation">
351
+
352
+ <div class="pilwrap ">
353
+ <a class="pilcrow" href="#section-19">&#182;</a>
354
+ </div>
355
+ <p>Check required variables</p>
356
+
357
+ </div>
358
+
359
+ <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>
360
+
361
+ </li>
362
+
363
+
364
+ <li id="section-20">
365
+ <div class="annotation">
366
+
367
+ <div class="pilwrap ">
368
+ <a class="pilcrow" href="#section-20">&#182;</a>
369
+ </div>
370
+ <p>Configure your access to API server.</p>
371
+
372
+ </div>
373
+
374
+ <div class="content"><div class='highlight'><pre> <span class="constant">GroupDocs</span>.configure <span class="keyword">do</span> |groupdocs|
375
+ groupdocs.client_id = settings.client_id
376
+ groupdocs.private_key = settings.private_key
377
+ <span class="keyword">end</span></pre></div></div>
378
+
379
+ </li>
380
+
381
+
382
+ <li id="section-21">
383
+ <div class="annotation">
384
+
385
+ <div class="pilwrap ">
386
+ <a class="pilcrow" href="#section-21">&#182;</a>
387
+ </div>
388
+ <p>Write client and private key to the file for callback job</p>
389
+
390
+ </div>
391
+
392
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> settings.callback[<span class="number">0</span>]
393
+ 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>
394
+
395
+ </li>
396
+
397
+
398
+ <li id="section-22">
399
+ <div class="annotation">
400
+
401
+ <div class="pilwrap ">
402
+ <a class="pilcrow" href="#section-22">&#182;</a>
403
+ </div>
404
+ <p>white space is required</p>
405
+
406
+ </div>
407
+
408
+ <div class="content"><div class='highlight'><pre> out_file.write(<span class="string">"<span class="subst">#{settings.client_id}</span> "</span>)
409
+ out_file.write(<span class="string">"<span class="subst">#{settings.private_key}</span>"</span>)
410
+ out_file.write(<span class="string">"<span class="subst">#{settings.email}</span>"</span>)
411
+ out_file.close
412
+ <span class="keyword">end</span>
413
+
414
+ iframe = <span class="string">''</span>
415
+
416
+ <span class="keyword">case</span> settings.source
417
+ <span class="keyword">when</span> <span class="string">'form'</span></pre></div></div>
418
+
419
+ </li>
420
+
421
+
422
+ <li id="section-23">
423
+ <div class="annotation">
424
+
425
+ <div class="pilwrap ">
426
+ <a class="pilcrow" href="#section-23">&#182;</a>
427
+ </div>
428
+ <p>Create new Form with guid</p>
429
+
430
+ </div>
431
+
432
+ <div class="content"><div class='highlight'><pre> form = <span class="constant">GroupDocs::Signature::Form</span>.new({<span class="symbol">:guid</span> =&gt; settings.form_guid})</pre></div></div>
433
+
434
+ </li>
435
+
436
+
437
+ <li id="section-24">
438
+ <div class="annotation">
439
+
440
+ <div class="pilwrap ">
441
+ <a class="pilcrow" href="#section-24">&#182;</a>
442
+ </div>
443
+ <p>Publish the Form</p>
444
+
445
+ </div>
446
+
447
+ <div class="content"><div class='highlight'><pre> form.publish!({<span class="symbol">:callbackUrl</span> =&gt; settings.callback})
448
+
449
+ iframe = <span class="string">"https://apps.groupdocs.com/signature2/forms/signembed/ <span class="subst">#{settings.form_guid}</span>"</span>;
450
+ <span class="keyword">when</span> <span class="string">'template'</span>
451
+
452
+ form = <span class="constant">GroupDocs::Signature::Form</span>.new
453
+ form.name = <span class="string">'test'</span>
454
+ form.notifyOwnerOnSign = <span class="keyword">true</span></pre></div></div>
455
+
456
+ </li>
457
+
458
+
459
+ <li id="section-25">
460
+ <div class="annotation">
461
+
462
+ <div class="pilwrap ">
463
+ <a class="pilcrow" href="#section-25">&#182;</a>
464
+ </div>
465
+ <p>Create new Form with template</p>
466
+
467
+ </div>
468
+
469
+ <div class="content"><div class='highlight'><pre> signature = form.create!({ <span class="symbol">:templateId</span> =&gt; settings.template_guid})</pre></div></div>
470
+
471
+ </li>
472
+
473
+
474
+ <li id="section-26">
475
+ <div class="annotation">
476
+
477
+ <div class="pilwrap ">
478
+ <a class="pilcrow" href="#section-26">&#182;</a>
479
+ </div>
480
+ <p>Publish the Form</p>
481
+
482
+ </div>
483
+
484
+ <div class="content"><div class='highlight'><pre> form.publish!({<span class="symbol">:callbackUrl</span> =&gt; settings.callback})
485
+
486
+ iframe = <span class="string">"&lt;iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/signature2/forms/signembed/ <span class="subst">#{signature}</span>'&gt;&lt;/iframe&gt;"</span>
487
+ <span class="keyword">end</span>
488
+
489
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
490
+ err = e.message
491
+ <span class="keyword">end</span></pre></div></div>
492
+
493
+ </li>
494
+
495
+
496
+ <li id="section-27">
497
+ <div class="annotation">
498
+
499
+ <div class="pilwrap ">
500
+ <a class="pilcrow" href="#section-27">&#182;</a>
501
+ </div>
502
+ <p>Set variables for template</p>
503
+
504
+ </div>
505
+
506
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample32</span>, <span class="symbol">:locals</span> =&gt; {<span class="symbol">:userId</span> =&gt; settings.client_id,
507
+ <span class="symbol">:privateKey</span> =&gt; settings.private_key,
508
+ <span class="symbol">:callback</span> =&gt; settings.callback,
509
+ <span class="symbol">:email</span> =&gt; settings.email,
510
+ <span class="symbol">:iframe</span> =&gt; iframe,
511
+ <span class="symbol">:err</span> =&gt; err}
512
+ <span class="keyword">end</span></pre></div></div>
513
+
514
+ </li>
515
+
516
+ </ul>
517
+ </div>
518
+ </body>
519
+ </html>