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,9 +1,9 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample32' do
|
3
3
|
haml :sample32
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample32/callback' do
|
8
8
|
|
9
9
|
source_id = ''
|
@@ -11,19 +11,19 @@ post '/sample32/callback' do
|
|
11
11
|
private_key = ''
|
12
12
|
subscriber_email = ''
|
13
13
|
|
14
|
-
#
|
14
|
+
#Get callback request
|
15
15
|
data = JSON.parse(request.body.read)
|
16
16
|
begin
|
17
17
|
raise 'Empty params!' if data.empty?
|
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(' ')
|
@@ -32,16 +32,16 @@ post '/sample32/callback' do
|
|
32
32
|
subscriber_email = contents[2]
|
33
33
|
end
|
34
34
|
|
35
|
-
#
|
35
|
+
#Create new Form
|
36
36
|
form = GroupDocs::Signature::Form.new({:id => source_id})
|
37
37
|
|
38
|
-
#
|
38
|
+
#Get document by Form id
|
39
39
|
document = form.documents!({:client_id => client_id, :private_key => private_key})
|
40
40
|
|
41
|
-
#
|
41
|
+
#An adress recipient
|
42
42
|
to = subscriber_email
|
43
43
|
|
44
|
-
#
|
44
|
+
#The Body message
|
45
45
|
body = "
|
46
46
|
<html>
|
47
47
|
<head>
|
@@ -53,28 +53,22 @@ post '/sample32/callback' do
|
|
53
53
|
</html>"
|
54
54
|
|
55
55
|
|
56
|
-
#
|
56
|
+
#A method send the mail
|
57
57
|
def send_mail(to, body)
|
58
|
-
#
|
58
|
+
#Implement your send mail function with your SMTP server
|
59
59
|
return true
|
60
60
|
end
|
61
61
|
|
62
|
-
send_mail(to, body) #
|
62
|
+
send_mail(to, body) #Send notification mail
|
63
63
|
|
64
64
|
rescue Exception => e
|
65
65
|
err = e.message
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# POST request
|
69
|
+
#POST request
|
76
70
|
post '/sample32' do
|
77
|
-
#
|
71
|
+
#Set variables
|
78
72
|
set :client_id, params[:clientId]
|
79
73
|
set :private_key, params[:privateKey]
|
80
74
|
set :template_guid, params[:templateGuid]
|
@@ -86,23 +80,30 @@ post '/sample32' do
|
|
86
80
|
|
87
81
|
begin
|
88
82
|
|
89
|
-
#
|
83
|
+
#Check required variables
|
90
84
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
91
85
|
|
92
|
-
|
86
|
+
#Prepare base path
|
87
|
+
if settings.base_path.empty?
|
88
|
+
base_path = 'https://api.groupdocs.com'
|
89
|
+
elsif settings.base_path.match('/v2.0')
|
90
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
91
|
+
else
|
92
|
+
base_path = settings.base_path
|
93
|
+
end
|
93
94
|
|
94
|
-
#
|
95
|
+
#Configure your access to API server
|
95
96
|
GroupDocs.configure do |groupdocs|
|
96
97
|
groupdocs.client_id = settings.client_id
|
97
98
|
groupdocs.private_key = settings.private_key
|
98
|
-
#
|
99
|
-
groupdocs.api_server =
|
99
|
+
#Optionally specify API server and version
|
100
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
100
101
|
end
|
101
102
|
|
102
|
-
#
|
103
|
+
#Write client and private key to the file for callback job
|
103
104
|
if settings.callback
|
104
105
|
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
105
|
-
#
|
106
|
+
#White space is required
|
106
107
|
out_file.write("#{settings.client_id} ")
|
107
108
|
out_file.write("#{settings.private_key} ")
|
108
109
|
out_file.write("#{settings.email}")
|
@@ -115,16 +116,16 @@ post '/sample32' do
|
|
115
116
|
case settings.source
|
116
117
|
when 'form'
|
117
118
|
id = settings.form_guid
|
118
|
-
#
|
119
|
+
#Create new Form with guid
|
119
120
|
form = GroupDocs::Signature::Form.new
|
120
121
|
form.name = 'test'
|
121
122
|
form.notifyOwnerOnSign = true
|
122
123
|
|
123
|
-
#
|
124
|
+
#Create new Form with template
|
124
125
|
id = form.create!({:formId => guid})
|
125
126
|
form = GroupDocs::Signature::Form.get!(id)
|
126
127
|
|
127
|
-
#
|
128
|
+
#Publish the Form
|
128
129
|
form.publish!({:callbackUrl => settings.callback})
|
129
130
|
guid = settings.form_guid
|
130
131
|
|
@@ -134,34 +135,36 @@ post '/sample32' do
|
|
134
135
|
form.name = 'test'
|
135
136
|
form.notifyOwnerOnSign = true
|
136
137
|
|
137
|
-
#
|
138
|
+
#Create new Form with template
|
138
139
|
guid = form.create!({ :templateId => settings.template_guid})
|
139
140
|
|
140
|
-
#
|
141
|
+
#Publish the Form
|
141
142
|
form.publish!({:callbackUrl => settings.callback})
|
142
143
|
|
143
144
|
end
|
144
145
|
|
145
|
-
#
|
146
|
-
|
147
|
-
|
146
|
+
#Prepare to sign url
|
147
|
+
iframe = "/signature2/forms/signembed/#{guid}"
|
148
|
+
# Construct result string
|
149
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
150
|
+
#Generate iframe URL
|
151
|
+
case base_path
|
148
152
|
when 'https://stage-api-groupdocs.dynabic.com'
|
149
|
-
|
153
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
150
154
|
when 'https://dev-api-groupdocs.dynabic.com'
|
151
|
-
|
155
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
152
156
|
else
|
153
|
-
|
157
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
154
158
|
end
|
155
159
|
|
156
|
-
#
|
157
|
-
iframe =
|
158
|
-
iframe = "<iframe width='100%' height='600' frameborder='0' src='#{iframe}'></iframe>"
|
160
|
+
#Make iframe
|
161
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
159
162
|
|
160
163
|
rescue Exception => e
|
161
164
|
err = e.message
|
162
165
|
end
|
163
166
|
|
164
|
-
#
|
167
|
+
#Set variables for template
|
165
168
|
haml :sample32, :locals => {:userId => settings.client_id,
|
166
169
|
:privateKey => settings.private_key,
|
167
170
|
:callback => settings.callback,
|
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample33' do
|
3
3
|
haml :sample33
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample33' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :url_1, params[:url1]
|
@@ -14,36 +14,44 @@ post '/sample33' do
|
|
14
14
|
set :base_path, params[:basePath]
|
15
15
|
|
16
16
|
begin
|
17
|
-
#
|
17
|
+
#Check required variables
|
18
18
|
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.url_1.empty? or settings.url_2.empty? or settings.url_3.empty?
|
19
19
|
|
20
|
-
|
20
|
+
#Prepare base path
|
21
|
+
if settings.base_path.empty?
|
22
|
+
base_path = 'https://api.groupdocs.com'
|
23
|
+
elsif settings.base_path.match('/v2.0')
|
24
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
25
|
+
else
|
26
|
+
base_path = settings.base_path
|
27
|
+
end
|
21
28
|
|
22
|
-
#
|
29
|
+
#Configure your access to API server
|
23
30
|
GroupDocs.configure do |groupdocs|
|
24
31
|
groupdocs.client_id = settings.client_id
|
25
32
|
groupdocs.private_key = settings.private_key
|
26
|
-
#
|
27
|
-
groupdocs.api_server =
|
33
|
+
#Optionally specify API server and version
|
34
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
35
|
+
|
28
36
|
end
|
29
37
|
|
30
38
|
|
31
|
-
#
|
39
|
+
#Create Array from variables
|
32
40
|
url = [settings.url_1, settings.url_2, settings.url_3 ]
|
33
41
|
|
34
|
-
#
|
42
|
+
#Create Hash with the options for job. :status=> -1 means the Draft status of the job
|
35
43
|
options = {:actions => [:convert, :combine], :out_formats => ['pdf'], :status => -1, :name => 'sample'}
|
36
44
|
|
37
|
-
#
|
45
|
+
#Create Job with provided options with Draft status (Sheduled job)
|
38
46
|
job = GroupDocs::Job.create!(options)
|
39
47
|
|
40
|
-
#
|
48
|
+
#Upload documents to GroupDocs Storage by url and add the documents to previously created Job
|
41
49
|
url.each do |url|
|
42
50
|
document = GroupDocs::Storage::File.upload_web!(url).to_document
|
43
51
|
job.add_document!(document, {:check_ownership => false})
|
44
52
|
end
|
45
53
|
|
46
|
-
#
|
54
|
+
#Update the Job with new status. :status => '0' mean Active status of the job (Start the job)
|
47
55
|
id = job.update!({:status => '0'})
|
48
56
|
|
49
57
|
i = 1
|
@@ -55,28 +63,31 @@ post '/sample33' do
|
|
55
63
|
i = i + 1
|
56
64
|
end
|
57
65
|
|
58
|
-
#
|
66
|
+
#Get the document into Pdf format
|
59
67
|
file = job.documents!()
|
60
68
|
|
61
69
|
document = file[:outputs]
|
62
70
|
|
63
|
-
#
|
71
|
+
#Set iframe with document GUID or raise an error
|
64
72
|
if document
|
65
73
|
|
66
|
-
#
|
67
|
-
|
68
|
-
|
74
|
+
#Prepare to sign url
|
75
|
+
iframe = "/document-viewer/embed/#{document[0].guid}"
|
76
|
+
#Construct result string
|
77
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
78
|
+
#Generate iframe URL
|
79
|
+
case base_path
|
69
80
|
when 'https://stage-api-groupdocs.dynabic.com'
|
70
|
-
|
81
|
+
iframe = "https://stage-api-groupdocs.dynabic.com#{url}"
|
71
82
|
when 'https://dev-api-groupdocs.dynabic.com'
|
72
|
-
|
83
|
+
iframe = "https://dev-apps.groupdocs.com#{url}"
|
73
84
|
else
|
74
|
-
|
85
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
75
86
|
end
|
76
87
|
|
77
|
-
#
|
78
|
-
iframe =
|
79
|
-
|
88
|
+
#Make iframe
|
89
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
90
|
+
|
80
91
|
else
|
81
92
|
raise 'File was not converted'
|
82
93
|
end
|
@@ -84,6 +95,6 @@ post '/sample33' do
|
|
84
95
|
err = e.message
|
85
96
|
end
|
86
97
|
|
87
|
-
#
|
98
|
+
#Set variables for template
|
88
99
|
haml :sample33, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :err => err, :iframe => iframe}
|
89
100
|
end
|
@@ -1,31 +1,38 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample34' do
|
3
3
|
haml :sample34
|
4
4
|
end
|
5
5
|
|
6
|
-
#
|
6
|
+
#POST request
|
7
7
|
post '/sample34' do
|
8
|
-
#
|
8
|
+
#Set variables
|
9
9
|
set :client_id, params[:clientId]
|
10
10
|
set :private_key, params[:privateKey]
|
11
11
|
set :path, params[:folder]
|
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?
|
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
31
|
# Optionally specify API server and version
|
25
|
-
groupdocs.api_server =
|
32
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
26
33
|
end
|
27
34
|
|
28
|
-
#
|
35
|
+
#Create new Folder
|
29
36
|
folder = GroupDocs::Storage::Folder.create!(settings.path)
|
30
37
|
if folder.id
|
31
38
|
message = "<span style=\"color:green\">Folder was created #{folder.path} </span> "
|
@@ -35,6 +42,6 @@ post '/sample34' do
|
|
35
42
|
err = e.message
|
36
43
|
end
|
37
44
|
|
38
|
-
#
|
45
|
+
#Set variables for template
|
39
46
|
haml :sample34, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :message => message, :err => err}
|
40
47
|
end
|
@@ -1,66 +1,71 @@
|
|
1
|
-
#
|
1
|
+
#GET request
|
2
2
|
get '/sample35' do
|
3
3
|
haml :sample35
|
4
4
|
end
|
5
5
|
|
6
6
|
|
7
|
-
#
|
7
|
+
#POST request
|
8
8
|
post '/sample35' do
|
9
|
-
#
|
9
|
+
#Set variables
|
10
10
|
set :client_id, params[:clientId]
|
11
11
|
set :private_key, params[:privateKey]
|
12
12
|
set :source, params[:source]
|
13
13
|
set :file_id, params[:fileId]
|
14
14
|
set :url, params[:url]
|
15
|
-
set :
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
24
29
|
|
25
|
-
#
|
30
|
+
#Configure your access to API server.
|
26
31
|
GroupDocs.configure do |groupdocs|
|
27
32
|
groupdocs.client_id = settings.client_id
|
28
33
|
groupdocs.private_key = settings.private_key
|
29
|
-
#
|
30
|
-
groupdocs.api_server =
|
34
|
+
#Optionally specify API server and version
|
35
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
31
36
|
|
32
37
|
end
|
33
38
|
|
34
39
|
|
35
|
-
#
|
40
|
+
#Get document by file GUID
|
36
41
|
case settings.source
|
37
42
|
when 'guid'
|
38
|
-
#
|
43
|
+
#Create instance of File
|
39
44
|
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
40
45
|
when 'local'
|
41
|
-
#
|
46
|
+
#Construct path
|
42
47
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
43
|
-
#
|
48
|
+
#Open file
|
44
49
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
45
|
-
#
|
50
|
+
#Make a request to API using client_id and private_key
|
46
51
|
file = GroupDocs::Storage::File.upload!(file_path, {})
|
47
52
|
when 'url'
|
48
|
-
#
|
53
|
+
#Upload file from defined url
|
49
54
|
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
50
55
|
else
|
51
56
|
raise 'Wrong GUID source.'
|
52
57
|
end
|
53
58
|
|
54
|
-
#
|
59
|
+
#Raise exception if something went wrong
|
55
60
|
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
56
61
|
|
57
62
|
|
58
|
-
#
|
63
|
+
#Make GroupDocs::Storage::Document instance
|
59
64
|
document = file.to_document
|
60
|
-
#
|
65
|
+
#Get array of document's fields
|
61
66
|
fields = document.fields!
|
62
67
|
|
63
|
-
#
|
68
|
+
#Create the fields for form
|
64
69
|
html = ''
|
65
70
|
fields.map do |e|
|
66
71
|
|
@@ -90,62 +95,64 @@ post '/sample35' do
|
|
90
95
|
|
91
96
|
end
|
92
97
|
|
93
|
-
|
94
98
|
rescue Exception => e
|
95
99
|
err = e.message
|
96
100
|
end
|
97
101
|
|
98
|
-
#
|
99
|
-
haml :sample35, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :
|
102
|
+
#Set variables for template
|
103
|
+
haml :sample35, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => document.file.guid, :base_path => settings.base_path, :html => html, :err => err}
|
100
104
|
end
|
101
105
|
|
102
|
-
#
|
106
|
+
#GET request
|
103
107
|
get '/sample35/check' do
|
104
108
|
haml :sample35
|
105
109
|
end
|
106
110
|
|
107
|
-
#
|
111
|
+
#POST request
|
108
112
|
post '/sample35/check' do
|
109
113
|
set :client_id, params[:clientId]
|
110
114
|
set :private_key, params[:privateKey]
|
111
|
-
set :
|
115
|
+
set :base_path, params[:basePath]
|
112
116
|
set :file_id, params[:fileId]
|
113
117
|
|
114
118
|
begin
|
115
119
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
+
#Prepare base path
|
121
|
+
if settings.base_path.empty?
|
122
|
+
base_path = 'https://api.groupdocs.com'
|
123
|
+
elsif settings.base_path.match('/v2.0')
|
124
|
+
base_path = settings.base_path.split('/v2.0')[0]
|
125
|
+
else
|
126
|
+
base_path = settings.base_path
|
127
|
+
end
|
120
128
|
|
121
|
-
#
|
129
|
+
#Get document by file GUID
|
122
130
|
GroupDocs.configure do |groupdocs|
|
123
131
|
groupdocs.client_id = settings.client_id
|
124
132
|
groupdocs.private_key = settings.private_key
|
125
|
-
#
|
126
|
-
groupdocs.api_server =
|
127
|
-
groupdocs.api_version = '2.0' # default is '2.0'
|
133
|
+
#Optionally specify API server and version
|
134
|
+
groupdocs.api_server = base_path # default is 'https://api.groupdocs.com'
|
128
135
|
end
|
129
136
|
|
130
137
|
|
131
138
|
#TODO:
|
132
139
|
#Merge template PDF FIle with the data provided via dynamically created HTML form.
|
133
140
|
|
134
|
-
#
|
141
|
+
#Create instance of File
|
135
142
|
document = GroupDocs::Storage::File.new({:guid => settings.file_id}).to_document
|
136
143
|
|
137
|
-
#
|
144
|
+
#Create datasource with fields
|
138
145
|
datasource = GroupDocs::DataSource.new
|
139
146
|
|
140
|
-
#
|
147
|
+
#Get array of document's fields
|
141
148
|
fields = document.fields!()
|
142
149
|
|
143
|
-
#
|
150
|
+
#Get unique fields
|
144
151
|
fields = fields.uniq{ |f| f.name }
|
145
152
|
|
146
153
|
datasource.fields = []
|
147
154
|
|
148
|
-
#
|
155
|
+
#Create Field instance and fill the fields
|
149
156
|
fields.each do |field|
|
150
157
|
if field.type == 'Text'
|
151
158
|
datasource.fields << GroupDocs::DataSource::Field.new(name: field.name, type: :text, values: [params[field.name.to_sym]])
|
@@ -184,14 +191,14 @@ post '/sample35/check' do
|
|
184
191
|
|
185
192
|
end
|
186
193
|
|
187
|
-
#
|
194
|
+
#Adds datasource.
|
188
195
|
datasource.add!()
|
189
196
|
|
190
|
-
#
|
197
|
+
#Creates new job to merge datasource into document.
|
191
198
|
job = document.datasource!(datasource, {:new_type => 'pdf'})
|
192
199
|
|
193
200
|
i = 0
|
194
|
-
#
|
201
|
+
#Checks status of Job.
|
195
202
|
while i<5 do
|
196
203
|
sleep(5)
|
197
204
|
job_status = GroupDocs::Job.get!(job.id)
|
@@ -199,22 +206,28 @@ post '/sample35/check' do
|
|
199
206
|
i += 1
|
200
207
|
end
|
201
208
|
|
202
|
-
#
|
209
|
+
#Returns an hash of input and output documents associated to job.
|
203
210
|
document = job.documents!()
|
204
211
|
|
205
|
-
#
|
212
|
+
#Set converted document GUID
|
206
213
|
guid = document[:inputs][0].outputs[0].guid
|
207
214
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
215
|
+
#Prepare to sign url
|
216
|
+
iframe = "/document-viewer/embed/#{guid}"
|
217
|
+
# Construct result string
|
218
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
219
|
+
#Generate iframe URL
|
220
|
+
case base_path
|
221
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
222
|
+
iframe = "https://stage-apps-groupdocs.dynabic.com/#{url}"
|
223
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
224
|
+
iframe = "https://dev-apps-groupdocs.dynabic.com#{url}"
|
225
|
+
else
|
226
|
+
iframe = "https://apps.groupdocs.com#{url}"
|
216
227
|
end
|
217
228
|
|
229
|
+
#Make iframe
|
230
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
218
231
|
|
219
232
|
rescue Exception => e
|
220
233
|
err = e.message
|