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,43 +1,41 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample12' do
|
3
3
|
haml :sample12
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample12' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :file_id, params[:fileId]
|
12
12
|
set :base_path, params[:basePath]
|
13
13
|
|
14
14
|
begin
|
15
|
-
#
|
15
|
+
#Check required variables
|
16
16
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
|
17
17
|
|
18
|
-
|
18
|
+
#Prepare base path
|
19
|
+
if settings.base_path.empty?
|
20
|
+
base_path = 'https://api.groupdocs.com'
|
21
|
+
elsif settings.base_path.match('/v2.0')
|
22
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
23
|
+
else
|
24
|
+
base_path = settings.base_path
|
25
|
+
end
|
19
26
|
|
20
|
-
#
|
27
|
+
#Configure your access to API server
|
21
28
|
GroupDocs.configure do |groupdocs|
|
22
29
|
groupdocs.client_id = settings.client_id
|
23
30
|
groupdocs.private_key = settings.private_key
|
24
|
-
#
|
25
|
-
groupdocs.api_server =
|
26
|
-
end
|
27
|
-
|
28
|
-
# Make a request to API using client_id and private_key
|
29
|
-
files_list = GroupDocs::Storage::Folder.list!('/', {})
|
30
|
-
document = ''
|
31
|
-
|
32
|
-
# Get document by file ID
|
33
|
-
files_list.each do |element|
|
34
|
-
if element.respond_to?('guid') == true and element.guid == settings.file_id
|
35
|
-
document = element
|
36
|
-
end
|
31
|
+
#Optionally specify API server and version
|
32
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
37
33
|
end
|
38
34
|
|
35
|
+
#Create document object
|
36
|
+
document = GroupDocs::Storage::File.new(guid: settings.file_id)
|
39
37
|
unless document.instance_of? String
|
40
|
-
#
|
38
|
+
#Get list of annotations
|
41
39
|
annotations = document.to_document.annotations!()
|
42
40
|
end
|
43
41
|
|
@@ -45,6 +43,6 @@ post '/sample12' do
|
|
45
43
|
err = e.message
|
46
44
|
end
|
47
45
|
|
48
|
-
#
|
46
|
+
#Set variables for template
|
49
47
|
haml :sample12, :locals => {:clientId => settings.client_id, :privateKey => settings.private_key, :annotations => annotations, :fileId => settings.file_id, :err => err}
|
50
48
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample13' do
|
3
3
|
haml :sample13
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample13' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :file_id, params[:fileId]
|
@@ -13,32 +13,30 @@ post '/sample13' do
|
|
13
13
|
set :base_path, params[:basePath]
|
14
14
|
|
15
15
|
begin
|
16
|
-
#
|
16
|
+
#Check required variables
|
17
17
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty? or settings.email.empty?
|
18
18
|
|
19
|
-
|
19
|
+
#Prepare base path
|
20
|
+
if settings.base_path.empty?
|
21
|
+
base_path = 'https://api.groupdocs.com'
|
22
|
+
elsif settings.base_path.match('/v2.0')
|
23
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
24
|
+
else
|
25
|
+
base_path = settings.base_path
|
26
|
+
end
|
20
27
|
|
21
|
-
#
|
28
|
+
#Configure your access to API server
|
22
29
|
GroupDocs.configure do |groupdocs|
|
23
30
|
groupdocs.client_id = settings.client_id
|
24
31
|
groupdocs.private_key = settings.private_key
|
25
|
-
#
|
26
|
-
groupdocs.api_server =
|
27
|
-
end
|
28
|
-
|
29
|
-
# Make a request to API using client_id and private_key
|
30
|
-
files_list = GroupDocs::Storage::Folder.list!('/', {})
|
31
|
-
document = ''
|
32
|
-
|
33
|
-
# Get document by file ID
|
34
|
-
files_list.each do |element|
|
35
|
-
if element.respond_to?('guid') == true and element.guid == settings.file_id
|
36
|
-
document = element
|
37
|
-
end
|
32
|
+
#Optionally specify API server and version
|
33
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
38
34
|
end
|
39
35
|
|
36
|
+
#Create document object
|
37
|
+
document = GroupDocs::Storage::File.new(guid: settings.file_id)
|
40
38
|
unless document.instance_of? String
|
41
|
-
#
|
39
|
+
#Add collaborator to doc with annotations
|
42
40
|
result = document.to_document.set_collaborators!(settings.email.split(' '), 1)
|
43
41
|
end
|
44
42
|
|
@@ -47,6 +45,6 @@ post '/sample13' do
|
|
47
45
|
err = e.message
|
48
46
|
end
|
49
47
|
|
50
|
-
#
|
48
|
+
#Set variables for template
|
51
49
|
haml :sample13, :locals => {:clientId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.file_id, :email => settings.email, :result => result, :err => err}
|
52
50
|
end
|
@@ -1,31 +1,38 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample14' do
|
3
3
|
haml :sample14
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample14' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :folder, params[:path]
|
12
12
|
set :base_path, params[:basePath]
|
13
13
|
|
14
14
|
begin
|
15
|
-
#
|
15
|
+
#Check required variables
|
16
16
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.folder.empty?
|
17
17
|
|
18
|
-
|
18
|
+
#Prepare base path
|
19
|
+
if settings.base_path.empty?
|
20
|
+
base_path = 'https://api.groupdocs.com'
|
21
|
+
elsif settings.base_path.match('/v2.0')
|
22
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
23
|
+
else
|
24
|
+
base_path = settings.base_path
|
25
|
+
end
|
19
26
|
|
20
|
-
#
|
27
|
+
#Configure your access to API server
|
21
28
|
GroupDocs.configure do |groupdocs|
|
22
29
|
groupdocs.client_id = settings.client_id
|
23
30
|
groupdocs.private_key = settings.private_key
|
24
|
-
#
|
25
|
-
groupdocs.api_server =
|
31
|
+
#Optionally specify API server and version
|
32
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
26
33
|
end
|
27
34
|
folder = nil
|
28
|
-
#
|
35
|
+
#Make a request to API using client_id and private_key
|
29
36
|
files_list = GroupDocs::Storage::Folder.list!()
|
30
37
|
|
31
38
|
files_list.map do |e|
|
@@ -34,14 +41,13 @@ post '/sample14' do
|
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
37
|
-
|
38
|
-
# get list of shares for a folder
|
44
|
+
#Get list of shares for a folder
|
39
45
|
shares = folder.sharers!()
|
40
46
|
|
41
47
|
rescue Exception => e
|
42
48
|
err = e.message
|
43
49
|
end
|
44
50
|
|
45
|
-
#
|
51
|
+
#Set variables for template
|
46
52
|
haml :sample14, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :folder => settings.folder, :shares => shares, :err => err}
|
47
53
|
end
|
@@ -1,30 +1,37 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample15' do
|
3
3
|
haml :sample15
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample15' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :base_path, params[:basePath]
|
12
12
|
|
13
13
|
begin
|
14
|
-
#
|
14
|
+
#Check required variables
|
15
15
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
16
16
|
|
17
|
-
|
17
|
+
#Prepare base path
|
18
|
+
if settings.base_path.empty?
|
19
|
+
base_path = 'https://api.groupdocs.com'
|
20
|
+
elsif settings.base_path.match('/v2.0')
|
21
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
22
|
+
else
|
23
|
+
base_path = settings.base_path
|
24
|
+
end
|
18
25
|
|
19
|
-
#
|
26
|
+
#Configure your access to API server
|
20
27
|
GroupDocs.configure do |groupdocs|
|
21
28
|
groupdocs.client_id = settings.client_id
|
22
29
|
groupdocs.private_key = settings.private_key
|
23
|
-
#
|
24
|
-
groupdocs.api_server =
|
30
|
+
#Optionally specify API server and version
|
31
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
25
32
|
end
|
26
33
|
|
27
|
-
#
|
34
|
+
#Check the number of document's views. Make a request to API using client_id and private_key
|
28
35
|
views = GroupDocs::Document.views!({})
|
29
36
|
total = views.count()
|
30
37
|
|
@@ -32,6 +39,6 @@ post '/sample15' do
|
|
32
39
|
err = e.message
|
33
40
|
end
|
34
41
|
|
35
|
-
#
|
42
|
+
#Set variables for template
|
36
43
|
haml :sample15, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :total => total, :err => err}
|
37
44
|
end
|
@@ -1,43 +1,51 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample16' do
|
3
3
|
haml :sample16
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample16' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :fileId, params[:fileId]
|
10
10
|
set :base_path, params[:basePath]
|
11
11
|
|
12
12
|
begin
|
13
|
-
#
|
13
|
+
#Check required variables
|
14
14
|
raise 'Please enter all required parameters' if settings.fileId.empty?
|
15
15
|
|
16
|
-
|
16
|
+
#Prepare base path
|
17
|
+
if settings.base_path.empty?
|
18
|
+
base_path = 'https://api.groupdocs.com'
|
19
|
+
elsif settings.base_path.match('/v2.0')
|
20
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
21
|
+
else
|
22
|
+
base_path = settings.base_path
|
23
|
+
end
|
17
24
|
|
18
|
-
#
|
25
|
+
#Configure your access to API server
|
19
26
|
GroupDocs.configure do |groupdocs|
|
20
27
|
groupdocs.client_id = settings.client_id
|
21
28
|
groupdocs.private_key = settings.private_key
|
22
|
-
#
|
23
|
-
groupdocs.api_server =
|
29
|
+
#Optionally specify API server and version
|
30
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
24
31
|
end
|
25
32
|
|
26
|
-
|
33
|
+
#Prepare to sign url
|
34
|
+
iframe = "/assembly2/questionnaire-assembly/#{settings.fileId}"
|
35
|
+
# Construct result string
|
36
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
37
|
+
#Generate iframe URL
|
27
38
|
case settings.base_path
|
28
|
-
|
29
39
|
when 'https://stage-api-groupdocs.dynabic.com'
|
30
|
-
|
40
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
31
41
|
when 'https://dev-api-groupdocs.dynabic.com'
|
32
|
-
|
42
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
33
43
|
else
|
34
|
-
|
44
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
35
45
|
end
|
36
46
|
|
37
|
-
#
|
38
|
-
iframe =
|
39
|
-
# Construct result iframe
|
40
|
-
iframe = "<iframe src='#{iframe}' frameborder='0' width='100%' height='600'></iframe>"
|
47
|
+
#Make iframe
|
48
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
41
49
|
|
42
50
|
rescue Exception => e
|
43
51
|
err = e.message
|
@@ -1,57 +1,65 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample17' do
|
3
3
|
haml :sample17
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample17' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :file, params[:file]
|
12
12
|
set :base_path, params[:basePath]
|
13
13
|
|
14
14
|
begin
|
15
|
-
#
|
15
|
+
#Check required variables
|
16
16
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file.nil?
|
17
17
|
|
18
|
-
|
18
|
+
#Prepare base path
|
19
|
+
if settings.base_path.empty?
|
20
|
+
base_path = 'https://api.groupdocs.com'
|
21
|
+
elsif settings.base_path.match('/v2.0')
|
22
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
23
|
+
else
|
24
|
+
base_path = settings.base_path
|
25
|
+
end
|
19
26
|
|
20
|
-
#
|
27
|
+
#Configure your access to API server
|
21
28
|
GroupDocs.configure do |groupdocs|
|
22
29
|
groupdocs.client_id = settings.client_id
|
23
30
|
groupdocs.private_key = settings.private_key
|
24
|
-
#
|
25
|
-
groupdocs.api_server =
|
31
|
+
#Optionally specify API server and version
|
32
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
26
33
|
end
|
27
34
|
|
28
|
-
#
|
35
|
+
#Construct path
|
29
36
|
filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
30
|
-
#
|
37
|
+
#Open file
|
31
38
|
File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
32
|
-
#
|
39
|
+
#Upload file
|
33
40
|
file = GroupDocs::Storage::File.upload!(filepath, {})
|
34
|
-
#
|
41
|
+
#Compress file
|
35
42
|
file.compress!()
|
36
43
|
|
37
|
-
#
|
44
|
+
#Construct result messages
|
38
45
|
massage = "<p>Archive created and saved successfully. Here you can see your <strong>#{params[:file][:filename]}</strong> file in the GroupDocs Embedded Viewer.</p>"
|
39
46
|
|
40
|
-
#
|
41
|
-
|
42
|
-
|
47
|
+
#Prepare to sign url
|
48
|
+
iframe = "/document-viewer/embed/#{file.guid}"
|
49
|
+
# Construct result string
|
50
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
51
|
+
#Generate iframe URL
|
52
|
+
case base_path
|
43
53
|
when 'https://stage-api-groupdocs.dynabic.com'
|
44
|
-
|
54
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
45
55
|
when 'https://dev-api-groupdocs.dynabic.com'
|
46
|
-
|
56
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
47
57
|
else
|
48
|
-
|
58
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
49
59
|
end
|
50
60
|
|
51
|
-
#
|
52
|
-
iframe =
|
53
|
-
# Construct result iframe
|
54
|
-
iframe = "<iframe src='#{iframe}' frameborder='0' width='100%' height='600'></iframe>"
|
61
|
+
#Make iframe
|
62
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
55
63
|
|
56
64
|
rescue Exception => e
|
57
65
|
err = e.message
|
@@ -1,14 +1,14 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample18' do
|
3
3
|
haml :sample18
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample18/convert_callback' do
|
8
|
-
#
|
8
|
+
#Set download path
|
9
9
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
10
10
|
|
11
|
-
#
|
11
|
+
#Get callback request
|
12
12
|
data = JSON.parse(request.body.read)
|
13
13
|
begin
|
14
14
|
raise 'Empty params!' if data.empty?
|
@@ -16,14 +16,14 @@ post '/sample18/convert_callback' do
|
|
16
16
|
client_id = nil
|
17
17
|
private_key = nil
|
18
18
|
|
19
|
-
#
|
19
|
+
#Get value of SourceId
|
20
20
|
data.each do |key, value|
|
21
21
|
if key == 'SourceId'
|
22
22
|
source_id = value
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
26
|
+
#Get private key and client_id from file user_info.txt
|
27
27
|
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
28
28
|
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
29
29
|
contents = contents.split(' ')
|
@@ -31,13 +31,13 @@ post '/sample18/convert_callback' do
|
|
31
31
|
private_key = contents.last
|
32
32
|
end
|
33
33
|
|
34
|
-
#
|
34
|
+
#Create Job instance
|
35
35
|
job = GroupDocs::Job.new({:id => source_id})
|
36
36
|
|
37
|
-
#
|
37
|
+
#Get document by job id
|
38
38
|
documents = job.documents!({:client_id => client_id, :private_key => private_key})
|
39
39
|
|
40
|
-
#
|
40
|
+
#Download converted file
|
41
41
|
documents[:inputs].first.outputs.first.download!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
42
42
|
|
43
43
|
rescue Exception => e
|
@@ -46,15 +46,15 @@ post '/sample18/convert_callback' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
|
49
|
-
#
|
49
|
+
#GET request
|
50
50
|
get '/sample18/check' do
|
51
51
|
|
52
|
-
#
|
52
|
+
#Check is there download directory
|
53
53
|
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
54
54
|
return 'Directory was not found.'
|
55
55
|
end
|
56
56
|
|
57
|
-
#
|
57
|
+
#Get file name from download directory
|
58
58
|
name = nil
|
59
59
|
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
60
60
|
name = file if file != '.' && file != '..'
|
@@ -63,16 +63,16 @@ get '/sample18/check' do
|
|
63
63
|
name
|
64
64
|
end
|
65
65
|
|
66
|
-
#
|
66
|
+
#GET request
|
67
67
|
get '/sample18/downloads/:filename' do |filename|
|
68
68
|
# Send file with header to download it
|
69
69
|
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
70
70
|
end
|
71
71
|
|
72
72
|
|
73
|
-
#
|
73
|
+
#POST request
|
74
74
|
post '/sample18' do
|
75
|
-
#
|
75
|
+
#Set variables
|
76
76
|
set :client_id, params[:clientId]
|
77
77
|
set :private_key, params[:privateKey]
|
78
78
|
set :source, params[:source]
|
@@ -82,10 +82,10 @@ post '/sample18' do
|
|
82
82
|
set :callback, params[:callback]
|
83
83
|
set :base_path, params[:basePath]
|
84
84
|
|
85
|
-
#
|
85
|
+
#Set download path
|
86
86
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
87
87
|
|
88
|
-
#
|
88
|
+
#Remove all files from download directory or create folder if it not there
|
89
89
|
if File.directory?(downloads_path)
|
90
90
|
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
91
91
|
else
|
@@ -93,25 +93,30 @@ post '/sample18' do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
begin
|
96
|
-
#
|
96
|
+
#Check required variables
|
97
97
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
#Prepare base path
|
100
|
+
if settings.base_path.empty?
|
101
|
+
base_path = 'https://api.groupdocs.com'
|
102
|
+
elsif settings.base_path.match('/v2.0')
|
103
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
104
|
+
else
|
105
|
+
base_path = settings.base_path
|
101
106
|
end
|
102
107
|
|
103
|
-
#
|
108
|
+
#Configure your access to API server
|
104
109
|
GroupDocs.configure do |groupdocs|
|
105
110
|
groupdocs.client_id = settings.client_id
|
106
111
|
groupdocs.private_key = settings.private_key
|
107
|
-
#
|
108
|
-
groupdocs.api_server =
|
112
|
+
#Optionally specify API server and version
|
113
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
109
114
|
end
|
110
115
|
|
111
|
-
#
|
116
|
+
#Write client and private key to the file for callback job
|
112
117
|
if settings.callback[0]
|
113
118
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
114
|
-
#
|
119
|
+
#White space is required
|
115
120
|
out_file.write("#{settings.client_id} ")
|
116
121
|
out_file.write("#{settings.private_key}")
|
117
122
|
out_file.close
|
@@ -119,67 +124,67 @@ post '/sample18' do
|
|
119
124
|
|
120
125
|
file = nil
|
121
126
|
|
122
|
-
#
|
127
|
+
#Get document by file GUID
|
123
128
|
case settings.source
|
124
129
|
when 'guid'
|
125
|
-
#
|
130
|
+
#Create instance of File
|
126
131
|
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
127
132
|
when 'local'
|
128
|
-
#
|
133
|
+
#Construct path
|
129
134
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
130
|
-
#
|
135
|
+
#Open file
|
131
136
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
132
|
-
#
|
137
|
+
#Make a request to API using client_id and private_key
|
133
138
|
file = GroupDocs::Storage::File.upload!(file_path, {})
|
134
139
|
when 'url'
|
135
|
-
#
|
140
|
+
#Upload file from defined url
|
136
141
|
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
137
142
|
else
|
138
143
|
raise 'Wrong GUID source.'
|
139
144
|
end
|
140
145
|
|
141
|
-
#
|
146
|
+
#Raise exception if something went wrong
|
142
147
|
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
143
148
|
|
144
|
-
#
|
149
|
+
#Make document from file
|
145
150
|
document = file.to_document
|
146
|
-
#
|
151
|
+
#Convert document
|
147
152
|
convert = document.convert!(settings.convert_type, {:callback => settings.callback})
|
148
|
-
#
|
149
|
-
|
153
|
+
#Waite 15 seconds for while file converting
|
154
|
+
for i in 1..5
|
155
|
+
i+=1
|
156
|
+
sleep(2)
|
157
|
+
if GroupDocs::Job.get!(convert.id).status.to_s == 'archived' then break end
|
158
|
+
end
|
150
159
|
|
151
|
-
|
160
|
+
|
161
|
+
#Get array of changes in document from job
|
152
162
|
original_document = convert.documents!()
|
153
163
|
|
154
|
-
#
|
164
|
+
#Get converted document GUID
|
155
165
|
guid = original_document[:inputs].first.outputs.first.guid
|
156
166
|
|
157
|
-
#
|
158
|
-
|
159
|
-
|
167
|
+
#Prepare to sign url
|
168
|
+
iframe = "/document-viewer/embed/#{guid}"
|
169
|
+
# Construct result string
|
170
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
171
|
+
#Generate iframe URL
|
172
|
+
case base_path
|
160
173
|
when 'https://stage-api-groupdocs.dynabic.com'
|
161
|
-
|
174
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
162
175
|
when 'https://dev-api-groupdocs.dynabic.com'
|
163
|
-
|
176
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
164
177
|
else
|
165
|
-
|
178
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
166
179
|
end
|
167
180
|
|
168
|
-
|
169
|
-
|
170
|
-
if guid
|
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>"
|
175
|
-
else
|
176
|
-
raise 'File was not converted'
|
177
|
-
end
|
181
|
+
#Make iframe
|
182
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
178
183
|
|
179
184
|
rescue Exception => e
|
180
185
|
err = e.message
|
181
186
|
end
|
182
187
|
|
183
|
-
#
|
188
|
+
#Set variables for template
|
184
189
|
haml :sample18, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :callback => settings.callback, :fileId => file, :converted => guid, :iframe => iframe, :err => err}
|
185
190
|
end
|