groupdocs 1.5.7 → 1.5.8
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 +51 -0
- data/examples/api-samples/Gemfile +1 -1
- data/examples/api-samples/Gemfile.lock +43 -0
- data/examples/api-samples/public/docs/{sample2.html → sample01.html} +39 -19
- data/examples/api-samples/public/docs/{sample3.html → sample02.html} +28 -22
- data/examples/api-samples/public/docs/sample03.html +285 -0
- data/examples/api-samples/public/docs/{sample4.html → sample04.html} +30 -36
- data/examples/api-samples/public/docs/{sample5.html → sample05.html} +68 -31
- data/examples/api-samples/public/docs/sample06.html +299 -0
- data/examples/api-samples/public/docs/{sample7.html → sample07.html} +53 -18
- data/examples/api-samples/public/docs/{sample8.html → sample08.html} +64 -41
- data/examples/api-samples/public/docs/sample09.html +260 -0
- data/examples/api-samples/public/docs/sample10.html +67 -28
- data/examples/api-samples/public/docs/sample11.html +171 -55
- data/examples/api-samples/public/docs/sample12.html +53 -17
- data/examples/api-samples/public/docs/sample13.html +52 -16
- data/examples/api-samples/public/docs/sample14.html +51 -8
- data/examples/api-samples/public/docs/sample15.html +46 -10
- data/examples/api-samples/public/docs/sample16.html +81 -7
- data/examples/api-samples/public/docs/sample17.html +103 -15
- data/examples/api-samples/public/docs/sample18.html +117 -41
- data/examples/api-samples/public/docs/sample19.html +410 -36
- data/examples/api-samples/public/docs/sample20.html +46 -10
- data/examples/api-samples/public/docs/sample21.html +504 -45
- data/examples/api-samples/public/docs/sample22.html +166 -28
- data/examples/api-samples/public/docs/sample23.html +61 -25
- data/examples/api-samples/public/docs/sample24.html +100 -12
- data/examples/api-samples/public/docs/sample25.html +123 -49
- data/examples/api-samples/public/docs/sample26.html +41 -8
- data/examples/api-samples/public/docs/sample27.html +125 -50
- data/examples/api-samples/public/docs/sample28.html +27 -9
- data/examples/api-samples/public/docs/sample29.html +10 -10
- data/examples/api-samples/public/docs/sample30.html +70 -14
- data/examples/api-samples/public/docs/sample31.html +108 -67
- data/examples/api-samples/public/docs/sample32.html +71 -99
- data/examples/api-samples/public/docs/sample33.html +107 -32
- data/examples/api-samples/public/docs/{sample1.html → sample34.html} +58 -18
- data/examples/api-samples/public/docs/sample35.html +666 -0
- data/examples/api-samples/public/docs/{sample6.html → sample36.html} +56 -37
- data/examples/api-samples/public/docs/sample37.html +815 -0
- data/examples/api-samples/public/docs/sample38.html +508 -0
- data/examples/api-samples/public/docs/sample39.html +921 -0
- data/examples/api-samples/public/docs/sample40.html +510 -0
- data/examples/api-samples/public/docs/sample41.html +452 -0
- data/examples/api-samples/public/docs/sample42.html +311 -0
- data/examples/api-samples/public/templates/test_all_fields2.pdf +0 -0
- data/examples/api-samples/samples/sample01.rb +37 -0
- data/examples/api-samples/samples/sample02.rb +41 -0
- data/examples/api-samples/samples/sample03.rb +73 -0
- data/examples/api-samples/samples/sample04.rb +47 -0
- data/examples/api-samples/samples/{sample5.rb → sample05.rb} +26 -14
- data/examples/api-samples/samples/sample06.rb +80 -0
- data/examples/api-samples/samples/sample07.rb +52 -0
- data/examples/api-samples/samples/sample08.rb +69 -0
- data/examples/api-samples/samples/sample09.rb +83 -0
- data/examples/api-samples/samples/sample10.rb +29 -15
- data/examples/api-samples/samples/sample11.rb +89 -37
- data/examples/api-samples/samples/sample12.rb +22 -11
- data/examples/api-samples/samples/sample13.rb +22 -10
- data/examples/api-samples/samples/sample14.rb +23 -5
- data/examples/api-samples/samples/sample15.rb +18 -7
- data/examples/api-samples/samples/sample16.rb +28 -4
- data/examples/api-samples/samples/sample17.rb +31 -5
- data/examples/api-samples/samples/sample18.rb +36 -8
- data/examples/api-samples/samples/sample19.rb +138 -18
- data/examples/api-samples/samples/sample20.rb +14 -3
- data/examples/api-samples/samples/sample21.rb +162 -23
- data/examples/api-samples/samples/sample22.rb +73 -22
- data/examples/api-samples/samples/sample23.rb +17 -6
- data/examples/api-samples/samples/sample24.rb +34 -7
- data/examples/api-samples/samples/sample25.rb +37 -12
- data/examples/api-samples/samples/sample26.rb +12 -5
- data/examples/api-samples/samples/sample27.rb +38 -12
- data/examples/api-samples/samples/sample28.rb +25 -6
- data/examples/api-samples/samples/sample29.rb +12 -12
- data/examples/api-samples/samples/sample30.rb +27 -15
- data/examples/api-samples/samples/sample31.rb +44 -33
- data/examples/api-samples/samples/sample32.rb +43 -41
- data/examples/api-samples/samples/sample33.rb +42 -14
- data/examples/api-samples/samples/sample34.rb +40 -0
- data/examples/api-samples/samples/sample35.rb +224 -0
- data/examples/api-samples/samples/sample36.rb +58 -0
- data/examples/api-samples/samples/sample37.rb +229 -0
- data/examples/api-samples/samples/sample38.rb +128 -0
- data/examples/api-samples/samples/sample39.rb +252 -0
- data/examples/api-samples/samples/sample40.rb +164 -0
- data/examples/api-samples/samples/sample41.rb +118 -0
- data/examples/api-samples/samples/sample42.rb +97 -0
- data/examples/api-samples/views/_others_samples.haml +25 -11
- data/examples/api-samples/views/index.haml +23 -11
- data/examples/api-samples/views/popup.haml +32 -0
- data/examples/api-samples/views/{sample1.haml → sample01.haml} +12 -7
- data/examples/api-samples/views/{sample2.haml → sample02.haml} +20 -15
- data/examples/api-samples/views/sample03.haml +83 -0
- data/examples/api-samples/views/sample04.haml +49 -0
- data/examples/api-samples/views/{sample5.haml → sample05.haml} +19 -14
- data/examples/api-samples/views/sample06.haml +53 -0
- data/examples/api-samples/views/sample07.haml +47 -0
- data/examples/api-samples/views/{sample8.haml → sample08.haml} +17 -12
- data/examples/api-samples/views/{sample9.haml → sample09.haml} +19 -4
- data/examples/api-samples/views/sample10.haml +18 -13
- data/examples/api-samples/views/sample11.haml +48 -19
- data/examples/api-samples/views/sample12.haml +26 -21
- data/examples/api-samples/views/sample13.haml +18 -12
- data/examples/api-samples/views/sample14.haml +21 -15
- data/examples/api-samples/views/sample15.haml +16 -9
- data/examples/api-samples/views/sample16.haml +18 -5
- data/examples/api-samples/views/sample17.haml +14 -9
- data/examples/api-samples/views/sample18.haml +13 -7
- data/examples/api-samples/views/sample19.haml +37 -8
- data/examples/api-samples/views/sample20.haml +13 -8
- data/examples/api-samples/views/sample21.haml +71 -13
- data/examples/api-samples/views/sample22.haml +53 -16
- data/examples/api-samples/views/sample23.haml +9 -4
- data/examples/api-samples/views/sample24.haml +9 -4
- data/examples/api-samples/views/sample25.haml +18 -13
- data/examples/api-samples/views/sample26.haml +8 -3
- data/examples/api-samples/views/sample27.haml +20 -14
- data/examples/api-samples/views/sample28.haml +16 -10
- data/examples/api-samples/views/sample29.haml +4 -4
- data/examples/api-samples/views/sample30.haml +16 -10
- data/examples/api-samples/views/sample31.haml +39 -32
- data/examples/api-samples/views/sample32.haml +25 -36
- data/examples/api-samples/views/sample33.haml +14 -17
- data/examples/api-samples/views/sample34.haml +48 -0
- data/examples/api-samples/views/sample35.haml +95 -0
- data/examples/api-samples/views/sample36.haml +64 -0
- data/examples/api-samples/views/sample37.haml +124 -0
- data/examples/api-samples/views/sample38.haml +115 -0
- data/examples/api-samples/views/sample39.haml +236 -0
- data/examples/api-samples/views/sample40.haml +95 -0
- data/examples/api-samples/views/{sample4.haml → sample41.haml} +90 -72
- data/examples/api-samples/views/sample42.haml +59 -0
- data/lib/groupdocs/api/helpers/rest_helper.rb +13 -1
- data/lib/groupdocs/datasource.rb +2 -1
- data/lib/groupdocs/document.rb +101 -13
- data/lib/groupdocs/document/annotation.rb +28 -13
- data/lib/groupdocs/document/annotation/marker.rb +18 -0
- data/lib/groupdocs/document/annotation/reply.rb +9 -2
- data/lib/groupdocs/document/field.rb +5 -1
- data/lib/groupdocs/job.rb +12 -2
- data/lib/groupdocs/questionnaire.rb +174 -4
- data/lib/groupdocs/questionnaire/collector.rb +21 -0
- data/lib/groupdocs/questionnaire/question.rb +19 -0
- data/lib/groupdocs/questionnaire/question/answer.rb +5 -0
- data/lib/groupdocs/questionnaire/question/conditions.rb +20 -0
- data/lib/groupdocs/signature.rb +36 -308
- data/lib/groupdocs/signature/envelope.rb +146 -4
- data/lib/groupdocs/signature/field.rb +20 -1
- data/lib/groupdocs/signature/field/location.rb +18 -7
- data/lib/groupdocs/signature/form.rb +199 -10
- data/lib/groupdocs/signature/shared/document_methods.rb +38 -0
- data/lib/groupdocs/signature/shared/entity_methods.rb +0 -1
- data/lib/groupdocs/signature/shared/field_methods.rb +13 -38
- data/lib/groupdocs/signature/shared/recipient_methods.rb +8 -0
- data/lib/groupdocs/signature/template.rb +3 -1
- data/lib/groupdocs/storage.rb +4 -1
- data/lib/groupdocs/storage/file.rb +18 -1
- data/lib/groupdocs/subscription.rb +8 -3
- data/lib/groupdocs/user.rb +8 -0
- data/lib/groupdocs/version.rb +1 -1
- data/spec/groupdocs/document/annotation_spec.rb +1 -14
- data/spec/groupdocs/subscription_spec.rb +2 -2
- metadata +86 -32
- checksums.yaml +0 -15
- data/examples/api-samples/public/docs/sample9.html +0 -200
- data/examples/api-samples/samples/sample1.rb +0 -25
- data/examples/api-samples/samples/sample2.rb +0 -29
- data/examples/api-samples/samples/sample3.rb +0 -33
- data/examples/api-samples/samples/sample4.rb +0 -51
- data/examples/api-samples/samples/sample6.rb +0 -49
- data/examples/api-samples/samples/sample7.rb +0 -42
- data/examples/api-samples/samples/sample8.rb +0 -61
- data/examples/api-samples/samples/sample9.rb +0 -48
- data/examples/api-samples/views/sample3.haml +0 -44
- data/examples/api-samples/views/sample6.haml +0 -49
- data/examples/api-samples/views/sample7.haml +0 -42
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# GET request
|
|
2
|
+
get '/sample36' do
|
|
3
|
+
haml :sample36
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# POST request
|
|
10
|
+
post '/sample36' do
|
|
11
|
+
# Set variables
|
|
12
|
+
set :client_id, params[:clientId]
|
|
13
|
+
set :private_key, params[:privateKey]
|
|
14
|
+
set :envelope, params[:envelopeGuid]
|
|
15
|
+
set :base_path, params[:basePath]
|
|
16
|
+
|
|
17
|
+
# Set download path
|
|
18
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
19
|
+
|
|
20
|
+
# Remove all files from download directory or create folder if it not there
|
|
21
|
+
if File.directory?(downloads_path)
|
|
22
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
|
23
|
+
else
|
|
24
|
+
Dir::mkdir(downloads_path)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
begin
|
|
29
|
+
# Check required variables
|
|
30
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
|
|
31
|
+
|
|
32
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
|
33
|
+
|
|
34
|
+
# Configure your access to API server
|
|
35
|
+
GroupDocs.configure do |groupdocs|
|
|
36
|
+
groupdocs.client_id = settings.client_id
|
|
37
|
+
groupdocs.private_key = settings.private_key
|
|
38
|
+
# Optionally specify API server and version
|
|
39
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Get envelope from GroupDocs Storage
|
|
43
|
+
envelope = GroupDocs::Signature::Envelope.get!(settings.envelope)
|
|
44
|
+
|
|
45
|
+
#Download signed files
|
|
46
|
+
path = envelope.signed_documents!(downloads_path)
|
|
47
|
+
|
|
48
|
+
#Get file name
|
|
49
|
+
file = path.split('/').last
|
|
50
|
+
|
|
51
|
+
message = "<span style=\"color:green\">Files from the envelope were downloaded to server's local folder. You can check them <a href=\"/downloads/#{file}\">here</a></span>"
|
|
52
|
+
rescue Exception => e
|
|
53
|
+
err = e.message
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# set variables for template
|
|
57
|
+
haml :sample36, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :envelopeGuid => settings.envelope, :message => message, :err => err}
|
|
58
|
+
end
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Route the handler url "/sample37"
|
|
2
|
+
get '/sample37' do
|
|
3
|
+
haml :sample37
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
# GET request
|
|
7
|
+
|
|
8
|
+
# Route the handler url "/sample37/signature_callback". The block function for callback with server
|
|
9
|
+
post '/sample37/signature_callback' do
|
|
10
|
+
# Get data json from callback
|
|
11
|
+
data = JSON.parse(request.body.read)
|
|
12
|
+
begin
|
|
13
|
+
|
|
14
|
+
raise 'Empty params!' if data.empty?
|
|
15
|
+
|
|
16
|
+
# Set variables from data json
|
|
17
|
+
source_id = data['SourceId']
|
|
18
|
+
event_type = data['EventType']
|
|
19
|
+
|
|
20
|
+
# Set variables
|
|
21
|
+
client_id = nil
|
|
22
|
+
private_key = nil
|
|
23
|
+
|
|
24
|
+
return if event_type != 'JobCompleted'
|
|
25
|
+
|
|
26
|
+
# Set download path
|
|
27
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
28
|
+
|
|
29
|
+
# Get private key and client_id from file user_info.txt
|
|
30
|
+
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
31
|
+
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
32
|
+
contents = contents.split(' ')
|
|
33
|
+
client_id = contents[0]
|
|
34
|
+
private_key = contents[1]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Get Envelope instance
|
|
38
|
+
envelope = GroupDocs::Signature::Envelope.get!(source_id, {:client_id => client_id, :private_key => private_key})
|
|
39
|
+
|
|
40
|
+
# Get document by envelope
|
|
41
|
+
envelope.signed_documents!(downloads_path, {:client_id => client_id, :private_key => private_key})
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
rescue Exception => e
|
|
45
|
+
err = e.message
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# Route the handler url "/sample37/check"
|
|
51
|
+
|
|
52
|
+
get '/sample37/check' do
|
|
53
|
+
|
|
54
|
+
# Check is there download directory
|
|
55
|
+
unless File.directory?("#{File.dirname(__FILE__)}/../public/downloads")
|
|
56
|
+
return 'Directory was not found.'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Get file name from download directory
|
|
60
|
+
name = nil
|
|
61
|
+
|
|
62
|
+
i = 0
|
|
63
|
+
|
|
64
|
+
# Checking, if file exist
|
|
65
|
+
while i<10 do
|
|
66
|
+
sleep(5)
|
|
67
|
+
Dir.entries("#{File.dirname(__FILE__)}/../public/downloads").each do |file|
|
|
68
|
+
name = file if file != '.' && file != '..'
|
|
69
|
+
end
|
|
70
|
+
break if name
|
|
71
|
+
i += 1
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
name
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Route the handler url "/sample37/downloads"
|
|
78
|
+
get '/sample37/downloads/:filename' do |filename|
|
|
79
|
+
# Send file with header to download it
|
|
80
|
+
send_file "#{File.dirname(__FILE__)}/../public/downloads/#{filename}", :filename => filename, :type => 'Application/octet-stream'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Route the handler url "/sample37". The function block creates new envelope
|
|
84
|
+
post '/sample37' do
|
|
85
|
+
# Set variables from form
|
|
86
|
+
set :client_id, params[:clientId]
|
|
87
|
+
set :private_key, params[:privateKey]
|
|
88
|
+
set :email, params[:email]
|
|
89
|
+
set :name, params[:name]
|
|
90
|
+
set :lastName, params[:lastName]
|
|
91
|
+
set :fileId, params[:fileId]
|
|
92
|
+
set :callback, params[:callback]
|
|
93
|
+
set :base_path, params[:basePath]
|
|
94
|
+
set :url, params[:url]
|
|
95
|
+
set :source, params[:source]
|
|
96
|
+
|
|
97
|
+
# Set download path
|
|
98
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
99
|
+
|
|
100
|
+
# Remove all files from download directory or create folder if it not there
|
|
101
|
+
if File.directory?(downloads_path)
|
|
102
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
|
103
|
+
else
|
|
104
|
+
Dir::mkdir(downloads_path)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
begin
|
|
108
|
+
# Check required variables
|
|
109
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.email.empty? or settings.name.empty? or settings.lastName.empty?
|
|
110
|
+
|
|
111
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
|
112
|
+
|
|
113
|
+
# Configure your access to API server
|
|
114
|
+
GroupDocs.configure do |groupdocs|
|
|
115
|
+
groupdocs.client_id = settings.client_id
|
|
116
|
+
groupdocs.private_key = settings.private_key
|
|
117
|
+
# Optionally specify API server and version
|
|
118
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Write client and private key to the file for callback job
|
|
122
|
+
if settings.callback
|
|
123
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
|
124
|
+
# white space is required
|
|
125
|
+
out_file.write("#{settings.client_id} ")
|
|
126
|
+
out_file.write("#{settings.private_key}")
|
|
127
|
+
out_file.close
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
file = nil
|
|
131
|
+
# get document by file GUID
|
|
132
|
+
case settings.source
|
|
133
|
+
when 'guid'
|
|
134
|
+
# Create instance of File
|
|
135
|
+
file = GroupDocs::Storage::File.new({:guid => settings.fileId}).to_document.metadata!()
|
|
136
|
+
file = file.last_view.document.file.to_document
|
|
137
|
+
when 'local'
|
|
138
|
+
# construct path
|
|
139
|
+
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
140
|
+
|
|
141
|
+
# open file
|
|
142
|
+
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
143
|
+
# make a request to API using client_id and private_key
|
|
144
|
+
file = GroupDocs::Storage::File.upload!(file_path, {}).to_document
|
|
145
|
+
when 'url'
|
|
146
|
+
# Upload file from defined url
|
|
147
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url).to_document
|
|
148
|
+
else
|
|
149
|
+
raise 'Wrong GUID source.'
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
name = file.name
|
|
153
|
+
# create envelope using user id and entered by user name
|
|
154
|
+
envelope = GroupDocs::Signature::Envelope.new
|
|
155
|
+
envelope.name = file.name
|
|
156
|
+
envelope.email_subject = 'Sing this!'
|
|
157
|
+
envelope.create!({})
|
|
158
|
+
|
|
159
|
+
# Add uploaded document to envelope
|
|
160
|
+
envelope.add_document!(file, {})
|
|
161
|
+
|
|
162
|
+
# Get role list for current user
|
|
163
|
+
roles = GroupDocs::Signature::Role.get!({})
|
|
164
|
+
|
|
165
|
+
# Create new recipient
|
|
166
|
+
recipient = GroupDocs::Signature::Recipient.new
|
|
167
|
+
recipient.email = settings.email
|
|
168
|
+
recipient.first_name = settings.name
|
|
169
|
+
recipient.last_name = settings.lastName
|
|
170
|
+
recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
|
|
171
|
+
|
|
172
|
+
# Add recipient to envelope
|
|
173
|
+
add = envelope.add_recipient!(recipient)
|
|
174
|
+
|
|
175
|
+
# Get recipient id
|
|
176
|
+
recipient.id = add[:recipient][:id]
|
|
177
|
+
|
|
178
|
+
# Get document id
|
|
179
|
+
document = envelope.documents!
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
# Get field and add the location to field
|
|
183
|
+
field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
|
|
184
|
+
field.location = {:location_x => 0.15, :location_y => 0.73, :location_w => 150, :location_h => 50, :page => 1}
|
|
185
|
+
field.name = 'EMPLOYEE SIGNATURE'
|
|
186
|
+
|
|
187
|
+
# Add field to envelope
|
|
188
|
+
envelope.add_field!(field, document[0], recipient)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# Send envelop
|
|
193
|
+
envelope.send!({:callbackUrl => settings.callback})
|
|
194
|
+
|
|
195
|
+
# Write client and private key to the file for callback job
|
|
196
|
+
if settings.callback
|
|
197
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
|
198
|
+
# white space is required
|
|
199
|
+
out_file.write("#{settings.client_id} ")
|
|
200
|
+
out_file.write("#{settings.private_key}")
|
|
201
|
+
out_file.write("#{envelope.id}")
|
|
202
|
+
out_file.close
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
#Get url from request
|
|
206
|
+
case settings.base_path
|
|
207
|
+
|
|
208
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
|
209
|
+
url = "http://stage-apps-groupdocs.dynabic.com/signature/signembed/#{envelope.id}/#{recipient.id}"
|
|
210
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
|
211
|
+
url = "http://dev-apps-groupdocs.dynabic.com/signature/signembed/#{envelope.id}/#{recipient.id}"
|
|
212
|
+
else
|
|
213
|
+
url = "https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
|
218
|
+
# Make iframe
|
|
219
|
+
iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
|
|
220
|
+
message = "<p>File was uploaded to GroupDocs. Here you can see your <strong>#{name}</strong> file in the GroupDocs Embedded Viewer.</p>"
|
|
221
|
+
rescue Exception => e
|
|
222
|
+
err = e.message
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Set variables for template
|
|
226
|
+
haml :sample37, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :email => settings.email, :name => settings.name, :lastName => settings.lastName, :iframe => iframe, :massage => message, :err => err, :callback => settings.callback,}
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# GET request
|
|
2
|
+
get '/sample38' do
|
|
3
|
+
haml :sample38
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# POST request
|
|
10
|
+
post '/sample38' do
|
|
11
|
+
# Set variables
|
|
12
|
+
set :client_id, params[:clientId]
|
|
13
|
+
set :private_key, params[:privateKey]
|
|
14
|
+
set :email, params[:email]
|
|
15
|
+
set :source, params[:source]
|
|
16
|
+
set :file_id, params[:fileId]
|
|
17
|
+
set :url, params[:url]
|
|
18
|
+
set :first_name, params[:firstName]
|
|
19
|
+
set :last_name, params[:lastName]
|
|
20
|
+
set :base_path, params[:basePath]
|
|
21
|
+
#raise params.to_yaml
|
|
22
|
+
# Set download path
|
|
23
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
24
|
+
|
|
25
|
+
# Remove all files from download directory or create folder if it not there
|
|
26
|
+
if File.directory?(downloads_path)
|
|
27
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
|
28
|
+
else
|
|
29
|
+
Dir::mkdir(downloads_path)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
# Check required variables
|
|
35
|
+
#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?
|
|
36
|
+
|
|
37
|
+
if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
|
|
38
|
+
|
|
39
|
+
# Configure your access to API server
|
|
40
|
+
GroupDocs.configure do |groupdocs|
|
|
41
|
+
groupdocs.client_id = settings.client_id
|
|
42
|
+
groupdocs.private_key = settings.private_key
|
|
43
|
+
# Optionally specify API server and version
|
|
44
|
+
groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Get document by file GUID
|
|
48
|
+
case settings.source
|
|
49
|
+
when 'guid'
|
|
50
|
+
# Create instance of File
|
|
51
|
+
file = GroupDocs::Storage::File.new({:guid => settings.file_id})
|
|
52
|
+
when 'local'
|
|
53
|
+
# Construct path
|
|
54
|
+
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
55
|
+
# Open file
|
|
56
|
+
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
57
|
+
# Make a request to API using client_id and private_key
|
|
58
|
+
file = GroupDocs::Storage::File.upload!(file_path, {})
|
|
59
|
+
when 'url'
|
|
60
|
+
# Upload file from defined url
|
|
61
|
+
file = GroupDocs::Storage::File.upload_web!(settings.url)
|
|
62
|
+
else
|
|
63
|
+
raise 'Wrong GUID source.'
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#Get all users from accaunt
|
|
67
|
+
user = GroupDocs::User.get!
|
|
68
|
+
userGuid = nil
|
|
69
|
+
users = user.users!
|
|
70
|
+
users.map do |user|
|
|
71
|
+
email = user.primary_email
|
|
72
|
+
# Check whether there is a user with entered email
|
|
73
|
+
if settings.email == email
|
|
74
|
+
# Get user GUID
|
|
75
|
+
userGuid = user.guid
|
|
76
|
+
break
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
# Check is user with entered email was founded in GroupDocs account, if not user will be created
|
|
80
|
+
if userGuid.nil?
|
|
81
|
+
userNew = GroupDocs::User.new
|
|
82
|
+
# Set email as entered email
|
|
83
|
+
userNew.primary_email = settings.email
|
|
84
|
+
# Set nick name as entered first name
|
|
85
|
+
userNew.nickname = settings.email
|
|
86
|
+
# Set first name as entered first name
|
|
87
|
+
userNew.firstname = settings.first_name
|
|
88
|
+
# Set last name as entered last name
|
|
89
|
+
userNew.lastname = settings.last_name
|
|
90
|
+
# Set roles
|
|
91
|
+
userNew.roles = [{:id => '3', :name => 'User'}]
|
|
92
|
+
|
|
93
|
+
# Update account
|
|
94
|
+
new_user = GroupDocs::User.update_account!(userNew)
|
|
95
|
+
|
|
96
|
+
guid = new_user.guid
|
|
97
|
+
# Create array with entered email for set_collaborators! method
|
|
98
|
+
emails = [settings.email]
|
|
99
|
+
document = file.to_document
|
|
100
|
+
# Make request to Ant api for set new user as annotation collaborator
|
|
101
|
+
addCollaborator = document.set_collaborators!(emails)
|
|
102
|
+
getCollaborator = document.collaborators!
|
|
103
|
+
getCollaborator.each do |reviewer|
|
|
104
|
+
reviewer.access_rights = %w(view)
|
|
105
|
+
end
|
|
106
|
+
setReviewers = document.set_reviewers! getCollaborator
|
|
107
|
+
if setReviewers
|
|
108
|
+
case settings.base_path
|
|
109
|
+
when 'https://stage-api-groupdocs.dynabic.com'
|
|
110
|
+
iframe = "https://stage-api-groupdocs.dynabic.com/document-annotation2/embed/#{file.guid}?&uid=#{guid}&download=true"
|
|
111
|
+
when 'https://dev-api-groupdocs.dynabic.com'
|
|
112
|
+
iframe = "https://dev-apps.groupdocs.com//document-annotation2/embed/#{file.guid}?&uid=#{guid}&download=true"
|
|
113
|
+
else
|
|
114
|
+
iframe = "https://apps.groupdocs.com//document-annotation2/embed/#{file.guid}?&uid=#{guid}&download=true"
|
|
115
|
+
end
|
|
116
|
+
# Construct result string
|
|
117
|
+
url = GroupDocs::Api::Request.new(:path => iframe).prepare_and_sign_url
|
|
118
|
+
iframe = "<iframe src='#{url}' width='800' height='1000'></iframe>"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
rescue Exception => e
|
|
123
|
+
err = e.message
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# set variables for template
|
|
127
|
+
haml :sample38, :locals => {:userId => settings.client_id, :fileId => file.guid, :privateKey => settings.private_key, :iframe => iframe, :email => settings.email, :firstName => settings.first_name, :lastName => settings.last_name, :err => err}
|
|
128
|
+
end
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# GET request
|
|
2
|
+
get '/sample39' do
|
|
3
|
+
haml :sample39
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
# GET request
|
|
7
|
+
get '/popup' do
|
|
8
|
+
haml :popup
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# POST request
|
|
12
|
+
post '/sample39/signature_callback' do
|
|
13
|
+
begin
|
|
14
|
+
# Get callback request
|
|
15
|
+
data = JSON.parse(request.body.read)
|
|
16
|
+
|
|
17
|
+
raise 'Empty params!' if data.empty?
|
|
18
|
+
source_id = nil
|
|
19
|
+
client_id = nil
|
|
20
|
+
private_key = nil
|
|
21
|
+
|
|
22
|
+
# Get value of SourceId
|
|
23
|
+
data.each do |key, value|
|
|
24
|
+
if key == 'SourceId'
|
|
25
|
+
source_id = value
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Get private key and client_id from file user_info.txt
|
|
30
|
+
if File.exist?("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
31
|
+
contents = File.read("#{File.dirname(__FILE__)}/../public/user_info.txt")
|
|
32
|
+
contents = contents.split(' ')
|
|
33
|
+
client_id = contents.first
|
|
34
|
+
private_key = contents.last
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Create Job instance
|
|
38
|
+
job = GroupDocs::Signature::Envelope.new({:id => source_id})
|
|
39
|
+
|
|
40
|
+
# Get document by job id
|
|
41
|
+
documents = job.documents!({}, {:client_id => client_id, :private_key => private_key}).first
|
|
42
|
+
|
|
43
|
+
# Get guid from file
|
|
44
|
+
guid = documents.file.guid
|
|
45
|
+
|
|
46
|
+
# Create new file callback_info.txt and write the guid document
|
|
47
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/callback_info.txt", 'w')
|
|
48
|
+
# White space is required
|
|
49
|
+
out_file.write("#{guid}")
|
|
50
|
+
out_file.close
|
|
51
|
+
|
|
52
|
+
rescue Exception => e
|
|
53
|
+
err = e.message
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# POST request
|
|
58
|
+
post '/sample39/check' do
|
|
59
|
+
begin
|
|
60
|
+
result = nil
|
|
61
|
+
i = 0
|
|
62
|
+
for i in 1..10
|
|
63
|
+
i +=1
|
|
64
|
+
|
|
65
|
+
# Check is downloads folder exist
|
|
66
|
+
if File.exist?("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
67
|
+
result = File.read("#{File.dirname(__FILE__)}/../public/callback_info.txt")
|
|
68
|
+
if result.nil? then break end
|
|
69
|
+
end
|
|
70
|
+
sleep(5)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Check result
|
|
74
|
+
if result == 'Error'
|
|
75
|
+
result = "File was not found. Looks like something went wrong."
|
|
76
|
+
else
|
|
77
|
+
result
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
rescue Exception => e
|
|
81
|
+
err = e.message
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# POST request
|
|
87
|
+
post '/sample39/postdata' do
|
|
88
|
+
|
|
89
|
+
data = request.body.read
|
|
90
|
+
# Decode ajax data
|
|
91
|
+
json_post_data = JSON.parse(data);
|
|
92
|
+
# Get Client ID
|
|
93
|
+
clientId = json_post_data['userId'];
|
|
94
|
+
# Get Private Key
|
|
95
|
+
privateKey = json_post_data['privateKey'];
|
|
96
|
+
#Get document for sign
|
|
97
|
+
documents = json_post_data['documents'];
|
|
98
|
+
# Get signature file
|
|
99
|
+
signers = json_post_data['signers'];
|
|
100
|
+
def strict_decode64(str)
|
|
101
|
+
str.unpack("m0").first
|
|
102
|
+
end
|
|
103
|
+
# Documents local path
|
|
104
|
+
document_path = "#{File.dirname(__FILE__)}/../public/downloads/#{documents[0]['name']}"
|
|
105
|
+
signer_path = "#{File.dirname(__FILE__)}/../public/downloads/#{signers[0]['name']}.png"
|
|
106
|
+
|
|
107
|
+
# Get base64 string
|
|
108
|
+
base64_documents = documents[0]['data'].split(',').last
|
|
109
|
+
base64_signers = signers[0]['data'].split(',').last
|
|
110
|
+
|
|
111
|
+
# Write to the files decode base64 strings
|
|
112
|
+
File.open(document_path, 'wb') do |f|
|
|
113
|
+
f.write(Base64.strict_decode64(base64_documents))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
File.open(signer_path, 'wb') do |f|
|
|
117
|
+
f.write(Base64.strict_decode64(base64_signers))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Set document for signing
|
|
121
|
+
documents = GroupDocs::Storage::File.new(:name=>documents[0]['name'], :local_path=>document_path).to_document
|
|
122
|
+
# Set signature
|
|
123
|
+
signers = GroupDocs::Signature.new(:name=>signers[0]['name'], :image_path=>signer_path)
|
|
124
|
+
signers.position = {top: 0.83319, left: 0.72171, width: 100, height: 40}
|
|
125
|
+
|
|
126
|
+
# Make request to sign documnet
|
|
127
|
+
signDocument = GroupDocs::Document.sign_documents!([documents], [signers], {}, {:client_id=>clientId, :private_key=>privateKey})
|
|
128
|
+
sleep(5)
|
|
129
|
+
# Get the document guid
|
|
130
|
+
document = GroupDocs::Signature.sign_document_status!(signDocument, {:client_id=>clientId, :private_key=>privateKey})
|
|
131
|
+
# Get file GUID
|
|
132
|
+
guid = document.guid
|
|
133
|
+
# Create array with result data
|
|
134
|
+
result = ['guid' => guid,'clientId' => clientId,'privateKey' => privateKey]
|
|
135
|
+
# Decode array to json and return json string to ajax request
|
|
136
|
+
result.to_json
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# POST request
|
|
141
|
+
post '/sample39' do
|
|
142
|
+
# set variables
|
|
143
|
+
set :client_id, params[:clientId]
|
|
144
|
+
set :private_key, params[:privateKey]
|
|
145
|
+
set :name, params[:name]
|
|
146
|
+
set :email, params[:email]
|
|
147
|
+
set :callback, params[:callbackUrl]
|
|
148
|
+
set :last_name, params[:lastName]
|
|
149
|
+
|
|
150
|
+
# Set download path
|
|
151
|
+
downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
|
|
152
|
+
|
|
153
|
+
# Remove all files from download directory or create folder if it not there
|
|
154
|
+
if File.directory?(downloads_path)
|
|
155
|
+
Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
|
|
156
|
+
else
|
|
157
|
+
Dir::mkdir(downloads_path)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
begin
|
|
161
|
+
# check required variables
|
|
162
|
+
raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.name.empty? or settings.email.empty? or settings.last_name.empty?
|
|
163
|
+
|
|
164
|
+
# Configure your access to API server
|
|
165
|
+
GroupDocs.configure do |groupdocs|
|
|
166
|
+
groupdocs.client_id = settings.client_id
|
|
167
|
+
groupdocs.private_key = settings.private_key
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Write client and private key to the file for callback job
|
|
171
|
+
if settings.callback[0]
|
|
172
|
+
out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
|
|
173
|
+
# white space is required
|
|
174
|
+
out_file.write("#{settings.client_id} ")
|
|
175
|
+
out_file.write("#{settings.private_key}")
|
|
176
|
+
out_file.close
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Construct path
|
|
180
|
+
file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
|
|
181
|
+
# Open file
|
|
182
|
+
File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
|
|
183
|
+
# Make a request to API using client_id and private_key
|
|
184
|
+
file = GroupDocs::Storage::File.upload!(file_path)
|
|
185
|
+
document = file.to_document
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# create envelope using user id and entered by user name
|
|
189
|
+
envelope = GroupDocs::Signature::Envelope.new
|
|
190
|
+
envelope.name = file.name
|
|
191
|
+
envelope.email_subject = 'Sing this!'
|
|
192
|
+
envelope.create!
|
|
193
|
+
|
|
194
|
+
# Add uploaded document to envelope
|
|
195
|
+
envelope.add_document!(document)
|
|
196
|
+
|
|
197
|
+
# Get role list for current user
|
|
198
|
+
roles = GroupDocs::Signature::Role.get!
|
|
199
|
+
|
|
200
|
+
# Create new recipient
|
|
201
|
+
recipient = GroupDocs::Signature::Recipient.new
|
|
202
|
+
recipient.email = settings.email
|
|
203
|
+
recipient.first_name = settings.name
|
|
204
|
+
recipient.last_name = settings.last_name
|
|
205
|
+
recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
|
|
206
|
+
|
|
207
|
+
# Add recipient to envelope
|
|
208
|
+
add = envelope.add_recipient!(recipient)
|
|
209
|
+
|
|
210
|
+
# Get recipient id
|
|
211
|
+
recipient.id = add[:recipient][:id]
|
|
212
|
+
|
|
213
|
+
# Get document id
|
|
214
|
+
document = envelope.documents!()
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# Get field and add the location to field
|
|
218
|
+
field = GroupDocs::Signature::Field.get!().detect { |f| f.type == :signature }
|
|
219
|
+
field.location = {:location_x => 0.15, :location_y => 0.73, :location_w => 150, :location_h => 50, :page => 1}
|
|
220
|
+
field.name = 'EMPLOYEE SIGNATURE'
|
|
221
|
+
|
|
222
|
+
# Add field to envelope
|
|
223
|
+
envelope.add_field!(field, document[0], recipient, {})
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
# Send envelop
|
|
227
|
+
envelope.send!({:callbackUrl => settings.callback})
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
#Get url from request
|
|
231
|
+
url = "https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
|
|
232
|
+
|
|
233
|
+
iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
|
|
234
|
+
# Make iframe
|
|
235
|
+
iframe = "<iframe id='downloadframe' src='#{iframe}' width='800' height='1000'></iframe>"
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
rescue Exception => e
|
|
239
|
+
err = e.message
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# set variables for template
|
|
243
|
+
haml :sample39, :locals => {:userId => settings.client_id,
|
|
244
|
+
:privateKey => settings.private_key,
|
|
245
|
+
:callback => settings.callback,
|
|
246
|
+
:email => settings.email,
|
|
247
|
+
:name => settings.name,
|
|
248
|
+
:lastName => settings.last_name,
|
|
249
|
+
:iframe => iframe,
|
|
250
|
+
:err => err}
|
|
251
|
+
end
|
|
252
|
+
|