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,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
#GET request
|
|
2
2
|
get '/sample22' do
|
|
3
3
|
haml :sample22
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
#POST request
|
|
7
7
|
post '/sample22' do
|
|
8
|
-
#
|
|
8
|
+
#Set variables
|
|
9
9
|
set :client_id, params[:clientId]
|
|
10
10
|
set :private_key, params[:privateKey]
|
|
11
11
|
set :fileId, params[:fileId]
|
|
@@ -19,33 +19,40 @@ post '/sample22' do
|
|
|
19
19
|
|
|
20
20
|
begin
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
#Check required variables
|
|
23
23
|
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?
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
#Prepare base path
|
|
26
|
+
if settings.base_path.empty?
|
|
27
|
+
base_path = 'https://api.groupdocs.com'
|
|
28
|
+
elsif settings.base_path.match('/v2.0')
|
|
29
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
|
30
|
+
else
|
|
31
|
+
base_path = settings.base_path
|
|
32
|
+
end
|
|
26
33
|
|
|
27
|
-
#
|
|
34
|
+
#Configure your access to API server
|
|
28
35
|
GroupDocs.configure do |groupdocs|
|
|
29
36
|
groupdocs.client_id = settings.client_id
|
|
30
37
|
groupdocs.private_key = settings.private_key
|
|
31
|
-
#
|
|
32
|
-
groupdocs.api_server =
|
|
38
|
+
#Optionally specify API server and version
|
|
39
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
|
33
40
|
end
|
|
34
41
|
file = nil
|
|
35
42
|
|
|
36
|
-
#
|
|
43
|
+
#Get document by file GUID
|
|
37
44
|
case settings.source
|
|
38
45
|
when 'guid'
|
|
39
|
-
#
|
|
46
|
+
#Create instance of File
|
|
40
47
|
file = GroupDocs::Storage::File.new({:guid => settings.fileId})
|
|
41
48
|
when 'local'
|
|
42
49
|
filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
43
|
-
#
|
|
50
|
+
#Open file
|
|
44
51
|
File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
45
|
-
#
|
|
52
|
+
#Make a request to API using client_id and private_key
|
|
46
53
|
file = GroupDocs::Storage::File.upload!(filepath, {})
|
|
47
54
|
when 'url'
|
|
48
|
-
#
|
|
55
|
+
#Upload file from defined url
|
|
49
56
|
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
|
50
57
|
else
|
|
51
58
|
raise 'Wrong GUID source.'
|
|
@@ -53,7 +60,7 @@ post '/sample22' do
|
|
|
53
60
|
|
|
54
61
|
|
|
55
62
|
file = file.to_document
|
|
56
|
-
#
|
|
63
|
+
#Create new user
|
|
57
64
|
user = GroupDocs::User.new
|
|
58
65
|
|
|
59
66
|
user.primary_email = settings.email
|
|
@@ -62,42 +69,41 @@ post '/sample22' do
|
|
|
62
69
|
user.last_name = settings.last_name
|
|
63
70
|
|
|
64
71
|
user.roles = [{:id => '3', :name => 'User'}]
|
|
65
|
-
#
|
|
72
|
+
#Update account
|
|
66
73
|
new_user = GroupDocs::User.update_account!(user)
|
|
67
74
|
|
|
68
75
|
|
|
69
76
|
|
|
70
|
-
#
|
|
77
|
+
#Set new collaboration
|
|
71
78
|
file.set_collaborators!([settings.email], 2)
|
|
72
79
|
|
|
73
|
-
#
|
|
80
|
+
#Get all collaborations
|
|
74
81
|
collaborations = file.collaborators!()
|
|
75
82
|
|
|
76
|
-
#
|
|
83
|
+
#Set document reviewers
|
|
77
84
|
file.set_reviewers!(collaborations)
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
#Prepare to sign url
|
|
87
|
+
iframe = "/document-annotation2/embed/#{file.file.guid}?uid = #{new_user.guid}&download=true"
|
|
88
|
+
# Construct result string
|
|
89
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
|
90
|
+
#Generate iframe URL
|
|
91
|
+
case base_path
|
|
83
92
|
when 'https://stage-api-groupdocs.dynabic.com'
|
|
84
|
-
|
|
93
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
|
85
94
|
when 'https://dev-api-groupdocs.dynabic.com'
|
|
86
|
-
|
|
95
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
|
87
96
|
else
|
|
88
|
-
|
|
97
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
|
89
98
|
end
|
|
90
99
|
|
|
91
|
-
#
|
|
92
|
-
|
|
93
|
-
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
|
94
|
-
|
|
95
|
-
iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
|
|
100
|
+
#Make iframe
|
|
101
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
|
96
102
|
|
|
97
103
|
rescue Exception => e
|
|
98
104
|
err = e.message
|
|
99
105
|
end
|
|
100
106
|
|
|
101
|
-
#
|
|
107
|
+
#Set variables for template
|
|
102
108
|
haml :sample22, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.fileId, :email => settings.email, :firstName => settings.first_name, :lastName => settings.last_name, :iframe => iframe, :err => err}
|
|
103
109
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
#GET request
|
|
2
2
|
get '/sample23' do
|
|
3
3
|
haml :sample23
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
#POST request
|
|
7
7
|
post '/sample23' do
|
|
8
|
-
# set variables
|
|
9
8
|
|
|
9
|
+
#Set variables
|
|
10
10
|
set :client_id, params[:clientId]
|
|
11
11
|
set :private_key, params[:privateKey]
|
|
12
12
|
set :source, params[:source]
|
|
@@ -15,42 +15,49 @@ post '/sample23' do
|
|
|
15
15
|
set :base_path, params[:basePath]
|
|
16
16
|
|
|
17
17
|
begin
|
|
18
|
-
#
|
|
18
|
+
#Check required variables
|
|
19
19
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
#Prepare base path
|
|
22
|
+
if settings.base_path.empty?
|
|
23
|
+
base_path = 'https://api.groupdocs.com'
|
|
24
|
+
elsif settings.base_path.match('/v2.0')
|
|
25
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
|
26
|
+
else
|
|
27
|
+
base_path = settings.base_path
|
|
28
|
+
end
|
|
22
29
|
|
|
23
|
-
#
|
|
30
|
+
#Configure your access to API server
|
|
24
31
|
GroupDocs.configure do |groupdocs|
|
|
25
32
|
groupdocs.client_id = settings.client_id
|
|
26
33
|
groupdocs.private_key = settings.private_key
|
|
27
|
-
#
|
|
28
|
-
groupdocs.api_server =
|
|
34
|
+
#Optionally specify API server and version
|
|
35
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
|
29
36
|
end
|
|
30
37
|
|
|
31
|
-
#
|
|
38
|
+
#Get document by file GUID
|
|
32
39
|
case settings.source
|
|
33
40
|
when 'guid'
|
|
34
|
-
#
|
|
41
|
+
#Create instance of File
|
|
35
42
|
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
|
36
43
|
when 'local'
|
|
37
|
-
#
|
|
44
|
+
#Construct path
|
|
38
45
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
39
|
-
#
|
|
46
|
+
#Open file
|
|
40
47
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
41
|
-
#
|
|
48
|
+
#Make a request to API using client_id and private_key
|
|
42
49
|
file = GroupDocs::Storage::File.upload!(file_path, {})
|
|
43
50
|
when 'url'
|
|
44
|
-
#
|
|
51
|
+
#Upload file from defined url
|
|
45
52
|
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
|
46
53
|
else
|
|
47
54
|
raise 'Wrong GUID source.'
|
|
48
55
|
end
|
|
49
56
|
|
|
50
|
-
#
|
|
57
|
+
#Raise exception if something went wrong
|
|
51
58
|
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
|
52
59
|
|
|
53
|
-
#
|
|
60
|
+
#Make GroupDocs::Storage::Document instance
|
|
54
61
|
document = file.to_document
|
|
55
62
|
|
|
56
63
|
#Create new page
|
|
@@ -60,6 +67,6 @@ post '/sample23' do
|
|
|
60
67
|
err = e.message
|
|
61
68
|
end
|
|
62
69
|
|
|
63
|
-
#
|
|
70
|
+
#Set variables for template
|
|
64
71
|
haml :sample23, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :page_image => page_image, :err => err}
|
|
65
72
|
end
|
|
@@ -1,57 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
#GET request
|
|
2
2
|
get '/sample24' do
|
|
3
3
|
haml :sample24
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
#POST request
|
|
7
7
|
post '/sample24' do
|
|
8
|
-
#
|
|
8
|
+
#Set variables
|
|
9
9
|
set :client_id, params[:clientId]
|
|
10
10
|
set :private_key, params[:privateKey]
|
|
11
11
|
set :url, params[:url]
|
|
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.url.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
|
+
#Upload web file
|
|
29
36
|
file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
|
|
30
37
|
|
|
31
|
-
#
|
|
38
|
+
#Construct result messages
|
|
32
39
|
message = "<p>File was uploaded to GroupDocs. Here you can see your <strong> file in the GroupDocs Embedded Viewer.</p>"
|
|
33
40
|
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
#Prepare to sign url
|
|
42
|
+
iframe = "/document-viewer/embed/#{file.guid}"
|
|
43
|
+
# Construct result string
|
|
44
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
|
45
|
+
#Generate iframe URL
|
|
46
|
+
case base_path
|
|
37
47
|
when 'https://stage-api-groupdocs.dynabic.com'
|
|
38
|
-
|
|
48
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
|
39
49
|
when 'https://dev-api-groupdocs.dynabic.com'
|
|
40
|
-
|
|
50
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
|
41
51
|
else
|
|
42
|
-
|
|
52
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
|
43
53
|
end
|
|
44
54
|
|
|
45
|
-
#
|
|
46
|
-
iframe =
|
|
47
|
-
|
|
48
|
-
# Construct result iframe
|
|
49
|
-
iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
|
|
55
|
+
#Make iframe
|
|
56
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
|
50
57
|
|
|
51
58
|
rescue Exception => e
|
|
52
59
|
err = e.message
|
|
53
60
|
end
|
|
54
61
|
|
|
55
|
-
#
|
|
62
|
+
#Set variables for template
|
|
56
63
|
haml :sample24, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :message => message, :err => err}
|
|
57
64
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
#GET request
|
|
2
2
|
get '/sample25' do
|
|
3
3
|
haml :sample25
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
#POST request
|
|
7
7
|
post '/sample25' do
|
|
8
|
-
#
|
|
8
|
+
#Set variables
|
|
9
9
|
set :client_id, params[:clientId]
|
|
10
10
|
set :private_key, params[:privateKey]
|
|
11
11
|
set :source, params[:source]
|
|
@@ -13,10 +13,10 @@ post '/sample25' do
|
|
|
13
13
|
set :url, params[:url]
|
|
14
14
|
set :base_path, params[:basePath]
|
|
15
15
|
|
|
16
|
-
#
|
|
16
|
+
#Set download path
|
|
17
17
|
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
18
18
|
|
|
19
|
-
#
|
|
19
|
+
#Remove all files from download directory or create folder if it not there
|
|
20
20
|
if File.directory?(downloads_path)
|
|
21
21
|
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
|
22
22
|
else
|
|
@@ -24,90 +24,97 @@ post '/sample25' do
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
begin
|
|
27
|
-
#
|
|
27
|
+
#Check required variables
|
|
28
28
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
#Prepare base path
|
|
31
|
+
if settings.base_path.empty?
|
|
32
|
+
base_path = 'https://api.groupdocs.com'
|
|
33
|
+
elsif settings.base_path.match('/v2.0')
|
|
34
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
|
35
|
+
else
|
|
36
|
+
base_path = settings.base_path
|
|
37
|
+
end
|
|
31
38
|
|
|
32
|
-
#
|
|
39
|
+
#Configure your access to API server
|
|
33
40
|
GroupDocs.configure do |groupdocs|
|
|
34
41
|
groupdocs.client_id = settings.client_id
|
|
35
42
|
groupdocs.private_key = settings.private_key
|
|
36
|
-
#
|
|
37
|
-
groupdocs.api_server =
|
|
43
|
+
#Optionally specify API server and version
|
|
44
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
|
38
45
|
end
|
|
39
46
|
|
|
40
|
-
#
|
|
47
|
+
#Get document by file GUID
|
|
41
48
|
case settings.source
|
|
42
49
|
when 'guid'
|
|
43
|
-
#
|
|
50
|
+
#Create instance of File
|
|
44
51
|
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
|
45
52
|
when 'local'
|
|
46
|
-
#
|
|
53
|
+
#Construct path
|
|
47
54
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
48
|
-
#
|
|
55
|
+
#Open file
|
|
49
56
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
50
|
-
#
|
|
57
|
+
#Make a request to API using client_id and private_key
|
|
51
58
|
file = GroupDocs::Storage::File.upload!(file_path, {})
|
|
52
59
|
when 'url'
|
|
53
|
-
#
|
|
60
|
+
#Upload file from defined url
|
|
54
61
|
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
|
55
62
|
else
|
|
56
63
|
raise 'Wrong GUID source.'
|
|
57
64
|
end
|
|
58
65
|
|
|
59
|
-
#
|
|
66
|
+
#Raise exception if something went wrong
|
|
60
67
|
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
|
61
68
|
|
|
62
|
-
#
|
|
69
|
+
#Make GroupDocs::Storage::Document instance
|
|
63
70
|
document = file.to_document
|
|
64
71
|
|
|
65
|
-
#
|
|
72
|
+
#Create datasource with fields
|
|
66
73
|
datasource = GroupDocs::DataSource.new
|
|
67
74
|
|
|
68
|
-
#
|
|
75
|
+
#Get arry of document's fields
|
|
69
76
|
fields = document.fields!()
|
|
70
77
|
|
|
71
|
-
#
|
|
78
|
+
#Create Field instance and fill the fields
|
|
72
79
|
datasource.fields = fields.map { |field| GroupDocs::DataSource::Field.new(name: field.name, type: :text, values: %w(value1 value2)) }
|
|
73
80
|
|
|
74
|
-
#
|
|
81
|
+
#Adds datasource.
|
|
75
82
|
datasource.add!()
|
|
76
83
|
|
|
77
84
|
|
|
78
|
-
#
|
|
85
|
+
#Creates new job to merge datasource into document.
|
|
79
86
|
job = document.datasource!(datasource, {:new_type => 'pdf'})
|
|
80
87
|
sleep 10 # wait for merge and convert
|
|
81
88
|
|
|
82
|
-
#
|
|
89
|
+
#Returns an hash of input and output documents associated to job.
|
|
83
90
|
document = job.documents!()
|
|
84
91
|
|
|
85
|
-
#
|
|
92
|
+
#Download file
|
|
86
93
|
document[:inputs][0].outputs[0].download!("#{File.dirname(__FILE__)}/../public/downloads")
|
|
87
94
|
|
|
88
|
-
#
|
|
95
|
+
#Set converted document GUID
|
|
89
96
|
guid = document[:inputs][0].outputs[0].guid
|
|
90
|
-
#
|
|
97
|
+
#Set converted document Name
|
|
91
98
|
file_name = document[:inputs][0].outputs[0].name
|
|
92
99
|
|
|
93
|
-
#
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
#Prepare to sign url
|
|
101
|
+
iframe = "/document-viewer/embed/#{guid}"
|
|
102
|
+
# Construct result string
|
|
103
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
|
104
|
+
#Generate iframe URL
|
|
105
|
+
case base_path
|
|
96
106
|
when 'https://stage-api-groupdocs.dynabic.com'
|
|
97
|
-
|
|
107
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
|
98
108
|
when 'https://dev-api-groupdocs.dynabic.com'
|
|
99
|
-
|
|
109
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
|
100
110
|
else
|
|
101
|
-
|
|
111
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
|
102
112
|
end
|
|
103
113
|
|
|
104
|
-
#
|
|
105
|
-
|
|
106
|
-
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
|
107
|
-
|
|
108
|
-
# Set iframe with document GUID or raise an error
|
|
114
|
+
#Set iframe with document GUID or raise an error
|
|
109
115
|
if guid
|
|
110
|
-
|
|
116
|
+
#Make iframe
|
|
117
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
|
111
118
|
else
|
|
112
119
|
raise 'File was not converted'
|
|
113
120
|
end
|
|
@@ -116,6 +123,6 @@ post '/sample25' do
|
|
|
116
123
|
err = e.message
|
|
117
124
|
end
|
|
118
125
|
|
|
119
|
-
#
|
|
126
|
+
#Set variables for template
|
|
120
127
|
haml :sample25, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :fileName => file_name, :err => err}
|
|
121
128
|
end
|