groupdocs 1.5.3 → 1.5.4
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/.travis.yml +0 -1
- data/README.md +2 -0
- data/examples/api-samples/public/docs/annotation-sample.html +167 -57
- data/examples/api-samples/public/docs/docco.css +459 -151
- data/examples/api-samples/public/docs/envelope-sample.html +373 -131
- data/examples/api-samples/public/docs/sample1.html +126 -26
- data/examples/api-samples/public/docs/sample10.html +213 -50
- data/examples/api-samples/public/docs/sample11.html +319 -87
- data/examples/api-samples/public/docs/sample12.html +165 -40
- data/examples/api-samples/public/docs/sample13.html +166 -41
- data/examples/api-samples/public/docs/sample14.html +142 -30
- data/examples/api-samples/public/docs/sample15.html +127 -27
- data/examples/api-samples/public/docs/sample16.html +125 -25
- data/examples/api-samples/public/docs/sample17.html +188 -37
- data/examples/api-samples/public/docs/sample18.html +614 -157
- data/examples/api-samples/public/docs/sample19.html +221 -59
- data/examples/api-samples/public/docs/sample2.html +142 -30
- data/examples/api-samples/public/docs/sample20.html +176 -51
- data/examples/api-samples/public/docs/sample21.html +287 -66
- data/examples/api-samples/public/docs/sample22.html +224 -53
- data/examples/api-samples/public/docs/sample23.html +256 -0
- data/examples/api-samples/public/docs/sample24.html +143 -0
- data/examples/api-samples/public/docs/sample25.html +429 -0
- data/examples/api-samples/public/docs/sample26.html +113 -0
- data/examples/api-samples/public/docs/sample27.html +433 -0
- data/examples/api-samples/public/docs/sample28.html +185 -0
- data/examples/api-samples/public/docs/sample29.html +175 -0
- data/examples/api-samples/public/docs/sample3.html +172 -34
- data/examples/api-samples/public/docs/sample30.html +144 -0
- data/examples/api-samples/public/docs/sample31.html +734 -0
- data/examples/api-samples/public/docs/sample4.html +204 -52
- data/examples/api-samples/public/docs/sample5.html +241 -63
- data/examples/api-samples/public/docs/sample6.html +209 -48
- data/examples/api-samples/public/docs/sample7.html +155 -43
- data/examples/api-samples/public/docs/sample8.html +235 -62
- data/examples/api-samples/public/docs/sample9.html +200 -49
- data/examples/api-samples/public/templates/merge_field1_doc.docx +0 -0
- data/examples/api-samples/public/templates/merge_field2_doc.docx +0 -0
- data/examples/api-samples/samples/sample23.rb +54 -0
- data/examples/api-samples/samples/sample24.rb +30 -0
- data/examples/api-samples/samples/sample25.rb +4 -4
- data/examples/api-samples/samples/sample26.rb +25 -0
- data/examples/api-samples/samples/sample27.rb +100 -0
- data/examples/api-samples/samples/sample28.rb +47 -0
- data/examples/api-samples/samples/sample29.rb +52 -0
- data/examples/api-samples/samples/sample30.rb +39 -0
- data/examples/api-samples/samples/sample31.rb +204 -0
- data/examples/api-samples/samples/sample5.rb +5 -3
- data/examples/api-samples/samples/sample6.rb +2 -0
- data/examples/api-samples/views/_others_samples.haml +12 -0
- data/examples/api-samples/views/index.haml +12 -0
- data/examples/api-samples/views/layout.haml +1 -0
- data/examples/api-samples/views/sample1.haml +3 -2
- data/examples/api-samples/views/sample10.haml +3 -2
- data/examples/api-samples/views/sample11.haml +4 -0
- data/examples/api-samples/views/sample12.haml +4 -0
- data/examples/api-samples/views/sample13.haml +4 -0
- data/examples/api-samples/views/sample14.haml +4 -0
- data/examples/api-samples/views/sample15.haml +4 -0
- data/examples/api-samples/views/sample16.haml +4 -0
- data/examples/api-samples/views/sample17.haml +4 -0
- data/examples/api-samples/views/sample19.haml +4 -0
- data/examples/api-samples/views/sample2.haml +3 -2
- data/examples/api-samples/views/sample20.haml +4 -0
- data/examples/api-samples/views/sample21.haml +4 -0
- data/examples/api-samples/views/sample22.haml +4 -0
- data/examples/api-samples/views/sample23.haml +87 -0
- data/examples/api-samples/views/sample24.haml +44 -0
- data/examples/api-samples/views/sample26.haml +54 -0
- data/examples/api-samples/views/sample27.haml +122 -0
- data/examples/api-samples/views/sample28.haml +47 -0
- data/examples/api-samples/views/sample29.haml +70 -0
- data/examples/api-samples/views/sample3.haml +3 -2
- data/examples/api-samples/views/sample30.haml +46 -0
- data/examples/api-samples/views/sample31.haml +114 -0
- data/examples/api-samples/views/sample4.haml +3 -2
- data/examples/api-samples/views/sample5.haml +3 -2
- data/examples/api-samples/views/sample6.haml +3 -2
- data/examples/api-samples/views/sample7.haml +3 -2
- data/examples/api-samples/views/sample8.haml +3 -2
- data/examples/api-samples/views/sample9.haml +3 -2
- data/examples/viewer/Gemfile +1 -1
- data/groupdocs.gemspec +3 -3
- data/lib/groupdocs/datasource.rb +22 -0
- data/lib/groupdocs/document.rb +493 -43
- data/lib/groupdocs/document/annotation.rb +73 -0
- data/lib/groupdocs/job.rb +82 -1
- data/lib/groupdocs/post.rb +83 -0
- data/lib/groupdocs/questionnaire.rb +41 -0
- data/lib/groupdocs/signature.rb +342 -0
- data/lib/groupdocs/signature/envelope.rb +56 -0
- data/lib/groupdocs/signature/form.rb +47 -5
- data/lib/groupdocs/signature/shared/field_methods.rb +37 -0
- data/lib/groupdocs/storage/file.rb +83 -0
- data/lib/groupdocs/subscription.rb +218 -0
- data/lib/groupdocs/user.rb +422 -1
- data/lib/groupdocs/version.rb +1 -1
- data/spec/groupdocs/job_spec.rb +4 -5
- data/spec/groupdocs/user_spec.rb +157 -0
- data/spec/support/json/annotation_resize.json +11 -0
- data/spec/support/json/annotation_text_color.json +10 -0
- data/spec/support/json/annotation_text_info.json +11 -0
- data/spec/support/json/document_content_get.json +8 -0
- data/spec/support/json/document_edit_lock_get.json +10 -0
- data/spec/support/json/document_editlock_remove.json +8 -0
- data/spec/support/json/document_page_html_urls_get.json +14 -0
- data/spec/support/json/document_password_set.json +19 -0
- data/spec/support/json/document_representations.json +25 -0
- data/spec/support/json/document_shared_documents_get.json +32 -0
- data/spec/support/json/document_tags_get.json +9 -0
- data/spec/support/json/document_tags_remove.json +8 -0
- data/spec/support/json/document_tags_set.json +8 -0
- data/spec/support/json/document_user_status_set.json +12 -0
- data/spec/support/json/job_documents.json +103 -35
- data/spec/support/json/job_xml_get.json +30 -0
- data/spec/support/json/jobs_documents.json +40 -0
- data/spec/support/json/user_get_profile.json +73 -0
- metadata +49 -177
Binary file
|
Binary file
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample23' do
|
3
|
+
haml :sample23
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample23' do
|
8
|
+
# set variables
|
9
|
+
|
10
|
+
set :client_id, params[:client_id]
|
11
|
+
set :private_key, params[:private_key]
|
12
|
+
set :source, params[:source]
|
13
|
+
set :file_id, params[:fileId]
|
14
|
+
set :url, params[:url]
|
15
|
+
|
16
|
+
begin
|
17
|
+
# check required variables
|
18
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
19
|
+
|
20
|
+
# get document by file GUID
|
21
|
+
case settings.source
|
22
|
+
when 'guid'
|
23
|
+
# Create instance of File
|
24
|
+
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
25
|
+
when 'local'
|
26
|
+
# Construct path
|
27
|
+
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
28
|
+
# Open file
|
29
|
+
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
30
|
+
# Make a request to API using client_id and private_key
|
31
|
+
file = GroupDocs::Storage::File.upload!(file_path, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
32
|
+
when 'url'
|
33
|
+
# Upload file from defined url
|
34
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
|
35
|
+
else
|
36
|
+
raise 'Wrong GUID source.'
|
37
|
+
end
|
38
|
+
|
39
|
+
# Raise exception if something went wrong
|
40
|
+
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
41
|
+
|
42
|
+
# Make GroupDocs::Storage::Document instance
|
43
|
+
document = file.to_document
|
44
|
+
|
45
|
+
#Create new page
|
46
|
+
page_image = document.page_images!(700, 700, {first_page: 0, page_count: 2}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
47
|
+
pp page_image
|
48
|
+
rescue Exception => e
|
49
|
+
err = e.message
|
50
|
+
end
|
51
|
+
|
52
|
+
# set variables for template
|
53
|
+
haml :sample23, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :page_image => page_image, :err => err}
|
54
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample24' do
|
3
|
+
haml :sample24
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample24' do
|
8
|
+
# set variables
|
9
|
+
set :client_id, params[:client_id]
|
10
|
+
set :private_key, params[:private_key]
|
11
|
+
set :url, params[:url]
|
12
|
+
|
13
|
+
begin
|
14
|
+
# check required variables
|
15
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.url.nil?
|
16
|
+
|
17
|
+
# upload web file
|
18
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
|
19
|
+
|
20
|
+
# construct result messages
|
21
|
+
message = "<p>File was uploaded to GroupDocs. Here you can see your <strong> file in the GroupDocs Embedded Viewer.</p>"
|
22
|
+
iframe = "<iframe src='https://apps.groupdocs.com/document-viewer/Embed/#{file.guid}' frameborder='0' width='720' height='600'></iframe>"
|
23
|
+
|
24
|
+
rescue Exception => e
|
25
|
+
err = e.message
|
26
|
+
end
|
27
|
+
|
28
|
+
# set variables for template
|
29
|
+
haml :sample24, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :message => message, :err => err}
|
30
|
+
end
|
@@ -29,20 +29,20 @@ post '/sample25' do
|
|
29
29
|
|
30
30
|
# get document by file GUID
|
31
31
|
case settings.source
|
32
|
-
|
32
|
+
when 'guid'
|
33
33
|
# Create instance of File
|
34
34
|
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
35
|
-
|
35
|
+
when 'local'
|
36
36
|
# Construct path
|
37
37
|
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
38
38
|
# Open file
|
39
39
|
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
40
40
|
# Make a request to API using client_id and private_key
|
41
41
|
file = GroupDocs::Storage::File.upload!(file_path, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
42
|
-
|
42
|
+
when 'url'
|
43
43
|
# Upload file from defined url
|
44
44
|
file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
|
45
|
-
|
45
|
+
else
|
46
46
|
raise 'Wrong GUID source.'
|
47
47
|
end
|
48
48
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample26' do
|
3
|
+
haml :sample26
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample26' do
|
8
|
+
set :email, params[:email]
|
9
|
+
set :password, params[:password]
|
10
|
+
|
11
|
+
|
12
|
+
begin
|
13
|
+
# check required variables
|
14
|
+
raise 'Please enter all required parameters' if settings.email.empty? or settings.password.empty?
|
15
|
+
|
16
|
+
# make a request to API using email and password
|
17
|
+
user = GroupDocs::User.login!(settings.email, settings.password)
|
18
|
+
|
19
|
+
rescue Exception => e
|
20
|
+
err = e.message
|
21
|
+
end
|
22
|
+
|
23
|
+
# set variables for template
|
24
|
+
haml :sample26, :locals => {:user => user, :err => err}
|
25
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample27' do
|
3
|
+
haml :sample27
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample27' do
|
8
|
+
# set variables
|
9
|
+
set :client_id, params[:client_id]
|
10
|
+
set :private_key, params[:private_key]
|
11
|
+
set :file_id, params[:fileId]
|
12
|
+
set :source, params[:source]
|
13
|
+
set :sex, params[:sex]
|
14
|
+
set :age, params[:age]
|
15
|
+
set :sunrise, params[:sunrise]
|
16
|
+
set :name, params[:name]
|
17
|
+
set :type, params[:type]
|
18
|
+
|
19
|
+
# Set download path
|
20
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
21
|
+
|
22
|
+
# Remove all files from download directory or create folder if it not there
|
23
|
+
if File.directory?(downloads_path)
|
24
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
25
|
+
else
|
26
|
+
Dir::mkdir(downloads_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
# Check required variables
|
31
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
32
|
+
|
33
|
+
# get document by file GUID
|
34
|
+
case settings.source
|
35
|
+
when 'guid'
|
36
|
+
# Create instance of File
|
37
|
+
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
38
|
+
when 'local'
|
39
|
+
# Construct path
|
40
|
+
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
41
|
+
# Open file
|
42
|
+
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
43
|
+
# Make a request to API using client_id and private_key
|
44
|
+
file = GroupDocs::Storage::File.upload!(file_path, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
45
|
+
when 'url'
|
46
|
+
# Upload file from defined url
|
47
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
|
48
|
+
else
|
49
|
+
raise 'Wrong GUID source.'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Raise exception if something went wrong
|
53
|
+
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
54
|
+
|
55
|
+
# Make GroupDocs::Storage::Document instance
|
56
|
+
document = file.to_document
|
57
|
+
|
58
|
+
# Create datasource with fields
|
59
|
+
datasource = GroupDocs::DataSource.new
|
60
|
+
|
61
|
+
# Get arry of document's fields
|
62
|
+
enteredData = {"sex" => settings.sex, "name" => settings.name, "age"=> settings.age, "sunrise" => settings.sunrise}
|
63
|
+
|
64
|
+
# Create Field instance and fill the fields
|
65
|
+
datasource.fields = enteredData.map { |key, value| GroupDocs::DataSource::Field.new(name: key, type: :text, values: Array.new() << value) }
|
66
|
+
|
67
|
+
|
68
|
+
# Adds datasource.
|
69
|
+
datasource.add!({:client_id => settings.client_id, :private_key => settings.private_key})
|
70
|
+
|
71
|
+
# Creates new job to merge datasource into document.
|
72
|
+
job = document.datasource!(datasource, {:new_type => settings.type}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
73
|
+
sleep 10 # wait for merge and convert
|
74
|
+
|
75
|
+
# Returns an hash of input and output documents associated to job.
|
76
|
+
document = job.documents!({:client_id => settings.client_id, :private_key => settings.private_key})
|
77
|
+
|
78
|
+
# Download file
|
79
|
+
document[:inputs][0].outputs[0].download!(downloads_path, {:client_id => settings.client_id, :private_key => settings.private_key})
|
80
|
+
|
81
|
+
# Set converted document GUID
|
82
|
+
guid = document[:inputs][0].outputs[0].guid
|
83
|
+
|
84
|
+
# Set converted document Name
|
85
|
+
file_name = document[:inputs][0].outputs[0].name
|
86
|
+
|
87
|
+
# Set iframe with document GUID or raise an error
|
88
|
+
if guid
|
89
|
+
iframe = "<iframe width='100%' height='600' frameborder='0' src='https://apps.groupdocs.com/document-viewer/embed/#{guid}'></iframe>"
|
90
|
+
else
|
91
|
+
raise 'File was not converted'
|
92
|
+
end
|
93
|
+
|
94
|
+
rescue Exception => e
|
95
|
+
err = e.message
|
96
|
+
end
|
97
|
+
|
98
|
+
# set variables for template
|
99
|
+
haml :sample27, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :sex => settings.sex, :age => settings.age, :sunrise => settings.sunrise, :name => settings.name, :type => settings.type, :iframe => iframe, :file_name => file_name, :err => err}
|
100
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample28' do
|
3
|
+
haml :sample28
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample28' do
|
8
|
+
# set variables
|
9
|
+
set :client_id, params[:client_id]
|
10
|
+
set :private_key, params[:private_key]
|
11
|
+
set :file_id, params[:fileId]
|
12
|
+
|
13
|
+
begin
|
14
|
+
# check required variables
|
15
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.file_id.empty?
|
16
|
+
|
17
|
+
# make a request to API using client_id and private_key
|
18
|
+
files_list = GroupDocs::Storage::Folder.list!('/', {}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
19
|
+
document = ''
|
20
|
+
|
21
|
+
# get document by file ID
|
22
|
+
files_list.each do |element|
|
23
|
+
if element.respond_to?('guid') == true and element.guid == settings.file_id
|
24
|
+
document = element
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
unless document.instance_of? String
|
30
|
+
# get list of annotations
|
31
|
+
annotations = document.to_document.annotations!(:client_id => settings.client_id, :private_key => settings.private_key)
|
32
|
+
|
33
|
+
# delete all annotations from document
|
34
|
+
annotations.each do |annotation|
|
35
|
+
annotation.remove!(:client_id => settings.client_id, :private_key => settings.private_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
message = 'Annotations was deleted from document'
|
39
|
+
end
|
40
|
+
|
41
|
+
rescue Exception => e
|
42
|
+
err = e.message
|
43
|
+
end
|
44
|
+
|
45
|
+
# set variables for template
|
46
|
+
haml :sample28, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :messages => message, :fileId => settings.file_id, :err => err}
|
47
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
get '/sample29' do
|
2
|
+
haml :sample29
|
3
|
+
end
|
4
|
+
|
5
|
+
# POST request
|
6
|
+
post '/sample29' do
|
7
|
+
|
8
|
+
# set variables
|
9
|
+
set :client_id, params[:clientId]
|
10
|
+
set :base_path, params[:basePath]
|
11
|
+
set :url, params[:url]
|
12
|
+
|
13
|
+
url = settings.url
|
14
|
+
base_path = settings.base_path
|
15
|
+
client_id = settings.client_id
|
16
|
+
|
17
|
+
begin
|
18
|
+
|
19
|
+
#If base base is empty seting base path to prod server
|
20
|
+
base_path = 'https://api.groupdocs.com/v2.0' unless !base_path.empty?
|
21
|
+
|
22
|
+
#Generate iframe url for chosen server
|
23
|
+
if (!url.empty?)
|
24
|
+
|
25
|
+
if (base_path == "https://api.groupdocs.com/v2.0")
|
26
|
+
iframe = "https://apps.groupdocs.com/document-viewer/embed?url=#{url} + '&user_id=#{client_id}"
|
27
|
+
elsif (base_path == "https://dev-api.groupdocs.com/v2.0")
|
28
|
+
|
29
|
+
#iframe to dev server
|
30
|
+
iframe = "https://dev-apps.groupdocs.com/document-viewer/embed?url=#{url} + '&user_id=#{client_id}"
|
31
|
+
elsif (base_path == "https://stage-api.groupdocs.com/v2.0")
|
32
|
+
|
33
|
+
#iframe to test server
|
34
|
+
iframe = "https://stage-apps.groupdocs.com/document-viewer/embed?url=#{url} + '&user_id=#{client_id}"
|
35
|
+
elsif (base_path == "http://realtime-api.groupdocs.com")
|
36
|
+
iframe = "http://realtime-apps.groupdocs.com/document-viewer/embed?url=#{url} + '&user_id=#{client_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
rescue Exception => e
|
43
|
+
err = e.message
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'json'
|
47
|
+
content_type 'text/html'
|
48
|
+
|
49
|
+
#Create json string with result data
|
50
|
+
iframe = {:iframe => iframe, :error => ''}.to_json
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample30' do
|
3
|
+
haml :sample30
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample30' do
|
8
|
+
# set variables
|
9
|
+
set :client_id, params[:client_id]
|
10
|
+
set :private_key, params[:private_key]
|
11
|
+
set :name, params[:name]
|
12
|
+
|
13
|
+
begin
|
14
|
+
# check required variables
|
15
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.name.empty?
|
16
|
+
|
17
|
+
# get List files from GroupDocs Storage
|
18
|
+
file = GroupDocs::Storage::Folder.list!("", {}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
19
|
+
file_name = ''
|
20
|
+
|
21
|
+
# choose the desired file
|
22
|
+
file.map do |element|
|
23
|
+
if element.name == settings.name
|
24
|
+
file_name = element
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# delete file from GroupDocs Storage
|
29
|
+
file_name.delete!({:client_id => settings.client_id, :private_key => settings.private_key})
|
30
|
+
|
31
|
+
message = 'File was deleted from GroupDocs Storage'
|
32
|
+
|
33
|
+
rescue Exception => e
|
34
|
+
err = e.message
|
35
|
+
end
|
36
|
+
|
37
|
+
# set variables for template
|
38
|
+
haml :sample30, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :message => message, :name => settings.name, :err => err}
|
39
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
# GET request
|
2
|
+
get '/sample31' do
|
3
|
+
haml :sample31
|
4
|
+
end
|
5
|
+
|
6
|
+
# POST request
|
7
|
+
post '/sample31/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
|
+
|
49
|
+
# GET request
|
50
|
+
get '/sample31/check' do
|
51
|
+
|
52
|
+
# Check is there download directory
|
53
|
+
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
54
|
+
return 'Directory was not found.'
|
55
|
+
end
|
56
|
+
|
57
|
+
# Get file name from download directory
|
58
|
+
name = nil
|
59
|
+
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
60
|
+
name = file if file != '.' && file != '..'
|
61
|
+
end
|
62
|
+
|
63
|
+
name
|
64
|
+
end
|
65
|
+
|
66
|
+
# GET request
|
67
|
+
get '/sample31/downloads/:filename' do |filename|
|
68
|
+
# Send file with header to download it
|
69
|
+
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# POST request
|
74
|
+
post '/sample31' do
|
75
|
+
# set variables
|
76
|
+
set :client_id, params[:client_id]
|
77
|
+
set :private_key, params[:private_key]
|
78
|
+
set :template_guid, params[:template_guid]
|
79
|
+
set :name, params[:name]
|
80
|
+
set :country, params[:country]
|
81
|
+
set :city, params[:city]
|
82
|
+
set :street, params[:street]
|
83
|
+
set :email, params[:email]
|
84
|
+
set :callback, params[:callback]
|
85
|
+
set :last_name, params[:last_name]
|
86
|
+
|
87
|
+
# Set download path
|
88
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
89
|
+
|
90
|
+
# Remove all files from download directory or create folder if it not there
|
91
|
+
if File.directory?(downloads_path)
|
92
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
93
|
+
else
|
94
|
+
Dir::mkdir(downloads_path)
|
95
|
+
end
|
96
|
+
|
97
|
+
begin
|
98
|
+
# check required variables
|
99
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
100
|
+
|
101
|
+
# Write client and private key to the file for callback job
|
102
|
+
if settings.callback[0]
|
103
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
104
|
+
# white space is required
|
105
|
+
out_file.write("#{settings.client_id} ")
|
106
|
+
out_file.write("#{settings.private_key}")
|
107
|
+
out_file.close
|
108
|
+
end
|
109
|
+
|
110
|
+
file = nil
|
111
|
+
# Create instance of File
|
112
|
+
file = GroupDocs::Storage::File.new({:guid => settings.template_guid})
|
113
|
+
# Raise exception if something went wrong
|
114
|
+
raise 'No such file' unless file.is_a?(GroupDocs::Storage::File)
|
115
|
+
|
116
|
+
# Make GroupDocs::Storage::Document instance
|
117
|
+
document = file.to_document
|
118
|
+
|
119
|
+
# Create datasource with fields
|
120
|
+
datasource = GroupDocs::DataSource.new
|
121
|
+
|
122
|
+
# Get arry of document's fields
|
123
|
+
enteredData = {"email" => settings.email, "name" => settings.name, "last_name" => settings.last_name, "country"=> settings.country, "city" => settings.city, "street" => settings.street}
|
124
|
+
|
125
|
+
|
126
|
+
# Create Field instance and fill the fields
|
127
|
+
datasource.fields = enteredData.map { |key, value| GroupDocs::DataSource::Field.new(name: key, type: :text, values: Array.new() << value) }
|
128
|
+
|
129
|
+
# Adds datasource.
|
130
|
+
datasource.add!({:client_id => settings.client_id, :private_key => settings.private_key})
|
131
|
+
|
132
|
+
|
133
|
+
# Creates new job to merge datasource into document.
|
134
|
+
job = document.datasource!(datasource, {:new_type => "pdf"}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
135
|
+
sleep 10 # wait for merge and convert
|
136
|
+
|
137
|
+
# Returns an hash of input and output documents associated to job.
|
138
|
+
jobInfo = job.documents!({:client_id => settings.client_id, :private_key => settings.private_key})
|
139
|
+
|
140
|
+
# Creates new document to envelope
|
141
|
+
document = jobInfo[:inputs][0].outputs[0].to_document
|
142
|
+
|
143
|
+
# Creates envelope using user id and entered by user name
|
144
|
+
envelope = GroupDocs::Signature::Envelope.new
|
145
|
+
envelope.name = jobInfo[:inputs][0].outputs[0].name
|
146
|
+
envelope.create!({}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
147
|
+
|
148
|
+
# Adds uploaded document to envelope
|
149
|
+
envelope.add_document!(document, {}, {:client_id => settings.client_id, :private_key => settings.private_key})
|
150
|
+
|
151
|
+
# Get role list for current user
|
152
|
+
roles = GroupDocs::Signature::Role.get!({}, {client_id: settings.client_id, private_key: settings.private_key})
|
153
|
+
|
154
|
+
# Creates new recipient
|
155
|
+
recipient = GroupDocs::Signature::Recipient.new
|
156
|
+
recipient.email = 'test@test.com'
|
157
|
+
recipient.first_name = 'test'
|
158
|
+
recipient.last_name = 'test'
|
159
|
+
recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
|
160
|
+
|
161
|
+
# Adds recipient to envelope
|
162
|
+
envelope.add_recipient!(recipient, {client_id: settings.client_id, private_key: settings.private_key})
|
163
|
+
|
164
|
+
#Get field
|
165
|
+
fieldGet = GroupDocs::Signature::Field.get!({},{client_id: settings.client_id, private_key: settings.private_key}).detect { |f| f.type == :signature }
|
166
|
+
fieldGet.location = { location_x: 0.15,
|
167
|
+
location_y: 0.73,
|
168
|
+
location_width: 150,
|
169
|
+
location_height: 50,
|
170
|
+
page: 1 }
|
171
|
+
|
172
|
+
#Get document
|
173
|
+
documentGet = envelope.documents!({}, {client_id: settings.client_id, private_key: settings.private_key}).first
|
174
|
+
|
175
|
+
#Get recipients
|
176
|
+
recipientGet = envelope.recipients!({},{client_id: settings.client_id, private_key: settings.private_key}).first
|
177
|
+
|
178
|
+
# Add field to envelope
|
179
|
+
addField = envelope.add_field!(fieldGet, documentGet, recipientGet, {}, {client_id: settings.client_id, private_key: settings.private_key})
|
180
|
+
|
181
|
+
|
182
|
+
# Send envelope
|
183
|
+
envelope.send!(settings.callback, {client_id: settings.client_id, private_key: settings.private_key})
|
184
|
+
|
185
|
+
# Make iframe
|
186
|
+
iframe = "<iframe src='https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipientGet.id}' frameborder='0' width='720' height='600'></iframe>"
|
187
|
+
|
188
|
+
|
189
|
+
rescue Exception => e
|
190
|
+
err = e.message
|
191
|
+
end
|
192
|
+
|
193
|
+
# set variables for template
|
194
|
+
haml :sample31, :locals => {:userId => settings.client_id,
|
195
|
+
:privateKey => settings.private_key,
|
196
|
+
:callback => settings.callback,
|
197
|
+
:email => settings.email,
|
198
|
+
:name => settings.name,
|
199
|
+
:country => settings.country,
|
200
|
+
:city => settings.city,
|
201
|
+
:street => settings.street,
|
202
|
+
:iframe => iframe,
|
203
|
+
:err => err}
|
204
|
+
end
|