groupdocs 1.5.8 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- 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,23 +1,20 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample36' do
|
3
3
|
haml :sample36
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# POST request
|
6
|
+
#POST request
|
10
7
|
post '/sample36' do
|
11
|
-
#
|
8
|
+
#Set variables
|
12
9
|
set :client_id, params[:clientId]
|
13
10
|
set :private_key, params[:privateKey]
|
14
11
|
set :envelope, params[:envelopeGuid]
|
15
12
|
set :base_path, params[:basePath]
|
16
13
|
|
17
|
-
#
|
14
|
+
#Set download path
|
18
15
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
19
16
|
|
20
|
-
#
|
17
|
+
#Remove all files from download directory or create folder if it not there
|
21
18
|
if File.directory?(downloads_path)
|
22
19
|
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
23
20
|
else
|
@@ -26,20 +23,27 @@ post '/sample36' do
|
|
26
23
|
|
27
24
|
|
28
25
|
begin
|
29
|
-
#
|
26
|
+
#Check required variables
|
30
27
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
31
28
|
|
32
|
-
|
29
|
+
#Prepare base path
|
30
|
+
if settings.base_path.empty?
|
31
|
+
base_path = 'https://api.groupdocs.com'
|
32
|
+
elsif settings.base_path.match('/v2.0')
|
33
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
34
|
+
else
|
35
|
+
base_path = settings.base_path
|
36
|
+
end
|
33
37
|
|
34
|
-
#
|
38
|
+
#Configure your access to API server
|
35
39
|
GroupDocs.configure do |groupdocs|
|
36
40
|
groupdocs.client_id = settings.client_id
|
37
41
|
groupdocs.private_key = settings.private_key
|
38
|
-
#
|
39
|
-
groupdocs.api_server =
|
42
|
+
#Optionally specify API server and version
|
43
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
40
44
|
end
|
41
45
|
|
42
|
-
#
|
46
|
+
#Get envelope from GroupDocs Storage
|
43
47
|
envelope = GroupDocs::Signature::Envelope.get!(settings.envelope)
|
44
48
|
|
45
49
|
#Download signed files
|
@@ -53,6 +57,6 @@ post '/sample36' do
|
|
53
57
|
err = e.message
|
54
58
|
end
|
55
59
|
|
56
|
-
#
|
60
|
+
#Set variables for template
|
57
61
|
haml :sample36, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :envelopeGuid => settings.envelope, :message => message, :err => err}
|
58
62
|
end
|
@@ -1,72 +1,27 @@
|
|
1
|
-
#
|
1
|
+
#Route the handler url "/sample37"
|
2
2
|
get '/sample37' do
|
3
3
|
haml :sample37
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#GET request
|
7
7
|
|
8
|
-
#
|
8
|
+
#Route the handler url "/sample37/signature_callback". The block function for callback with server
|
9
9
|
post '/sample37/signature_callback' do
|
10
|
-
# Get data json from callback
|
11
|
-
data = JSON.parse(request.body.read)
|
12
|
-
begin
|
13
|
-
|
14
|
-
raise 'Empty params!' if data.empty?
|
15
|
-
|
16
|
-
# Set variables from data json
|
17
|
-
source_id = data['SourceId']
|
18
|
-
event_type = data['EventType']
|
19
|
-
|
20
|
-
# Set variables
|
21
|
-
client_id = nil
|
22
|
-
private_key = nil
|
23
|
-
|
24
|
-
return if event_type != 'JobCompleted'
|
25
|
-
|
26
|
-
# Set download path
|
27
|
-
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
28
|
-
|
29
|
-
# Get private key and client_id from file user_info.txt
|
30
|
-
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
31
|
-
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
32
|
-
contents = contents.split(' ')
|
33
|
-
client_id = contents[0]
|
34
|
-
private_key = contents[1]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Get Envelope instance
|
38
|
-
envelope = GroupDocs::Signature::Envelope.get!(source_id, {:client_id => client_id, :private_key => private_key})
|
39
|
-
|
40
|
-
# Get document by envelope
|
41
|
-
envelope.signed_documents!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
|
-
|
43
|
-
|
44
|
-
rescue Exception => e
|
45
|
-
err = e.message
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
# Route the handler url "/sample37/check"
|
51
|
-
|
52
|
-
get '/sample37/check' do
|
53
|
-
|
54
|
-
# Check is there download directory
|
55
10
|
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
56
11
|
return 'Directory was not found.'
|
57
12
|
end
|
58
13
|
|
59
|
-
#
|
14
|
+
#Get file name from download directory
|
60
15
|
name = nil
|
61
|
-
|
16
|
+
|
62
17
|
i = 0
|
63
18
|
|
64
|
-
#
|
19
|
+
#Checking, if file exist
|
65
20
|
while i<10 do
|
66
|
-
sleep(5)
|
67
|
-
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
68
|
-
name = file if file != '.' && file != '..'
|
69
|
-
end
|
21
|
+
sleep(5)
|
22
|
+
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
23
|
+
name = file if file != '.' && file != '..'
|
24
|
+
end
|
70
25
|
break if name
|
71
26
|
i += 1
|
72
27
|
end
|
@@ -74,15 +29,15 @@ get '/sample37/check' do
|
|
74
29
|
name
|
75
30
|
end
|
76
31
|
|
77
|
-
#
|
32
|
+
#Route the handler url "/sample37/downloads"
|
78
33
|
get '/sample37/downloads/:filename' do |filename|
|
79
|
-
#
|
34
|
+
#Send file with header to download it
|
80
35
|
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
81
36
|
end
|
82
37
|
|
83
|
-
#
|
38
|
+
#Route the handler url "/sample37". The function block creates new envelope
|
84
39
|
post '/sample37' do
|
85
|
-
#
|
40
|
+
#Set variables from form
|
86
41
|
set :client_id, params[:clientId]
|
87
42
|
set :private_key, params[:privateKey]
|
88
43
|
set :email, params[:email]
|
@@ -94,10 +49,10 @@ post '/sample37' do
|
|
94
49
|
set :url, params[:url]
|
95
50
|
set :source, params[:source]
|
96
51
|
|
97
|
-
#
|
52
|
+
#Set download path
|
98
53
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
99
54
|
|
100
|
-
#
|
55
|
+
#Remove all files from download directory or create folder if it not there
|
101
56
|
if File.directory?(downloads_path)
|
102
57
|
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
103
58
|
else
|
@@ -105,124 +60,131 @@ post '/sample37' do
|
|
105
60
|
end
|
106
61
|
|
107
62
|
begin
|
108
|
-
#
|
63
|
+
#Check required variables
|
109
64
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.email.empty? or settings.name.empty? or settings.lastName.empty?
|
110
65
|
|
111
|
-
|
66
|
+
#Prepare base path
|
67
|
+
if settings.base_path.empty?
|
68
|
+
base_path = 'https://api.groupdocs.com'
|
69
|
+
elsif settings.base_path.match('/v2.0')
|
70
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
71
|
+
else
|
72
|
+
base_path = settings.base_path
|
73
|
+
end
|
112
74
|
|
113
|
-
#
|
75
|
+
#Configure your access to API server
|
114
76
|
GroupDocs.configure do |groupdocs|
|
115
77
|
groupdocs.client_id = settings.client_id
|
116
78
|
groupdocs.private_key = settings.private_key
|
117
79
|
# Optionally specify API server and version
|
118
|
-
groupdocs.api_server =
|
80
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
119
81
|
end
|
120
82
|
|
121
|
-
#
|
83
|
+
#Write client and private key to the file for callback job
|
122
84
|
if settings.callback
|
123
85
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
124
|
-
#
|
86
|
+
#White space is required
|
125
87
|
out_file.write("#{settings.client_id} ")
|
126
88
|
out_file.write("#{settings.private_key}")
|
127
89
|
out_file.close
|
128
90
|
end
|
129
91
|
|
130
92
|
file = nil
|
131
|
-
#
|
93
|
+
#Get document by file GUID
|
132
94
|
case settings.source
|
133
95
|
when 'guid'
|
134
|
-
#
|
96
|
+
#Create instance of File
|
135
97
|
file = GroupDocs::Storage::File.new({:guid => settings.fileId}).to_document.metadata!()
|
136
98
|
file = file.last_view.document.file.to_document
|
137
99
|
when 'local'
|
138
|
-
#
|
100
|
+
#Construct path
|
139
101
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
140
102
|
|
141
|
-
#
|
103
|
+
#Open file
|
142
104
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
143
|
-
#
|
144
|
-
file = GroupDocs::Storage::File.upload!(file_path
|
105
|
+
#Make a request to API using client_id and private_key
|
106
|
+
file = GroupDocs::Storage::File.upload!(file_path).to_document
|
107
|
+
|
145
108
|
when 'url'
|
146
|
-
#
|
109
|
+
#Upload file from defined url
|
147
110
|
file = GroupDocs::Storage::File.upload_web!(settings.url).to_document
|
148
111
|
else
|
149
112
|
raise 'Wrong GUID source.'
|
150
113
|
end
|
151
114
|
|
152
115
|
name = file.name
|
153
|
-
#
|
116
|
+
#Create envelope using user id and entered by user name
|
154
117
|
envelope = GroupDocs::Signature::Envelope.new
|
155
118
|
envelope.name = file.name
|
156
119
|
envelope.email_subject = 'Sing this!'
|
157
120
|
envelope.create!({})
|
158
121
|
|
159
|
-
#
|
122
|
+
#Add uploaded document to envelope
|
160
123
|
envelope.add_document!(file, {})
|
161
124
|
|
162
|
-
#
|
125
|
+
#Get role list for current user
|
163
126
|
roles = GroupDocs::Signature::Role.get!({})
|
164
127
|
|
165
|
-
#
|
128
|
+
#Create new recipient
|
166
129
|
recipient = GroupDocs::Signature::Recipient.new
|
167
130
|
recipient.email = settings.email
|
168
131
|
recipient.first_name = settings.name
|
169
132
|
recipient.last_name = settings.lastName
|
170
133
|
recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
|
171
134
|
|
172
|
-
#
|
173
|
-
|
174
|
-
|
175
|
-
# Get recipient id
|
176
|
-
recipient.id = add[:recipient][:id]
|
135
|
+
#Add recipient to envelope
|
136
|
+
recipient = envelope.add_recipient!(recipient)
|
177
137
|
|
178
|
-
#
|
138
|
+
#Get document id
|
179
139
|
document = envelope.documents!
|
180
140
|
|
181
141
|
|
182
|
-
#
|
142
|
+
#Get field and add the location to field
|
183
143
|
field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
|
184
144
|
field.location = {:location_x => 0.15, :location_y => 0.73, :location_w => 150, :location_h => 50, :page => 1}
|
185
145
|
field.name = 'EMPLOYEE SIGNATURE'
|
186
146
|
|
187
|
-
#
|
147
|
+
#Add field to envelope
|
188
148
|
envelope.add_field!(field, document[0], recipient)
|
189
149
|
|
190
150
|
|
191
151
|
|
192
|
-
#
|
152
|
+
#Send envelop
|
193
153
|
envelope.send!({:callbackUrl => settings.callback})
|
194
154
|
|
195
|
-
#
|
155
|
+
#Write client and private key to the file for callback job
|
196
156
|
if settings.callback
|
197
157
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
198
|
-
#
|
158
|
+
#White space is required
|
199
159
|
out_file.write("#{settings.client_id} ")
|
200
160
|
out_file.write("#{settings.private_key}")
|
201
161
|
out_file.write("#{envelope.id}")
|
202
162
|
out_file.close
|
203
163
|
end
|
204
164
|
|
205
|
-
#
|
206
|
-
|
207
|
-
|
165
|
+
#Prepare to sign url
|
166
|
+
iframe = "/signature2/signembed/#{envelope.id}/#{recipient.id}"
|
167
|
+
# Construct result string
|
168
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
169
|
+
#Generate iframe URL
|
170
|
+
case base_path
|
208
171
|
when 'https://stage-api-groupdocs.dynabic.com'
|
209
|
-
|
172
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
210
173
|
when 'https://dev-api-groupdocs.dynabic.com'
|
211
|
-
|
174
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
212
175
|
else
|
213
|
-
|
176
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
214
177
|
end
|
215
178
|
|
179
|
+
#Make iframe
|
180
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
216
181
|
|
217
|
-
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
218
|
-
# Make iframe
|
219
|
-
iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
|
220
182
|
message = "<p>File was uploaded to GroupDocs. Here you can see your <strong>#{name}</strong> file in the GroupDocs Embedded Viewer.</p>"
|
221
183
|
rescue Exception => e
|
222
184
|
err = e.message
|
223
185
|
end
|
224
186
|
|
225
|
-
#
|
187
|
+
#Set variables for template
|
226
188
|
haml :sample37, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :email => settings.email, :name => settings.name, :lastName => settings.lastName, :iframe => iframe, :massage => message, :err => err, :callback => settings.callback,}
|
227
189
|
end
|
228
190
|
|
@@ -1,14 +1,11 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample38' do
|
3
3
|
haml :sample38
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# POST request
|
6
|
+
#POST request
|
10
7
|
post '/sample38' do
|
11
|
-
#
|
8
|
+
#Set variables
|
12
9
|
set :client_id, params[:clientId]
|
13
10
|
set :private_key, params[:privateKey]
|
14
11
|
set :email, params[:email]
|
@@ -18,46 +15,52 @@ post '/sample38' do
|
|
18
15
|
set :first_name, params[:firstName]
|
19
16
|
set :last_name, params[:lastName]
|
20
17
|
set :base_path, params[:basePath]
|
21
|
-
|
22
|
-
#
|
18
|
+
|
19
|
+
#Set download path
|
23
20
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
24
21
|
|
25
|
-
#
|
22
|
+
#Remove all files from download directory or create folder if it not there
|
26
23
|
if File.directory?(downloads_path)
|
27
24
|
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
28
25
|
else
|
29
26
|
Dir::mkdir(downloads_path)
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
29
|
begin
|
34
|
-
#
|
35
|
-
|
30
|
+
#Check required variables
|
31
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.email.empty? or settings.first_name.empty? or settings.last_name.empty?
|
36
32
|
|
37
|
-
|
33
|
+
#Prepare base path
|
34
|
+
if settings.base_path.empty?
|
35
|
+
base_path = 'https://api.groupdocs.com'
|
36
|
+
elsif settings.base_path.match('/v2.0')
|
37
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
38
|
+
else
|
39
|
+
base_path = settings.base_path
|
40
|
+
end
|
38
41
|
|
39
|
-
#
|
42
|
+
#Configure your access to API server
|
40
43
|
GroupDocs.configure do |groupdocs|
|
41
44
|
groupdocs.client_id = settings.client_id
|
42
45
|
groupdocs.private_key = settings.private_key
|
43
|
-
#
|
44
|
-
groupdocs.api_server =
|
46
|
+
#Optionally specify API server and version
|
47
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
45
48
|
end
|
46
|
-
|
47
|
-
#
|
49
|
+
file = nil
|
50
|
+
#Get document by file GUID
|
48
51
|
case settings.source
|
49
52
|
when 'guid'
|
50
|
-
#
|
53
|
+
#Create instance of File
|
51
54
|
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
52
55
|
when 'local'
|
53
|
-
#
|
56
|
+
#Construct path
|
54
57
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
55
|
-
#
|
58
|
+
#Open file
|
56
59
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
57
|
-
#
|
60
|
+
#Make a request to API using client_id and private_key
|
58
61
|
file = GroupDocs::Storage::File.upload!(file_path, {})
|
59
62
|
when 'url'
|
60
|
-
#
|
63
|
+
#Upload file from defined url
|
61
64
|
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
62
65
|
else
|
63
66
|
raise 'Wrong GUID source.'
|
@@ -69,53 +72,58 @@ post '/sample38' do
|
|
69
72
|
users = user.users!
|
70
73
|
users.map do |user|
|
71
74
|
email = user.primary_email
|
72
|
-
#
|
75
|
+
#Check whether there is a user with entered email
|
73
76
|
if settings.email == email
|
74
|
-
#
|
77
|
+
#Get user GUID
|
75
78
|
userGuid = user.guid
|
76
79
|
break
|
77
80
|
end
|
78
81
|
end
|
79
|
-
#
|
82
|
+
#Check is user with entered email was founded in GroupDocs account, if not user will be created
|
80
83
|
if userGuid.nil?
|
81
84
|
userNew = GroupDocs::User.new
|
82
|
-
#
|
85
|
+
#Set email as entered email
|
83
86
|
userNew.primary_email = settings.email
|
84
|
-
#
|
87
|
+
#Set nick name as entered first name
|
85
88
|
userNew.nickname = settings.email
|
86
|
-
#
|
89
|
+
#Set first name as entered first name
|
87
90
|
userNew.firstname = settings.first_name
|
88
|
-
#
|
91
|
+
#Set last name as entered last name
|
89
92
|
userNew.lastname = settings.last_name
|
90
|
-
#
|
93
|
+
#Set roles
|
91
94
|
userNew.roles = [{:id => '3', :name => 'User'}]
|
92
95
|
|
93
|
-
#
|
96
|
+
#Update account
|
94
97
|
new_user = GroupDocs::User.update_account!(userNew)
|
95
98
|
|
96
99
|
guid = new_user.guid
|
97
|
-
#
|
100
|
+
#Create array with entered email for set_collaborators! method
|
98
101
|
emails = [settings.email]
|
99
102
|
document = file.to_document
|
100
|
-
#
|
103
|
+
#Make request to Ant api for set new user as annotation collaborator
|
101
104
|
addCollaborator = document.set_collaborators!(emails)
|
102
105
|
getCollaborator = document.collaborators!
|
103
106
|
getCollaborator.each do |reviewer|
|
104
107
|
reviewer.access_rights = %w(view)
|
105
108
|
end
|
106
109
|
setReviewers = document.set_reviewers! getCollaborator
|
110
|
+
|
107
111
|
if setReviewers
|
108
|
-
|
112
|
+
#Add user GUID as "uid" parameter to the iframe URL
|
113
|
+
iframe = "/document-annotation2/embed/#{file.guid}?&uid=#{guid}&download=true"
|
114
|
+
# Construct result string
|
115
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
116
|
+
#Generate iframe URL
|
117
|
+
case base_path
|
109
118
|
when 'https://stage-api-groupdocs.dynabic.com'
|
110
|
-
iframe = "https://stage-api-groupdocs.dynabic.com
|
119
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
111
120
|
when 'https://dev-api-groupdocs.dynabic.com'
|
112
|
-
iframe = "https://dev-apps.groupdocs.com
|
121
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
113
122
|
else
|
114
|
-
iframe = "https://apps.groupdocs.com
|
123
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
115
124
|
end
|
116
|
-
|
117
|
-
|
118
|
-
iframe = "<iframe src='#{url}' width='800' height='1000'></iframe>"
|
125
|
+
|
126
|
+
iframe = "<iframe src='#{iframe}' width='800' height='1000'></iframe>"
|
119
127
|
end
|
120
128
|
end
|
121
129
|
|
@@ -123,6 +131,6 @@ post '/sample38' do
|
|
123
131
|
err = e.message
|
124
132
|
end
|
125
133
|
|
126
|
-
#
|
127
|
-
haml :sample38, :locals => {:userId => settings.client_id, :fileId =>
|
134
|
+
#Set variables for template
|
135
|
+
haml :sample38, :locals => {:userId => settings.client_id, :fileId => settings.file_id, :privateKey => settings.private_key, :iframe => iframe, :email => settings.email, :firstName => settings.first_name, :lastName => settings.last_name, :err => err}
|
128
136
|
end
|