groupdocs 1.5.7 → 1.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +51 -0
- data/examples/api-samples/Gemfile +1 -1
- data/examples/api-samples/Gemfile.lock +43 -0
- data/examples/api-samples/public/docs/{sample2.html → sample01.html} +39 -19
- data/examples/api-samples/public/docs/{sample3.html → sample02.html} +28 -22
- data/examples/api-samples/public/docs/sample03.html +285 -0
- data/examples/api-samples/public/docs/{sample4.html → sample04.html} +30 -36
- data/examples/api-samples/public/docs/{sample5.html → sample05.html} +68 -31
- data/examples/api-samples/public/docs/sample06.html +299 -0
- data/examples/api-samples/public/docs/{sample7.html → sample07.html} +53 -18
- data/examples/api-samples/public/docs/{sample8.html → sample08.html} +64 -41
- data/examples/api-samples/public/docs/sample09.html +260 -0
- data/examples/api-samples/public/docs/sample10.html +67 -28
- data/examples/api-samples/public/docs/sample11.html +171 -55
- data/examples/api-samples/public/docs/sample12.html +53 -17
- data/examples/api-samples/public/docs/sample13.html +52 -16
- data/examples/api-samples/public/docs/sample14.html +51 -8
- data/examples/api-samples/public/docs/sample15.html +46 -10
- data/examples/api-samples/public/docs/sample16.html +81 -7
- data/examples/api-samples/public/docs/sample17.html +103 -15
- data/examples/api-samples/public/docs/sample18.html +117 -41
- data/examples/api-samples/public/docs/sample19.html +410 -36
- data/examples/api-samples/public/docs/sample20.html +46 -10
- data/examples/api-samples/public/docs/sample21.html +504 -45
- data/examples/api-samples/public/docs/sample22.html +166 -28
- data/examples/api-samples/public/docs/sample23.html +61 -25
- data/examples/api-samples/public/docs/sample24.html +100 -12
- data/examples/api-samples/public/docs/sample25.html +123 -49
- data/examples/api-samples/public/docs/sample26.html +41 -8
- data/examples/api-samples/public/docs/sample27.html +125 -50
- data/examples/api-samples/public/docs/sample28.html +27 -9
- data/examples/api-samples/public/docs/sample29.html +10 -10
- data/examples/api-samples/public/docs/sample30.html +70 -14
- data/examples/api-samples/public/docs/sample31.html +108 -67
- data/examples/api-samples/public/docs/sample32.html +71 -99
- data/examples/api-samples/public/docs/sample33.html +107 -32
- data/examples/api-samples/public/docs/{sample1.html → sample34.html} +58 -18
- data/examples/api-samples/public/docs/sample35.html +666 -0
- data/examples/api-samples/public/docs/{sample6.html → sample36.html} +56 -37
- data/examples/api-samples/public/docs/sample37.html +815 -0
- data/examples/api-samples/public/docs/sample38.html +508 -0
- data/examples/api-samples/public/docs/sample39.html +921 -0
- data/examples/api-samples/public/docs/sample40.html +510 -0
- data/examples/api-samples/public/docs/sample41.html +452 -0
- data/examples/api-samples/public/docs/sample42.html +311 -0
- data/examples/api-samples/public/templates/test_all_fields2.pdf +0 -0
- data/examples/api-samples/samples/sample01.rb +37 -0
- data/examples/api-samples/samples/sample02.rb +41 -0
- data/examples/api-samples/samples/sample03.rb +73 -0
- data/examples/api-samples/samples/sample04.rb +47 -0
- data/examples/api-samples/samples/{sample5.rb → sample05.rb} +26 -14
- data/examples/api-samples/samples/sample06.rb +80 -0
- data/examples/api-samples/samples/sample07.rb +52 -0
- data/examples/api-samples/samples/sample08.rb +69 -0
- data/examples/api-samples/samples/sample09.rb +83 -0
- data/examples/api-samples/samples/sample10.rb +29 -15
- data/examples/api-samples/samples/sample11.rb +89 -37
- data/examples/api-samples/samples/sample12.rb +22 -11
- data/examples/api-samples/samples/sample13.rb +22 -10
- data/examples/api-samples/samples/sample14.rb +23 -5
- data/examples/api-samples/samples/sample15.rb +18 -7
- data/examples/api-samples/samples/sample16.rb +28 -4
- data/examples/api-samples/samples/sample17.rb +31 -5
- data/examples/api-samples/samples/sample18.rb +36 -8
- data/examples/api-samples/samples/sample19.rb +138 -18
- data/examples/api-samples/samples/sample20.rb +14 -3
- data/examples/api-samples/samples/sample21.rb +162 -23
- data/examples/api-samples/samples/sample22.rb +73 -22
- data/examples/api-samples/samples/sample23.rb +17 -6
- data/examples/api-samples/samples/sample24.rb +34 -7
- data/examples/api-samples/samples/sample25.rb +37 -12
- data/examples/api-samples/samples/sample26.rb +12 -5
- data/examples/api-samples/samples/sample27.rb +38 -12
- data/examples/api-samples/samples/sample28.rb +25 -6
- data/examples/api-samples/samples/sample29.rb +12 -12
- data/examples/api-samples/samples/sample30.rb +27 -15
- data/examples/api-samples/samples/sample31.rb +44 -33
- data/examples/api-samples/samples/sample32.rb +43 -41
- data/examples/api-samples/samples/sample33.rb +42 -14
- data/examples/api-samples/samples/sample34.rb +40 -0
- data/examples/api-samples/samples/sample35.rb +224 -0
- data/examples/api-samples/samples/sample36.rb +58 -0
- data/examples/api-samples/samples/sample37.rb +229 -0
- data/examples/api-samples/samples/sample38.rb +128 -0
- data/examples/api-samples/samples/sample39.rb +252 -0
- data/examples/api-samples/samples/sample40.rb +164 -0
- data/examples/api-samples/samples/sample41.rb +118 -0
- data/examples/api-samples/samples/sample42.rb +97 -0
- data/examples/api-samples/views/_others_samples.haml +25 -11
- data/examples/api-samples/views/index.haml +23 -11
- data/examples/api-samples/views/popup.haml +32 -0
- data/examples/api-samples/views/{sample1.haml → sample01.haml} +12 -7
- data/examples/api-samples/views/{sample2.haml → sample02.haml} +20 -15
- data/examples/api-samples/views/sample03.haml +83 -0
- data/examples/api-samples/views/sample04.haml +49 -0
- data/examples/api-samples/views/{sample5.haml → sample05.haml} +19 -14
- data/examples/api-samples/views/sample06.haml +53 -0
- data/examples/api-samples/views/sample07.haml +47 -0
- data/examples/api-samples/views/{sample8.haml → sample08.haml} +17 -12
- data/examples/api-samples/views/{sample9.haml → sample09.haml} +19 -4
- data/examples/api-samples/views/sample10.haml +18 -13
- data/examples/api-samples/views/sample11.haml +48 -19
- data/examples/api-samples/views/sample12.haml +26 -21
- data/examples/api-samples/views/sample13.haml +18 -12
- data/examples/api-samples/views/sample14.haml +21 -15
- data/examples/api-samples/views/sample15.haml +16 -9
- data/examples/api-samples/views/sample16.haml +18 -5
- data/examples/api-samples/views/sample17.haml +14 -9
- data/examples/api-samples/views/sample18.haml +13 -7
- data/examples/api-samples/views/sample19.haml +37 -8
- data/examples/api-samples/views/sample20.haml +13 -8
- data/examples/api-samples/views/sample21.haml +71 -13
- data/examples/api-samples/views/sample22.haml +53 -16
- data/examples/api-samples/views/sample23.haml +9 -4
- data/examples/api-samples/views/sample24.haml +9 -4
- data/examples/api-samples/views/sample25.haml +18 -13
- data/examples/api-samples/views/sample26.haml +8 -3
- data/examples/api-samples/views/sample27.haml +20 -14
- data/examples/api-samples/views/sample28.haml +16 -10
- data/examples/api-samples/views/sample29.haml +4 -4
- data/examples/api-samples/views/sample30.haml +16 -10
- data/examples/api-samples/views/sample31.haml +39 -32
- data/examples/api-samples/views/sample32.haml +25 -36
- data/examples/api-samples/views/sample33.haml +14 -17
- data/examples/api-samples/views/sample34.haml +48 -0
- data/examples/api-samples/views/sample35.haml +95 -0
- data/examples/api-samples/views/sample36.haml +64 -0
- data/examples/api-samples/views/sample37.haml +124 -0
- data/examples/api-samples/views/sample38.haml +115 -0
- data/examples/api-samples/views/sample39.haml +236 -0
- data/examples/api-samples/views/sample40.haml +95 -0
- data/examples/api-samples/views/{sample4.haml → sample41.haml} +90 -72
- data/examples/api-samples/views/sample42.haml +59 -0
- data/lib/groupdocs/api/helpers/rest_helper.rb +13 -1
- data/lib/groupdocs/datasource.rb +2 -1
- data/lib/groupdocs/document.rb +101 -13
- data/lib/groupdocs/document/annotation.rb +28 -13
- data/lib/groupdocs/document/annotation/marker.rb +18 -0
- data/lib/groupdocs/document/annotation/reply.rb +9 -2
- data/lib/groupdocs/document/field.rb +5 -1
- data/lib/groupdocs/job.rb +12 -2
- data/lib/groupdocs/questionnaire.rb +174 -4
- data/lib/groupdocs/questionnaire/collector.rb +21 -0
- data/lib/groupdocs/questionnaire/question.rb +19 -0
- data/lib/groupdocs/questionnaire/question/answer.rb +5 -0
- data/lib/groupdocs/questionnaire/question/conditions.rb +20 -0
- data/lib/groupdocs/signature.rb +36 -308
- data/lib/groupdocs/signature/envelope.rb +146 -4
- data/lib/groupdocs/signature/field.rb +20 -1
- data/lib/groupdocs/signature/field/location.rb +18 -7
- data/lib/groupdocs/signature/form.rb +199 -10
- data/lib/groupdocs/signature/shared/document_methods.rb +38 -0
- data/lib/groupdocs/signature/shared/entity_methods.rb +0 -1
- data/lib/groupdocs/signature/shared/field_methods.rb +13 -38
- data/lib/groupdocs/signature/shared/recipient_methods.rb +8 -0
- data/lib/groupdocs/signature/template.rb +3 -1
- data/lib/groupdocs/storage.rb +4 -1
- data/lib/groupdocs/storage/file.rb +18 -1
- data/lib/groupdocs/subscription.rb +8 -3
- data/lib/groupdocs/user.rb +8 -0
- data/lib/groupdocs/version.rb +1 -1
- data/spec/groupdocs/document/annotation_spec.rb +1 -14
- data/spec/groupdocs/subscription_spec.rb +2 -2
- metadata +86 -32
- checksums.yaml +0 -15
- data/examples/api-samples/public/docs/sample9.html +0 -200
- data/examples/api-samples/samples/sample1.rb +0 -25
- data/examples/api-samples/samples/sample2.rb +0 -29
- data/examples/api-samples/samples/sample3.rb +0 -33
- data/examples/api-samples/samples/sample4.rb +0 -51
- data/examples/api-samples/samples/sample6.rb +0 -49
- data/examples/api-samples/samples/sample7.rb +0 -42
- data/examples/api-samples/samples/sample8.rb +0 -61
- data/examples/api-samples/samples/sample9.rb +0 -48
- data/examples/api-samples/views/sample3.haml +0 -44
- data/examples/api-samples/views/sample6.haml +0 -49
- data/examples/api-samples/views/sample7.haml +0 -42
@@ -5,22 +5,33 @@ end
|
|
5
5
|
|
6
6
|
# POST request
|
7
7
|
post '/sample15' do
|
8
|
-
#
|
9
|
-
set :client_id, params[:
|
10
|
-
set :private_key, params[:
|
8
|
+
# Set variables
|
9
|
+
set :client_id, params[:clientId]
|
10
|
+
set :private_key, params[:privateKey]
|
11
|
+
set :base_path, params[:basePath]
|
11
12
|
|
12
13
|
begin
|
13
|
-
#
|
14
|
+
# Check required variables
|
14
15
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
18
|
+
|
19
|
+
# Configure your access to API server
|
20
|
+
GroupDocs.configure do |groupdocs|
|
21
|
+
groupdocs.client_id = settings.client_id
|
22
|
+
groupdocs.private_key = settings.private_key
|
23
|
+
# Optionally specify API server and version
|
24
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Check the number of document's views. Make a request to API using client_id and private_key
|
28
|
+
views = GroupDocs::Document.views!({})
|
18
29
|
total = views.count()
|
19
30
|
|
20
31
|
rescue Exception => e
|
21
32
|
err = e.message
|
22
33
|
end
|
23
34
|
|
24
|
-
#
|
35
|
+
# Set variables for template
|
25
36
|
haml :sample15, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :total => total, :err => err}
|
26
37
|
end
|
@@ -5,15 +5,39 @@ end
|
|
5
5
|
|
6
6
|
# POST request
|
7
7
|
post '/sample16' do
|
8
|
-
#
|
8
|
+
# Set variables
|
9
9
|
set :fileId, params[:fileId]
|
10
|
+
set :base_path, params[:basePath]
|
10
11
|
|
11
12
|
begin
|
12
|
-
#
|
13
|
+
# Check required variables
|
13
14
|
raise 'Please enter all required parameters' if settings.fileId.empty?
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
17
|
+
|
18
|
+
# Configure your access to API server
|
19
|
+
GroupDocs.configure do |groupdocs|
|
20
|
+
groupdocs.client_id = settings.client_id
|
21
|
+
groupdocs.private_key = settings.private_key
|
22
|
+
# Optionally specify API server and version
|
23
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
24
|
+
end
|
25
|
+
|
26
|
+
#Get url from request
|
27
|
+
case settings.base_path
|
28
|
+
|
29
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
30
|
+
url = "http://stage-apps-groupdocs.dynabic.com/assembly2/questionnaire-assembly/#{settings.fileId}"
|
31
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
32
|
+
url = "http://dev-apps-groupdocs.dynabic.com/assembly2/questionnaire-assembly/#{settings.fileId}"
|
33
|
+
else
|
34
|
+
url = "https://apps.groupdocs.com/assembly2/questionnaire-assembly/#{settings.fileId}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Add the signature to the url request
|
38
|
+
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
39
|
+
# Construct result iframe
|
40
|
+
iframe = "<iframe src='#{iframe}' frameborder='0' width='100%' height='600'></iframe>"
|
17
41
|
|
18
42
|
rescue Exception => e
|
19
43
|
err = e.message
|
@@ -6,26 +6,52 @@ end
|
|
6
6
|
# POST request
|
7
7
|
post '/sample17' do
|
8
8
|
# set variables
|
9
|
-
set :client_id, params[:
|
10
|
-
set :private_key, params[:
|
9
|
+
set :client_id, params[:clientId]
|
10
|
+
set :private_key, params[:privateKey]
|
11
11
|
set :file, params[:file]
|
12
|
+
set :base_path, params[:basePath]
|
12
13
|
|
13
14
|
begin
|
14
15
|
# check required variables
|
15
16
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file.nil?
|
16
17
|
|
18
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
19
|
+
|
20
|
+
# Configure your access to API server
|
21
|
+
GroupDocs.configure do |groupdocs|
|
22
|
+
groupdocs.client_id = settings.client_id
|
23
|
+
groupdocs.private_key = settings.private_key
|
24
|
+
# Optionally specify API server and version
|
25
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
26
|
+
end
|
27
|
+
|
17
28
|
# construct path
|
18
29
|
filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
19
30
|
# open file
|
20
31
|
File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
21
32
|
# upload file
|
22
|
-
file = GroupDocs::Storage::File.upload!(filepath, {}
|
33
|
+
file = GroupDocs::Storage::File.upload!(filepath, {})
|
23
34
|
# compress file
|
24
|
-
file.compress!(
|
35
|
+
file.compress!()
|
25
36
|
|
26
37
|
# construct result messages
|
27
38
|
massage = "<p>Archive created and saved successfully. Here you can see your <strong>#{params[:file][:filename]}</strong> file in the GroupDocs Embedded Viewer.</p>"
|
28
|
-
|
39
|
+
|
40
|
+
#Get url from request
|
41
|
+
case settings.base_path
|
42
|
+
|
43
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
44
|
+
url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{file.guid}"
|
45
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
46
|
+
url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{file.guid}"
|
47
|
+
else
|
48
|
+
url = "https://apps.groupdocs.com/document-viewer/embed/#{file.guid}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Add the signature to the url request
|
52
|
+
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
53
|
+
# Construct result iframe
|
54
|
+
iframe = "<iframe src='#{iframe}' frameborder='0' width='100%' height='600'></iframe>"
|
29
55
|
|
30
56
|
rescue Exception => e
|
31
57
|
err = e.message
|
@@ -73,13 +73,14 @@ end
|
|
73
73
|
# POST request
|
74
74
|
post '/sample18' do
|
75
75
|
# set variables
|
76
|
-
set :client_id, params[:
|
77
|
-
set :private_key, params[:
|
76
|
+
set :client_id, params[:clientId]
|
77
|
+
set :private_key, params[:privateKey]
|
78
78
|
set :source, params[:source]
|
79
79
|
set :file_id, params[:fileId]
|
80
80
|
set :url, params[:url]
|
81
|
-
set :convert_type, params[:
|
81
|
+
set :convert_type, params[:convertType]
|
82
82
|
set :callback, params[:callback]
|
83
|
+
set :base_path, params[:basePath]
|
83
84
|
|
84
85
|
# Set download path
|
85
86
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
@@ -95,6 +96,18 @@ post '/sample18' do
|
|
95
96
|
# check required variables
|
96
97
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
97
98
|
|
99
|
+
if settings.base_path.empty? then
|
100
|
+
settings.base_path = 'https://api.groupdocs.com'
|
101
|
+
end
|
102
|
+
|
103
|
+
# Configure your access to API server
|
104
|
+
GroupDocs.configure do |groupdocs|
|
105
|
+
groupdocs.client_id = settings.client_id
|
106
|
+
groupdocs.private_key = settings.private_key
|
107
|
+
# Optionally specify API server and version
|
108
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
109
|
+
end
|
110
|
+
|
98
111
|
# Write client and private key to the file for callback job
|
99
112
|
if settings.callback[0]
|
100
113
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
@@ -117,10 +130,10 @@ post '/sample18' do
|
|
117
130
|
# open file
|
118
131
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
119
132
|
# make a request to API using client_id and private_key
|
120
|
-
file = GroupDocs::Storage::File.upload!(file_path, {}
|
133
|
+
file = GroupDocs::Storage::File.upload!(file_path, {})
|
121
134
|
when 'url'
|
122
135
|
# Upload file from defined url
|
123
|
-
file = GroupDocs::Storage::File.upload_web!(settings.url
|
136
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
124
137
|
else
|
125
138
|
raise 'Wrong GUID source.'
|
126
139
|
end
|
@@ -131,19 +144,34 @@ post '/sample18' do
|
|
131
144
|
# Make document from file
|
132
145
|
document = file.to_document
|
133
146
|
# convert document
|
134
|
-
convert = document.convert!(settings.convert_type, {:callback => settings.callback}
|
147
|
+
convert = document.convert!(settings.convert_type, {:callback => settings.callback})
|
135
148
|
# waite 10 seconds for while file converting
|
136
149
|
sleep(10)
|
137
150
|
|
138
151
|
# Get array of changes in document from job
|
139
|
-
original_document = convert.documents!(
|
152
|
+
original_document = convert.documents!()
|
140
153
|
|
141
154
|
# Get converted document GUID
|
142
155
|
guid = original_document[:inputs].first.outputs.first.guid
|
143
156
|
|
157
|
+
#Get url from request
|
158
|
+
case settings.base_path
|
159
|
+
|
160
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
161
|
+
url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
|
162
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
163
|
+
url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
|
164
|
+
else
|
165
|
+
url = "https://apps.groupdocs.com/document-viewer/embed/#{guid}"
|
166
|
+
end
|
167
|
+
|
168
|
+
|
144
169
|
# Set iframe with document GUID or raise an error
|
145
170
|
if guid
|
146
|
-
|
171
|
+
|
172
|
+
# Add the signature to url request
|
173
|
+
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
174
|
+
iframe = "<iframe width='100%' height='600' frameborder='0' src='#{iframe}'></iframe>"
|
147
175
|
else
|
148
176
|
raise 'File was not converted'
|
149
177
|
end
|
@@ -3,26 +3,122 @@ get '/sample19' do
|
|
3
3
|
haml :sample19
|
4
4
|
end
|
5
5
|
|
6
|
+
# POST request
|
7
|
+
post '/sample19/compere_callback' do
|
8
|
+
# Set download path
|
9
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
10
|
+
|
11
|
+
# Get callback request
|
12
|
+
data = JSON.parse(request.body.read)
|
13
|
+
begin
|
14
|
+
raise 'Empty params!' if data.empty?
|
15
|
+
source_id = nil
|
16
|
+
client_id = nil
|
17
|
+
private_key = nil
|
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.first
|
31
|
+
private_key = contents.last
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create Job instance
|
35
|
+
job = GroupDocs::Job.new({:id => source_id})
|
36
|
+
|
37
|
+
# Get document by job id
|
38
|
+
documents = job.documents!({:client_id => client_id, :private_key => private_key})
|
39
|
+
|
40
|
+
# Download converted file
|
41
|
+
documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
|
+
|
43
|
+
rescue Exception => e
|
44
|
+
err = e.message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# GET request
|
49
|
+
get '/sample19/check' do
|
50
|
+
|
51
|
+
# Check is there download directory
|
52
|
+
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
53
|
+
return 'Directory was not found.'
|
54
|
+
end
|
55
|
+
|
56
|
+
# Get file name from download directory
|
57
|
+
name = nil
|
58
|
+
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
59
|
+
name = file if file != '.' && file != '..'
|
60
|
+
end
|
61
|
+
|
62
|
+
name
|
63
|
+
end
|
64
|
+
|
65
|
+
# GET request
|
66
|
+
get '/sample19/downloads/:filename' do |filename|
|
67
|
+
# Send file with header to download it
|
68
|
+
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
69
|
+
end
|
70
|
+
|
6
71
|
# POST request
|
7
72
|
post '/sample19' do
|
8
|
-
#
|
9
|
-
set :client_id, params[:
|
10
|
-
set :private_key, params[:
|
73
|
+
# Set variables
|
74
|
+
set :client_id, params[:clientId]
|
75
|
+
set :private_key, params[:privateKey]
|
11
76
|
set :sourceFileId, params[:sourceFileId]
|
12
77
|
set :targetFileId, params[:targetFileId]
|
13
|
-
set :
|
78
|
+
set :callback, params[:callback]
|
79
|
+
set :base_path, params[:basePath]
|
80
|
+
|
81
|
+
# Set download path
|
82
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
83
|
+
|
84
|
+
# Remove all files from download directory or create folder if it not there
|
85
|
+
if File.directory?(downloads_path)
|
86
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
87
|
+
else
|
88
|
+
Dir::mkdir(downloads_path)
|
89
|
+
end
|
14
90
|
|
15
91
|
begin
|
16
|
-
|
92
|
+
|
93
|
+
# Check required variables
|
17
94
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.sourceFileId.empty? or settings.targetFileId.empty?
|
18
95
|
|
19
|
-
|
20
|
-
|
96
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
97
|
+
|
98
|
+
# Configure your access to API server
|
99
|
+
GroupDocs.configure do |groupdocs|
|
100
|
+
groupdocs.client_id = settings.client_id
|
101
|
+
groupdocs.private_key = settings.private_key
|
102
|
+
# Optionally specify API server and version
|
103
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
104
|
+
end
|
105
|
+
|
106
|
+
# Write client and private key to the file for callback job
|
107
|
+
if settings.callback
|
108
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
109
|
+
# white space is required
|
110
|
+
out_file.write("#{settings.client_id} ")
|
111
|
+
out_file.write("#{settings.private_key}")
|
112
|
+
out_file.close
|
113
|
+
end
|
114
|
+
|
115
|
+
# Make a request to API using client_id and private_key
|
116
|
+
files_list = GroupDocs::Storage::Folder.list!('/', {})
|
21
117
|
|
22
118
|
source_document = ''
|
23
119
|
target_document = ''
|
24
120
|
|
25
|
-
#
|
121
|
+
# Get source and target documents by file ID
|
26
122
|
files_list.each do |element|
|
27
123
|
if element.respond_to?('guid') == true and element.guid == settings.sourceFileId
|
28
124
|
source_document = element
|
@@ -32,20 +128,44 @@ post '/sample19' do
|
|
32
128
|
end
|
33
129
|
end
|
34
130
|
|
131
|
+
|
35
132
|
unless source_document.instance_of? String and target_document.instance_of? String
|
36
133
|
|
37
|
-
info = source_document.to_document.compare!(target_document.to_document,
|
38
|
-
|
134
|
+
info = source_document.to_document.compare!(target_document.to_document, settings.callback)
|
135
|
+
|
136
|
+
i = 0
|
137
|
+
|
138
|
+
while i<5 do
|
139
|
+
sleep(5)
|
140
|
+
job = GroupDocs::Job.get!(info.id)
|
141
|
+
break if job.status == :archived
|
142
|
+
i += 1
|
143
|
+
end
|
39
144
|
|
40
|
-
|
145
|
+
|
146
|
+
# Get job by ID
|
41
147
|
job = GroupDocs::Job.new(id: info.id)
|
42
|
-
|
43
|
-
|
44
|
-
|
148
|
+
|
149
|
+
# Get all job documents
|
150
|
+
documents = job.documents!()
|
151
|
+
# Get compared file giud
|
45
152
|
guid = documents[:outputs].first.file.guid
|
46
153
|
|
47
|
-
#
|
48
|
-
|
154
|
+
#Get url from request
|
155
|
+
case settings.base_path
|
156
|
+
|
157
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
158
|
+
url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
|
159
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
160
|
+
url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{guid}"
|
161
|
+
else
|
162
|
+
url = "https://apps.groupdocs.com/document-viewer/embed/#{guid}"
|
163
|
+
end
|
164
|
+
|
165
|
+
# Add the signature to url request
|
166
|
+
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
167
|
+
# Construct result iframe
|
168
|
+
iframe = "<iframe src='#{iframe}' frameborder='0' width='100%' height='600'></iframe>"
|
49
169
|
|
50
170
|
end
|
51
171
|
|
@@ -53,6 +173,6 @@ post '/sample19' do
|
|
53
173
|
err = e.message
|
54
174
|
end
|
55
175
|
|
56
|
-
#
|
57
|
-
haml :sample19, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sourceFileId => settings.sourceFileId, :targetFileId => settings.targetFileId, :
|
176
|
+
# Set variables for template
|
177
|
+
haml :sample19, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sourceFileId => settings.sourceFileId, :targetFileId => settings.targetFileId, :callback => settings.callback, :iframe => iframe, :err => err}
|
58
178
|
end
|
@@ -6,21 +6,32 @@ end
|
|
6
6
|
# POST request
|
7
7
|
post '/sample20' do
|
8
8
|
# set variables
|
9
|
-
set :client_id, params[:
|
10
|
-
set :private_key, params[:
|
9
|
+
set :client_id, params[:clientId]
|
10
|
+
set :private_key, params[:privateKey]
|
11
11
|
set :resultFileId, params[:resultFileId]
|
12
|
+
set :base_path, params[:basePath]
|
12
13
|
|
13
14
|
begin
|
14
15
|
|
15
16
|
# check required variables
|
16
17
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.resultFileId.empty?
|
17
18
|
|
19
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
20
|
+
|
21
|
+
# Configure your access to API server
|
22
|
+
GroupDocs.configure do |groupdocs|
|
23
|
+
groupdocs.client_id = settings.client_id
|
24
|
+
groupdocs.private_key = settings.private_key
|
25
|
+
# Optionally specify API server and version
|
26
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
27
|
+
end
|
28
|
+
|
18
29
|
# construct new storage file
|
19
30
|
file = GroupDocs::Storage::File.new(guid: settings.resultFileId)
|
20
31
|
# construct new document
|
21
32
|
document = GroupDocs::Document.new(file: file)
|
22
33
|
# get compare changes
|
23
|
-
changes = document.changes!(
|
34
|
+
changes = document.changes!()
|
24
35
|
|
25
36
|
result = ''
|
26
37
|
result += "<table class='border'>"
|