groupdocs 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,235 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <title>sample33.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>sample33.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">'/sample33'</span> <span class="keyword">do</span>
35
+ haml <span class="symbol">:sample33</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">'/sample33'</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">:url_1</span>, params[<span class="symbol">:url_1</span>]
69
+ set <span class="symbol">:url_2</span>, params[<span class="symbol">:url_2</span>]
70
+ set <span class="symbol">:url_3</span>, params[<span class="symbol">:url_3</span>]
71
+ set <span class="symbol">:url_4</span>, params[<span class="symbol">:url_4</span>]
72
+ set <span class="symbol">:url_5</span>, params[<span class="symbol">:url_5</span>]
73
+
74
+ <span class="keyword">begin</span></pre></div></div>
75
+
76
+ </li>
77
+
78
+
79
+ <li id="section-4">
80
+ <div class="annotation">
81
+
82
+ <div class="pilwrap ">
83
+ <a class="pilcrow" href="#section-4">&#182;</a>
84
+ </div>
85
+ <p>Check required variables</p>
86
+
87
+ </div>
88
+
89
+ <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.url_1.empty? <span class="keyword">or</span> settings.url_2.empty? <span class="keyword">or</span> settings.url_3.empty? <span class="keyword">or</span> settings.url_4.empty? <span class="keyword">or</span> settings.url_5.empty?
90
+
91
+ <span class="constant">GroupDocs</span>.configure <span class="keyword">do</span> |groupdocs|
92
+ groupdocs.client_id = settings.client_id
93
+ groupdocs.private_key = settings.private_key
94
+ <span class="keyword">end</span></pre></div></div>
95
+
96
+ </li>
97
+
98
+
99
+ <li id="section-5">
100
+ <div class="annotation">
101
+
102
+ <div class="pilwrap ">
103
+ <a class="pilcrow" href="#section-5">&#182;</a>
104
+ </div>
105
+ <p>Create Array from variables</p>
106
+
107
+ </div>
108
+
109
+ <div class="content"><div class='highlight'><pre> url = [settings.url_1, settings.url_2, settings.url_3, settings.url_4, settings.url_5 ]</pre></div></div>
110
+
111
+ </li>
112
+
113
+
114
+ <li id="section-6">
115
+ <div class="annotation">
116
+
117
+ <div class="pilwrap ">
118
+ <a class="pilcrow" href="#section-6">&#182;</a>
119
+ </div>
120
+ <p>Create Hash with the options for job. :status=&gt; -1 means the Draft status of the job</p>
121
+
122
+ </div>
123
+
124
+ <div class="content"><div class='highlight'><pre> options = {<span class="symbol">:actions</span> =&gt; [<span class="symbol">:convert</span>, <span class="symbol">:combine</span>], <span class="symbol">:out_formats</span> =&gt; [<span class="string">'pdf'</span>], <span class="symbol">:status</span> =&gt; -<span class="number">1</span>, <span class="symbol">:name</span> =&gt; <span class="string">'sample'</span>}</pre></div></div>
125
+
126
+ </li>
127
+
128
+
129
+ <li id="section-7">
130
+ <div class="annotation">
131
+
132
+ <div class="pilwrap ">
133
+ <a class="pilcrow" href="#section-7">&#182;</a>
134
+ </div>
135
+ <p>Create Job with provided options with Draft status (Sheduled job)</p>
136
+
137
+ </div>
138
+
139
+ <div class="content"><div class='highlight'><pre> job = <span class="constant">GroupDocs::Job</span>.create!(options)</pre></div></div>
140
+
141
+ </li>
142
+
143
+
144
+ <li id="section-8">
145
+ <div class="annotation">
146
+
147
+ <div class="pilwrap ">
148
+ <a class="pilcrow" href="#section-8">&#182;</a>
149
+ </div>
150
+ <p>Upload documents to GroupDocs Storage by url and add the documents to previously created Job</p>
151
+
152
+ </div>
153
+
154
+ <div class="content"><div class='highlight'><pre> url.each <span class="keyword">do</span> |url|
155
+ document = <span class="constant">GroupDocs::Storage::File</span>.upload_web!(url).to_document
156
+ job.add_document!(document, {<span class="symbol">:check_ownership</span> =&gt; <span class="keyword">false</span>})
157
+ <span class="keyword">end</span></pre></div></div>
158
+
159
+ </li>
160
+
161
+
162
+ <li id="section-9">
163
+ <div class="annotation">
164
+
165
+ <div class="pilwrap ">
166
+ <a class="pilcrow" href="#section-9">&#182;</a>
167
+ </div>
168
+ <p>Update the Job with new status. :status =&gt; &#39;0&#39; mean Active status of the job (Start the job)</p>
169
+
170
+ </div>
171
+
172
+ <div class="content"><div class='highlight'><pre> job.update!({<span class="symbol">:status</span> =&gt; <span class="string">'0'</span>})
173
+ sleep(<span class="number">5</span>)</pre></div></div>
174
+
175
+ </li>
176
+
177
+
178
+ <li id="section-10">
179
+ <div class="annotation">
180
+
181
+ <div class="pilwrap ">
182
+ <a class="pilcrow" href="#section-10">&#182;</a>
183
+ </div>
184
+ <p>Get the document into Pdf format</p>
185
+
186
+ </div>
187
+
188
+ <div class="content"><div class='highlight'><pre> file = job.documents!()
189
+ sleep(<span class="number">7</span>)
190
+ document = file[<span class="symbol">:outputs</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>Set iframe with document GUID or raise an error</p>
202
+
203
+ </div>
204
+
205
+ <div class="content"><div class='highlight'><pre> <span class="keyword">if</span> document
206
+ iframe = <span class="string">"&lt;iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/<span class="subst">#{document[<span class="number">0</span>].guid}</span>'&gt;&lt;/iframe&gt;"</span>
207
+ <span class="keyword">else</span>
208
+ raise <span class="string">'File was not converted'</span>
209
+ <span class="keyword">end</span>
210
+ <span class="keyword">rescue</span> <span class="constant">Exception</span> =&gt; e
211
+ err = e.message
212
+ <span class="keyword">end</span></pre></div></div>
213
+
214
+ </li>
215
+
216
+
217
+ <li id="section-12">
218
+ <div class="annotation">
219
+
220
+ <div class="pilwrap ">
221
+ <a class="pilcrow" href="#section-12">&#182;</a>
222
+ </div>
223
+ <p>Set variables for template</p>
224
+
225
+ </div>
226
+
227
+ <div class="content"><div class='highlight'><pre> haml <span class="symbol">:sample33</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">:err</span> =&gt; err, <span class="symbol">:iframe</span> =&gt; iframe}
228
+ <span class="keyword">end</span></pre></div></div>
229
+
230
+ </li>
231
+
232
+ </ul>
233
+ </div>
234
+ </body>
235
+ </html>
@@ -0,0 +1,169 @@
1
+ # GET request
2
+ get '/sample32' do
3
+ haml :sample32
4
+ end
5
+
6
+ # POST request
7
+ post '/sample32/callback' do
8
+
9
+ source_id = ''
10
+ client_id = ''
11
+ private_key = ''
12
+ subscriber_email = ''
13
+
14
+ # Get callback request
15
+ data = JSON.parse(request.body.read)
16
+ begin
17
+ raise 'Empty params!' if data.empty?
18
+
19
+ # Get value of SourceId
20
+ data.each do |key, value|
21
+ if key == 'SourceId'
22
+ source_id = value
23
+ end
24
+ end
25
+
26
+ # Get private key and client_id from file user_info.txt
27
+ if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
28
+ contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
29
+ contents = contents.split(' ')
30
+ client_id = contents[0]
31
+ private_key = contents[1]
32
+ subscriber_email = contens[2]
33
+ end
34
+
35
+ # Create new Form
36
+ form = GroupDocs::Signature::Form.new({:id => source_id})
37
+
38
+ # Get document by Form id
39
+ document = form.documents!({}, {:client_id => client_id, :private_key => private_key})
40
+
41
+ # An adress recipient
42
+ to = subscriber_email
43
+
44
+ # The Body message
45
+ body = "
46
+ <html>
47
+ <head>
48
+ <title>Sign form notification</title>
49
+ </head>
50
+ <body>
51
+ <p>Document #{document.name} is signed</p>
52
+ </body>
53
+ </html>"
54
+
55
+
56
+ # A method send the mail
57
+ def send_mail(to, body)
58
+ #implement your send mail function with your SMTP server
59
+ return true
60
+ end
61
+
62
+ send_mail(to, body) #send notification mail
63
+
64
+ rescue Exception => e
65
+ err = e.message
66
+ end
67
+ end
68
+
69
+
70
+ # GET request
71
+ get '/sample32/check' do
72
+
73
+ # Check is there download directory
74
+ unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
75
+ return 'Directory was not found.'
76
+ end
77
+
78
+ # Get file name from download directory
79
+ name = nil
80
+ Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
81
+ name = file if file != '.' && file != '..'
82
+ end
83
+
84
+ name
85
+ end
86
+
87
+
88
+
89
+ # POST request
90
+ post '/sample32' do
91
+ # set variables
92
+ set :client_id, params[:client_id]
93
+ set :private_key, params[:private_key]
94
+ set :template_guid, params[:template]
95
+ set :form_guid, params[:form]
96
+ set :email, params[:email]
97
+ set :callback, params[:callback]
98
+ set :source, params[:source]
99
+
100
+ # Set download path
101
+ downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
102
+
103
+ # Remove all files from download directory or create folder if it not there
104
+ if File.directory?(downloads_path)
105
+ Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
106
+ else
107
+ Dir::mkdir(downloads_path)
108
+ end
109
+
110
+ begin
111
+
112
+ # Check required variables
113
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
114
+
115
+ # Configure your access to API server.
116
+ GroupDocs.configure do |groupdocs|
117
+ groupdocs.client_id = settings.client_id
118
+ groupdocs.private_key = settings.private_key
119
+ end
120
+
121
+ # Write client and private key to the file for callback job
122
+ if settings.callback[0]
123
+ out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
124
+ # white space is required
125
+ out_file.write("#{settings.client_id} ")
126
+ out_file.write("#{settings.private_key}")
127
+ out_file.write("#{settings.email}")
128
+ out_file.close
129
+ end
130
+
131
+ iframe = ''
132
+
133
+ case settings.source
134
+ when 'form'
135
+ # Create new Form with guid
136
+ form = GroupDocs::Signature::Form.new({:guid => settings.form_guid})
137
+
138
+ # Publish the Form
139
+ form.publish!({:callbackUrl => settings.callback})
140
+
141
+ iframe = "https://apps.groupdocs.com/signature2/forms/signembed/ #{settings.form_guid}";
142
+ when 'template'
143
+
144
+ form = GroupDocs::Signature::Form.new
145
+ form.name = 'test'
146
+ form.notifyOwnerOnSign = true
147
+
148
+
149
+ # Create new Form with template
150
+ signature = form.create!({ :templateId => settings.template_guid})
151
+
152
+ # Publish the Form
153
+ form.publish!({:callbackUrl => settings.callback})
154
+
155
+ iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/signature2/forms/signembed/ #{signature}'></iframe>"
156
+ end
157
+
158
+ rescue Exception => e
159
+ err = e.message
160
+ end
161
+
162
+ # Set variables for template
163
+ haml :sample32, :locals => {:userId => settings.client_id,
164
+ :privateKey => settings.private_key,
165
+ :callback => settings.callback,
166
+ :email => settings.email,
167
+ :iframe => iframe,
168
+ :err => err}
169
+ end
@@ -0,0 +1,61 @@
1
+ # GET request
2
+ get '/sample33' do
3
+ haml :sample33
4
+ end
5
+
6
+ # POST request
7
+ post '/sample33' do
8
+ # set variables
9
+ set :client_id, params[:client_id]
10
+ set :private_key, params[:private_key]
11
+ set :url_1, params[:url_1]
12
+ set :url_2, params[:url_2]
13
+ set :url_3, params[:url_3]
14
+ set :url_4, params[:url_4]
15
+ set :url_5, params[:url_5]
16
+
17
+ begin
18
+ # Check required variables
19
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.url_1.empty? or settings.url_2.empty? or settings.url_3.empty? or settings.url_4.empty? or settings.url_5.empty?
20
+
21
+ GroupDocs.configure do |groupdocs|
22
+ groupdocs.client_id = settings.client_id
23
+ groupdocs.private_key = settings.private_key
24
+ end
25
+
26
+ # Create Array from variables
27
+ url = [settings.url_1, settings.url_2, settings.url_3, settings.url_4, settings.url_5 ]
28
+
29
+ # Create Hash with the options for job. :status=> -1 means the Draft status of the job
30
+ options = {:actions => [:convert, :combine], :out_formats => ['pdf'], :status => -1, :name => 'sample'}
31
+
32
+ # Create Job with provided options with Draft status (Sheduled job)
33
+ job = GroupDocs::Job.create!(options, {:client_id => client_id, :private_key => private_key})
34
+
35
+ # Upload documents to GroupDocs Storage by url and add the documents to previously created Job
36
+ url.each do |url|
37
+ document = GroupDocs::Storage::File.upload_web!(url).to_document
38
+ job.add_document!(document, {:check_ownership => false})
39
+ end
40
+
41
+ # Update the Job with new status. :status => '0' mean Active status of the job (Start the job)
42
+ job.update!({:status => '0'})
43
+ sleep(5)
44
+ # Get the document into Pdf format
45
+ file = job.documents!()
46
+ sleep(7)
47
+ document = file[:outputs]
48
+
49
+ # Set iframe with document GUID or raise an error
50
+ if document
51
+ iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/#{document[0].guid}'></iframe>"
52
+ else
53
+ raise 'File was not converted'
54
+ end
55
+ rescue Exception => e
56
+ err = e.message
57
+ end
58
+
59
+ # Set variables for template
60
+ haml :sample33, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :err => err, :iframe => iframe}
61
+ end