groupdocs 1.5.8 → 1.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +9 -0
- data/examples/api-samples/public/docs/sample01.html +34 -15
- data/examples/api-samples/public/docs/sample02.html +36 -15
- data/examples/api-samples/public/docs/sample03.html +55 -34
- data/examples/api-samples/public/docs/sample04.html +33 -14
- data/examples/api-samples/public/docs/sample05.html +51 -33
- data/examples/api-samples/public/docs/sample06.html +86 -40
- data/examples/api-samples/public/docs/sample07.html +32 -13
- data/examples/api-samples/public/docs/sample08.html +39 -20
- data/examples/api-samples/public/docs/sample09.html +93 -39
- data/examples/api-samples/public/docs/sample10.html +39 -21
- data/examples/api-samples/public/docs/sample11.html +133 -88
- data/examples/api-samples/public/docs/sample12.html +33 -14
- data/examples/api-samples/public/docs/sample13.html +14 -7
- data/examples/api-samples/public/docs/sample14.html +37 -18
- data/examples/api-samples/public/docs/sample15.html +29 -10
- data/examples/api-samples/public/docs/sample16.html +58 -25
- data/examples/api-samples/public/docs/sample17.html +71 -38
- data/examples/api-samples/public/docs/sample18.html +98 -71
- data/examples/api-samples/public/docs/sample19.html +74 -42
- data/examples/api-samples/public/docs/sample20.html +39 -21
- data/examples/api-samples/public/docs/sample21.html +113 -69
- data/examples/api-samples/public/docs/sample22.html +89 -43
- data/examples/api-samples/public/docs/sample23.html +50 -32
- data/examples/api-samples/public/docs/sample24.html +64 -31
- data/examples/api-samples/public/docs/sample25.html +107 -60
- data/examples/api-samples/public/docs/sample26.html +29 -10
- data/examples/api-samples/public/docs/sample27.html +107 -61
- data/examples/api-samples/public/docs/sample28.html +158 -9
- data/examples/api-samples/public/docs/sample29.html +13 -8
- data/examples/api-samples/public/docs/sample30.html +34 -15
- data/examples/api-samples/public/docs/sample31.html +107 -76
- data/examples/api-samples/public/docs/sample32.html +104 -40
- data/examples/api-samples/public/docs/sample33.html +85 -36
- data/examples/api-samples/public/docs/sample34.html +30 -11
- data/examples/api-samples/public/docs/sample35.html +90 -27
- data/examples/api-samples/public/docs/sample36.html +36 -16
- data/examples/api-samples/public/docs/sample37.html +144 -265
- data/examples/api-samples/public/docs/sample38.html +113 -64
- data/examples/api-samples/public/docs/sample39.html +118 -45
- data/examples/api-samples/public/docs/sample40.html +81 -46
- data/examples/api-samples/public/docs/sample41.html +562 -90
- data/examples/api-samples/public/docs/sample42.html +94 -39
- data/examples/api-samples/public/docs/sample43.html +669 -0
- data/examples/api-samples/samples/sample01.rb +17 -10
- data/examples/api-samples/samples/sample02.rb +21 -12
- data/examples/api-samples/samples/sample03.rb +35 -29
- data/examples/api-samples/samples/sample04.rb +19 -12
- data/examples/api-samples/samples/sample05.rb +24 -17
- data/examples/api-samples/samples/sample06.rb +38 -32
- data/examples/api-samples/samples/sample07.rb +19 -12
- data/examples/api-samples/samples/sample08.rb +22 -15
- data/examples/api-samples/samples/sample09.rb +31 -29
- data/examples/api-samples/samples/sample10.rb +22 -15
- data/examples/api-samples/samples/sample11.rb +78 -81
- data/examples/api-samples/samples/sample12.rb +19 -21
- data/examples/api-samples/samples/sample13.rb +19 -21
- data/examples/api-samples/samples/sample14.rb +18 -12
- data/examples/api-samples/samples/sample15.rb +17 -10
- data/examples/api-samples/samples/sample16.rb +25 -17
- data/examples/api-samples/samples/sample17.rb +31 -23
- data/examples/api-samples/samples/sample18.rb +60 -55
- data/examples/api-samples/samples/sample19.rb +48 -42
- data/examples/api-samples/samples/sample20.rb +20 -13
- data/examples/api-samples/samples/sample21.rb +62 -54
- data/examples/api-samples/samples/sample22.rb +37 -31
- data/examples/api-samples/samples/sample23.rb +24 -17
- data/examples/api-samples/samples/sample24.rb +29 -22
- data/examples/api-samples/samples/sample25.rb +47 -40
- data/examples/api-samples/samples/sample26.rb +16 -9
- data/examples/api-samples/samples/sample27.rb +46 -39
- data/examples/api-samples/samples/sample28.rb +42 -11
- data/examples/api-samples/samples/sample29.rb +13 -8
- data/examples/api-samples/samples/sample30.rb +19 -12
- data/examples/api-samples/samples/sample31.rb +63 -58
- data/examples/api-samples/samples/sample32.rb +45 -42
- data/examples/api-samples/samples/sample33.rb +36 -25
- data/examples/api-samples/samples/sample34.rb +16 -9
- data/examples/api-samples/samples/sample35.rb +66 -53
- data/examples/api-samples/samples/sample36.rb +19 -15
- data/examples/api-samples/samples/sample37.rb +61 -99
- data/examples/api-samples/samples/sample38.rb +51 -43
- data/examples/api-samples/samples/sample39.rb +78 -62
- data/examples/api-samples/samples/sample40.rb +48 -38
- data/examples/api-samples/samples/sample41.rb +189 -67
- data/examples/api-samples/samples/sample42.rb +37 -29
- data/examples/api-samples/samples/sample43.rb +127 -0
- data/examples/api-samples/views/_others_samples.haml +4 -2
- data/examples/api-samples/views/index.haml +4 -2
- data/examples/api-samples/views/sample11.haml +1 -1
- data/examples/api-samples/views/sample28.haml +8 -0
- data/examples/api-samples/views/sample31.haml +1 -6
- data/examples/api-samples/views/sample39.haml +7 -2
- data/examples/api-samples/views/sample41.haml +78 -33
- data/examples/api-samples/views/sample42.haml +0 -1
- data/examples/api-samples/views/sample43.haml +91 -0
- data/lib/groupdocs/api/helpers/access_rights_helper.rb +6 -5
- data/lib/groupdocs/api/helpers/url_helper.rb +2 -1
- data/lib/groupdocs/document.rb +3 -3
- data/lib/groupdocs/version.rb +1 -1
- metadata +5 -2
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
#GET request
|
|
2
2
|
get '/sample39' do
|
|
3
3
|
haml :sample39
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
#GET request
|
|
7
7
|
get '/popup' do
|
|
8
8
|
haml :popup
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
#
|
|
11
|
+
#POST request
|
|
12
12
|
post '/sample39/signature_callback' do
|
|
13
13
|
begin
|
|
14
|
-
#
|
|
14
|
+
#Get callback request
|
|
15
15
|
data = JSON.parse(request.body.read)
|
|
16
16
|
|
|
17
17
|
raise 'Empty params!' if data.empty?
|
|
@@ -19,14 +19,14 @@ post '/sample39/signature_callback' do
|
|
|
19
19
|
client_id = nil
|
|
20
20
|
private_key = nil
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
#Get value of SourceId
|
|
23
23
|
data.each do |key, value|
|
|
24
24
|
if key == 'SourceId'
|
|
25
25
|
source_id = value
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
#
|
|
29
|
+
#Get private key and client_id from file user_info.txt
|
|
30
30
|
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
31
31
|
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
32
32
|
contents = contents.split(' ')
|
|
@@ -34,18 +34,18 @@ post '/sample39/signature_callback' do
|
|
|
34
34
|
private_key = contents.last
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
#
|
|
37
|
+
#Create Job instance
|
|
38
38
|
job = GroupDocs::Signature::Envelope.new({:id => source_id})
|
|
39
39
|
|
|
40
|
-
#
|
|
40
|
+
#Get document by job id
|
|
41
41
|
documents = job.documents!({}, {:client_id => client_id, :private_key => private_key}).first
|
|
42
42
|
|
|
43
|
-
#
|
|
43
|
+
#Get guid from file
|
|
44
44
|
guid = documents.file.guid
|
|
45
45
|
|
|
46
|
-
#
|
|
46
|
+
#Create new file callback_info.txt and write the guid document
|
|
47
47
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/callback_info.txt", 'w')
|
|
48
|
-
#
|
|
48
|
+
#White space is required
|
|
49
49
|
out_file.write("#{guid}")
|
|
50
50
|
out_file.close
|
|
51
51
|
|
|
@@ -54,7 +54,7 @@ post '/sample39/signature_callback' do
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
#
|
|
57
|
+
#POST request
|
|
58
58
|
post '/sample39/check' do
|
|
59
59
|
begin
|
|
60
60
|
result = nil
|
|
@@ -62,7 +62,7 @@ post '/sample39/check' do
|
|
|
62
62
|
for i in 1..10
|
|
63
63
|
i +=1
|
|
64
64
|
|
|
65
|
-
#
|
|
65
|
+
#Check is downloads folder exist
|
|
66
66
|
if File.exist?("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
67
67
|
result = File.read("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
68
68
|
if result.nil? then break end
|
|
@@ -70,7 +70,7 @@ post '/sample39/check' do
|
|
|
70
70
|
sleep(5)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
#
|
|
73
|
+
#Check result
|
|
74
74
|
if result == 'Error'
|
|
75
75
|
result = "File was not found. Looks like something went wrong."
|
|
76
76
|
else
|
|
@@ -83,32 +83,30 @@ post '/sample39/check' do
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
#
|
|
86
|
+
#POST request
|
|
87
87
|
post '/sample39/postdata' do
|
|
88
88
|
|
|
89
89
|
data = request.body.read
|
|
90
|
-
#
|
|
90
|
+
#Decode ajax data
|
|
91
91
|
json_post_data = JSON.parse(data);
|
|
92
|
-
#
|
|
92
|
+
#Get Client ID
|
|
93
93
|
clientId = json_post_data['userId'];
|
|
94
|
-
#
|
|
94
|
+
#Get Private Key
|
|
95
95
|
privateKey = json_post_data['privateKey'];
|
|
96
96
|
#Get document for sign
|
|
97
97
|
documents = json_post_data['documents'];
|
|
98
|
-
#
|
|
98
|
+
#Get signature file
|
|
99
99
|
signers = json_post_data['signers'];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
end
|
|
103
|
-
# Documents local path
|
|
100
|
+
|
|
101
|
+
#Documents local path
|
|
104
102
|
document_path = "#{File.dirname(__FILE__)}/../public/downloads/#{documents[0]['name']}"
|
|
105
103
|
signer_path = "#{File.dirname(__FILE__)}/../public/downloads/#{signers[0]['name']}.png"
|
|
106
104
|
|
|
107
|
-
#
|
|
105
|
+
#Get base64 string
|
|
108
106
|
base64_documents = documents[0]['data'].split(',').last
|
|
109
107
|
base64_signers = signers[0]['data'].split(',').last
|
|
110
108
|
|
|
111
|
-
#
|
|
109
|
+
#Write to the files decode base64 strings
|
|
112
110
|
File.open(document_path, 'wb') do |f|
|
|
113
111
|
f.write(Base64.strict_decode64(base64_documents))
|
|
114
112
|
end
|
|
@@ -117,40 +115,41 @@ post '/sample39/postdata' do
|
|
|
117
115
|
f.write(Base64.strict_decode64(base64_signers))
|
|
118
116
|
end
|
|
119
117
|
|
|
120
|
-
#
|
|
118
|
+
#Set document for signing
|
|
121
119
|
documents = GroupDocs::Storage::File.new(:name=>documents[0]['name'], :local_path=>document_path).to_document
|
|
122
|
-
#
|
|
120
|
+
#Set signature
|
|
123
121
|
signers = GroupDocs::Signature.new(:name=>signers[0]['name'], :image_path=>signer_path)
|
|
124
122
|
signers.position = {top: 0.83319, left: 0.72171, width: 100, height: 40}
|
|
125
123
|
|
|
126
|
-
#
|
|
124
|
+
#Make request to sign documnet
|
|
127
125
|
signDocument = GroupDocs::Document.sign_documents!([documents], [signers], {}, {:client_id=>clientId, :private_key=>privateKey})
|
|
128
126
|
sleep(5)
|
|
129
|
-
#
|
|
127
|
+
#Get the document guid
|
|
130
128
|
document = GroupDocs::Signature.sign_document_status!(signDocument, {:client_id=>clientId, :private_key=>privateKey})
|
|
131
|
-
#
|
|
129
|
+
#Get file GUID
|
|
132
130
|
guid = document.guid
|
|
133
|
-
#
|
|
131
|
+
#Create array with result data
|
|
134
132
|
result = ['guid' => guid,'clientId' => clientId,'privateKey' => privateKey]
|
|
135
|
-
#
|
|
133
|
+
#Decode array to json and return json string to ajax request
|
|
136
134
|
result.to_json
|
|
137
135
|
end
|
|
138
136
|
|
|
139
137
|
|
|
140
|
-
#
|
|
138
|
+
#POST request
|
|
141
139
|
post '/sample39' do
|
|
142
|
-
#
|
|
140
|
+
#Set variables
|
|
143
141
|
set :client_id, params[:clientId]
|
|
144
142
|
set :private_key, params[:privateKey]
|
|
145
143
|
set :name, params[:name]
|
|
146
144
|
set :email, params[:email]
|
|
147
145
|
set :callback, params[:callbackUrl]
|
|
148
146
|
set :last_name, params[:lastName]
|
|
147
|
+
set :base_path, params[:basePath]
|
|
149
148
|
|
|
150
|
-
#
|
|
149
|
+
#Set download path
|
|
151
150
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
152
151
|
|
|
153
|
-
#
|
|
152
|
+
#Remove all files from download directory or create folder if it not there
|
|
154
153
|
if File.directory?(downloads_path)
|
|
155
154
|
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
|
156
155
|
else
|
|
@@ -158,80 +157,97 @@ post '/sample39' do
|
|
|
158
157
|
end
|
|
159
158
|
|
|
160
159
|
begin
|
|
161
|
-
#
|
|
160
|
+
#Check required variables
|
|
162
161
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.name.empty? or settings.email.empty? or settings.last_name.empty?
|
|
163
162
|
|
|
164
|
-
|
|
163
|
+
#Prepare base path
|
|
164
|
+
if settings.base_path.empty?
|
|
165
|
+
base_path = 'https://api.groupdocs.com'
|
|
166
|
+
elsif settings.base_path.match('/v2.0')
|
|
167
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
|
168
|
+
else
|
|
169
|
+
base_path = settings.base_path
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
#Configure your access to API server
|
|
165
173
|
GroupDocs.configure do |groupdocs|
|
|
166
174
|
groupdocs.client_id = settings.client_id
|
|
167
175
|
groupdocs.private_key = settings.private_key
|
|
176
|
+
#Optionally specify API server and version
|
|
177
|
+
groupdocs.api_server = base_path #Default is 'https://api.groupdocs.com'
|
|
178
|
+
|
|
168
179
|
end
|
|
169
180
|
|
|
170
|
-
#
|
|
181
|
+
#Write client and private key to the file for callback job
|
|
171
182
|
if settings.callback[0]
|
|
172
183
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
|
173
|
-
#
|
|
184
|
+
#White space is required
|
|
174
185
|
out_file.write("#{settings.client_id} ")
|
|
175
186
|
out_file.write("#{settings.private_key}")
|
|
176
187
|
out_file.close
|
|
177
188
|
end
|
|
178
189
|
|
|
179
|
-
#
|
|
190
|
+
#Construct path
|
|
180
191
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
181
|
-
#
|
|
192
|
+
#Open file
|
|
182
193
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
183
|
-
#
|
|
194
|
+
#Make a request to API using client_id and private_key
|
|
184
195
|
file = GroupDocs::Storage::File.upload!(file_path)
|
|
185
196
|
document = file.to_document
|
|
186
197
|
|
|
187
198
|
|
|
188
|
-
#
|
|
199
|
+
#Create envelope using user id and entered by user name
|
|
189
200
|
envelope = GroupDocs::Signature::Envelope.new
|
|
190
201
|
envelope.name = file.name
|
|
191
202
|
envelope.email_subject = 'Sing this!'
|
|
192
203
|
envelope.create!
|
|
193
204
|
|
|
194
|
-
#
|
|
205
|
+
#Add uploaded document to envelope
|
|
195
206
|
envelope.add_document!(document)
|
|
196
207
|
|
|
197
|
-
#
|
|
208
|
+
#Get role list for current user
|
|
198
209
|
roles = GroupDocs::Signature::Role.get!
|
|
199
210
|
|
|
200
|
-
#
|
|
211
|
+
#Create new recipient
|
|
201
212
|
recipient = GroupDocs::Signature::Recipient.new
|
|
202
213
|
recipient.email = settings.email
|
|
203
214
|
recipient.first_name = settings.name
|
|
204
215
|
recipient.last_name = settings.last_name
|
|
205
216
|
recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
|
|
206
217
|
|
|
207
|
-
#
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
# Get recipient id
|
|
211
|
-
recipient.id = add[:recipient][:id]
|
|
218
|
+
#Add recipient to envelope
|
|
219
|
+
recipient = envelope.add_recipient!(recipient)
|
|
212
220
|
|
|
213
|
-
#
|
|
221
|
+
#Get document id
|
|
214
222
|
document = envelope.documents!()
|
|
215
223
|
|
|
216
|
-
|
|
217
224
|
# Get field and add the location to field
|
|
218
225
|
field = GroupDocs::Signature::Field.get!().detect { |f| f.type == :signature }
|
|
219
226
|
field.location = {:location_x => 0.15, :location_y => 0.73, :location_w => 150, :location_h => 50, :page => 1}
|
|
220
227
|
field.name = 'EMPLOYEE SIGNATURE'
|
|
221
228
|
|
|
222
|
-
#
|
|
229
|
+
#Add field to envelope
|
|
223
230
|
envelope.add_field!(field, document[0], recipient, {})
|
|
224
231
|
|
|
225
232
|
|
|
226
|
-
#
|
|
233
|
+
#Send envelop
|
|
227
234
|
envelope.send!({:callbackUrl => settings.callback})
|
|
228
235
|
|
|
236
|
+
#Prepare to sign url
|
|
237
|
+
iframe = "/signature2/signembed/#{envelope.id}/#{recipient.id}"
|
|
238
|
+
# Construct result string
|
|
239
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
|
240
|
+
#Generate iframe URL
|
|
241
|
+
case base_path
|
|
242
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
|
243
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
|
244
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
|
245
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
|
246
|
+
else
|
|
247
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
|
248
|
+
end
|
|
229
249
|
|
|
230
|
-
|
|
231
|
-
url = "https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
|
|
232
|
-
|
|
233
|
-
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
|
234
|
-
# Make iframe
|
|
250
|
+
#Make iframe
|
|
235
251
|
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
|
236
252
|
|
|
237
253
|
|
|
@@ -239,7 +255,7 @@ post '/sample39' do
|
|
|
239
255
|
err = e.message
|
|
240
256
|
end
|
|
241
257
|
|
|
242
|
-
#
|
|
258
|
+
#Set variables for template
|
|
243
259
|
haml :sample39, :locals => {:userId => settings.client_id,
|
|
244
260
|
:privateKey => settings.private_key,
|
|
245
261
|
:callback => settings.callback,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
#GET request
|
|
2
2
|
get '/sample40' do
|
|
3
3
|
haml :sample40
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
#POST request
|
|
7
7
|
post '/sample40/check_guid' do
|
|
8
8
|
begin
|
|
9
9
|
result = nil
|
|
10
10
|
i = 0
|
|
11
11
|
for i in 1..10
|
|
12
12
|
i +=1
|
|
13
|
-
#
|
|
13
|
+
#Check is downloads folder exist
|
|
14
14
|
if File.exist?("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
15
15
|
result = File.read("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
16
16
|
if result != '' then break end
|
|
@@ -18,7 +18,7 @@ post '/sample40/check_guid' do
|
|
|
18
18
|
sleep(5)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
#
|
|
21
|
+
#Check result
|
|
22
22
|
if result == 'Error'
|
|
23
23
|
result = "File was not found. Looks like something went wrong."
|
|
24
24
|
else
|
|
@@ -31,20 +31,20 @@ post '/sample40/check_guid' do
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
#
|
|
34
|
+
#POST request
|
|
35
35
|
post '/sample40/callback' do
|
|
36
36
|
|
|
37
37
|
source_id = ''
|
|
38
38
|
client_id = ''
|
|
39
39
|
private_key = ''
|
|
40
40
|
|
|
41
|
-
#
|
|
41
|
+
#Get callback request
|
|
42
42
|
data = JSON.parse(request.body.read)
|
|
43
43
|
begin
|
|
44
44
|
participant = nil
|
|
45
45
|
raise 'Empty params!' if data.empty?
|
|
46
46
|
|
|
47
|
-
#
|
|
47
|
+
#Get value of SourceId
|
|
48
48
|
data.each do |key, value|
|
|
49
49
|
if key == 'SourceId'
|
|
50
50
|
source_id = value
|
|
@@ -59,7 +59,7 @@ post '/sample40/callback' do
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
#
|
|
62
|
+
#Get private key and client_id from file user_info.txt
|
|
63
63
|
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
64
64
|
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
65
65
|
contents = contents.split(' ')
|
|
@@ -67,16 +67,16 @@ post '/sample40/callback' do
|
|
|
67
67
|
private_key = contents[1]
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
#
|
|
70
|
+
#Create new Form
|
|
71
71
|
form = GroupDocs::Signature::Form.new({:id => source_id})
|
|
72
|
-
#
|
|
72
|
+
#Create new Signature
|
|
73
73
|
signature = GroupDocs::Signature.new()
|
|
74
74
|
doc_info = signature.get_sign_form_participant!(form.id , participant, {:client_id => client_id, :private_key => private_key} )
|
|
75
75
|
|
|
76
76
|
guid = doc_info[:documentGuid]
|
|
77
77
|
|
|
78
78
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/callback_info.txt", 'w')
|
|
79
|
-
#
|
|
79
|
+
#White space is required
|
|
80
80
|
out_file.write(guid)
|
|
81
81
|
out_file.close
|
|
82
82
|
|
|
@@ -87,9 +87,9 @@ end
|
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
#
|
|
90
|
+
#POST request
|
|
91
91
|
post '/sample40' do
|
|
92
|
-
#
|
|
92
|
+
#Set variables
|
|
93
93
|
set :client_id, params[:clientId]
|
|
94
94
|
set :private_key, params[:privateKey]
|
|
95
95
|
set :form_guid, params[:formGuid]
|
|
@@ -98,23 +98,36 @@ post '/sample40' do
|
|
|
98
98
|
|
|
99
99
|
begin
|
|
100
100
|
|
|
101
|
-
#
|
|
101
|
+
#Check required variables
|
|
102
102
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.form_guid.empty?
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
#Delete file callback_info.txt
|
|
105
|
+
if File.exist?("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
106
|
+
File.delete("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
#Prepare base path
|
|
110
|
+
if settings.base_path.empty?
|
|
111
|
+
base_path = 'https://api.groupdocs.com'
|
|
112
|
+
elsif settings.base_path.match('/v2.0')
|
|
113
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
|
114
|
+
else
|
|
115
|
+
base_path = settings.base_path
|
|
116
|
+
end
|
|
105
117
|
|
|
106
|
-
#
|
|
118
|
+
#Configure your access to API server
|
|
107
119
|
GroupDocs.configure do |groupdocs|
|
|
108
120
|
groupdocs.client_id = settings.client_id
|
|
109
121
|
groupdocs.private_key = settings.private_key
|
|
110
|
-
#
|
|
111
|
-
groupdocs.api_server =
|
|
122
|
+
#Optionally specify API server and version
|
|
123
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
|
124
|
+
|
|
112
125
|
end
|
|
113
126
|
|
|
114
|
-
#
|
|
127
|
+
#Write client and private key to the file for callback job
|
|
115
128
|
if settings.callback
|
|
116
129
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
|
117
|
-
#
|
|
130
|
+
#White space is required
|
|
118
131
|
out_file.write("#{settings.client_id} ")
|
|
119
132
|
out_file.write("#{settings.private_key} ")
|
|
120
133
|
out_file.close
|
|
@@ -122,40 +135,37 @@ post '/sample40' do
|
|
|
122
135
|
|
|
123
136
|
guid = settings.form_guid
|
|
124
137
|
|
|
125
|
-
#
|
|
138
|
+
#Create new Form with guid
|
|
126
139
|
form = GroupDocs::Signature::Form.new()
|
|
127
140
|
form.name = "Test Form"
|
|
128
|
-
#
|
|
141
|
+
#Get id with new Form
|
|
129
142
|
id = form.create!({:formId => guid})
|
|
130
|
-
#
|
|
143
|
+
#Get Form
|
|
131
144
|
form = GroupDocs::Signature::Form.get!(id)
|
|
132
|
-
#
|
|
145
|
+
#Publish the Form
|
|
133
146
|
form.publish!({:callbackUrl => settings.callback})
|
|
134
147
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
#Prepare to sign url
|
|
149
|
+
iframe = "//signature2/forms/signembed/#{guid}"
|
|
150
|
+
# Construct result string
|
|
151
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
|
152
|
+
#Generate iframe URL
|
|
153
|
+
case base_path
|
|
138
154
|
when 'https://stage-api-groupdocs.dynabic.com'
|
|
139
|
-
|
|
155
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
|
140
156
|
when 'https://dev-api-groupdocs.dynabic.com'
|
|
141
|
-
|
|
157
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
|
142
158
|
else
|
|
143
|
-
|
|
144
|
-
end
|
|
145
|
-
# Delete file callback_info.txt
|
|
146
|
-
if File.exist?("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
147
|
-
File.delete("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
159
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
|
148
160
|
end
|
|
149
161
|
|
|
150
|
-
|
|
151
|
-
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
|
152
|
-
iframe = "<iframe width='100%' id='downloadframe' height='600' src='#{iframe}'></iframe>"
|
|
162
|
+
iframe = "<iframe src='#{iframe}' id='downloadframe' width='800' height='1000'></iframe>"
|
|
153
163
|
|
|
154
164
|
rescue Exception => e
|
|
155
165
|
err = e.message
|
|
156
166
|
end
|
|
157
167
|
|
|
158
|
-
#
|
|
168
|
+
#Set variables for template
|
|
159
169
|
haml :sample40, :locals => {:userId => settings.client_id,
|
|
160
170
|
:privateKey => settings.private_key,
|
|
161
171
|
:callback => settings.callback,
|