groupdocs 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/CHANGELOG.md +51 -0
  2. data/examples/api-samples/Gemfile +1 -1
  3. data/examples/api-samples/Gemfile.lock +43 -0
  4. data/examples/api-samples/public/docs/{sample2.html → sample01.html} +39 -19
  5. data/examples/api-samples/public/docs/{sample3.html → sample02.html} +28 -22
  6. data/examples/api-samples/public/docs/sample03.html +285 -0
  7. data/examples/api-samples/public/docs/{sample4.html → sample04.html} +30 -36
  8. data/examples/api-samples/public/docs/{sample5.html → sample05.html} +68 -31
  9. data/examples/api-samples/public/docs/sample06.html +299 -0
  10. data/examples/api-samples/public/docs/{sample7.html → sample07.html} +53 -18
  11. data/examples/api-samples/public/docs/{sample8.html → sample08.html} +64 -41
  12. data/examples/api-samples/public/docs/sample09.html +260 -0
  13. data/examples/api-samples/public/docs/sample10.html +67 -28
  14. data/examples/api-samples/public/docs/sample11.html +171 -55
  15. data/examples/api-samples/public/docs/sample12.html +53 -17
  16. data/examples/api-samples/public/docs/sample13.html +52 -16
  17. data/examples/api-samples/public/docs/sample14.html +51 -8
  18. data/examples/api-samples/public/docs/sample15.html +46 -10
  19. data/examples/api-samples/public/docs/sample16.html +81 -7
  20. data/examples/api-samples/public/docs/sample17.html +103 -15
  21. data/examples/api-samples/public/docs/sample18.html +117 -41
  22. data/examples/api-samples/public/docs/sample19.html +410 -36
  23. data/examples/api-samples/public/docs/sample20.html +46 -10
  24. data/examples/api-samples/public/docs/sample21.html +504 -45
  25. data/examples/api-samples/public/docs/sample22.html +166 -28
  26. data/examples/api-samples/public/docs/sample23.html +61 -25
  27. data/examples/api-samples/public/docs/sample24.html +100 -12
  28. data/examples/api-samples/public/docs/sample25.html +123 -49
  29. data/examples/api-samples/public/docs/sample26.html +41 -8
  30. data/examples/api-samples/public/docs/sample27.html +125 -50
  31. data/examples/api-samples/public/docs/sample28.html +27 -9
  32. data/examples/api-samples/public/docs/sample29.html +10 -10
  33. data/examples/api-samples/public/docs/sample30.html +70 -14
  34. data/examples/api-samples/public/docs/sample31.html +108 -67
  35. data/examples/api-samples/public/docs/sample32.html +71 -99
  36. data/examples/api-samples/public/docs/sample33.html +107 -32
  37. data/examples/api-samples/public/docs/{sample1.html → sample34.html} +58 -18
  38. data/examples/api-samples/public/docs/sample35.html +666 -0
  39. data/examples/api-samples/public/docs/{sample6.html → sample36.html} +56 -37
  40. data/examples/api-samples/public/docs/sample37.html +815 -0
  41. data/examples/api-samples/public/docs/sample38.html +508 -0
  42. data/examples/api-samples/public/docs/sample39.html +921 -0
  43. data/examples/api-samples/public/docs/sample40.html +510 -0
  44. data/examples/api-samples/public/docs/sample41.html +452 -0
  45. data/examples/api-samples/public/docs/sample42.html +311 -0
  46. data/examples/api-samples/public/templates/test_all_fields2.pdf +0 -0
  47. data/examples/api-samples/samples/sample01.rb +37 -0
  48. data/examples/api-samples/samples/sample02.rb +41 -0
  49. data/examples/api-samples/samples/sample03.rb +73 -0
  50. data/examples/api-samples/samples/sample04.rb +47 -0
  51. data/examples/api-samples/samples/{sample5.rb → sample05.rb} +26 -14
  52. data/examples/api-samples/samples/sample06.rb +80 -0
  53. data/examples/api-samples/samples/sample07.rb +52 -0
  54. data/examples/api-samples/samples/sample08.rb +69 -0
  55. data/examples/api-samples/samples/sample09.rb +83 -0
  56. data/examples/api-samples/samples/sample10.rb +29 -15
  57. data/examples/api-samples/samples/sample11.rb +89 -37
  58. data/examples/api-samples/samples/sample12.rb +22 -11
  59. data/examples/api-samples/samples/sample13.rb +22 -10
  60. data/examples/api-samples/samples/sample14.rb +23 -5
  61. data/examples/api-samples/samples/sample15.rb +18 -7
  62. data/examples/api-samples/samples/sample16.rb +28 -4
  63. data/examples/api-samples/samples/sample17.rb +31 -5
  64. data/examples/api-samples/samples/sample18.rb +36 -8
  65. data/examples/api-samples/samples/sample19.rb +138 -18
  66. data/examples/api-samples/samples/sample20.rb +14 -3
  67. data/examples/api-samples/samples/sample21.rb +162 -23
  68. data/examples/api-samples/samples/sample22.rb +73 -22
  69. data/examples/api-samples/samples/sample23.rb +17 -6
  70. data/examples/api-samples/samples/sample24.rb +34 -7
  71. data/examples/api-samples/samples/sample25.rb +37 -12
  72. data/examples/api-samples/samples/sample26.rb +12 -5
  73. data/examples/api-samples/samples/sample27.rb +38 -12
  74. data/examples/api-samples/samples/sample28.rb +25 -6
  75. data/examples/api-samples/samples/sample29.rb +12 -12
  76. data/examples/api-samples/samples/sample30.rb +27 -15
  77. data/examples/api-samples/samples/sample31.rb +44 -33
  78. data/examples/api-samples/samples/sample32.rb +43 -41
  79. data/examples/api-samples/samples/sample33.rb +42 -14
  80. data/examples/api-samples/samples/sample34.rb +40 -0
  81. data/examples/api-samples/samples/sample35.rb +224 -0
  82. data/examples/api-samples/samples/sample36.rb +58 -0
  83. data/examples/api-samples/samples/sample37.rb +229 -0
  84. data/examples/api-samples/samples/sample38.rb +128 -0
  85. data/examples/api-samples/samples/sample39.rb +252 -0
  86. data/examples/api-samples/samples/sample40.rb +164 -0
  87. data/examples/api-samples/samples/sample41.rb +118 -0
  88. data/examples/api-samples/samples/sample42.rb +97 -0
  89. data/examples/api-samples/views/_others_samples.haml +25 -11
  90. data/examples/api-samples/views/index.haml +23 -11
  91. data/examples/api-samples/views/popup.haml +32 -0
  92. data/examples/api-samples/views/{sample1.haml → sample01.haml} +12 -7
  93. data/examples/api-samples/views/{sample2.haml → sample02.haml} +20 -15
  94. data/examples/api-samples/views/sample03.haml +83 -0
  95. data/examples/api-samples/views/sample04.haml +49 -0
  96. data/examples/api-samples/views/{sample5.haml → sample05.haml} +19 -14
  97. data/examples/api-samples/views/sample06.haml +53 -0
  98. data/examples/api-samples/views/sample07.haml +47 -0
  99. data/examples/api-samples/views/{sample8.haml → sample08.haml} +17 -12
  100. data/examples/api-samples/views/{sample9.haml → sample09.haml} +19 -4
  101. data/examples/api-samples/views/sample10.haml +18 -13
  102. data/examples/api-samples/views/sample11.haml +48 -19
  103. data/examples/api-samples/views/sample12.haml +26 -21
  104. data/examples/api-samples/views/sample13.haml +18 -12
  105. data/examples/api-samples/views/sample14.haml +21 -15
  106. data/examples/api-samples/views/sample15.haml +16 -9
  107. data/examples/api-samples/views/sample16.haml +18 -5
  108. data/examples/api-samples/views/sample17.haml +14 -9
  109. data/examples/api-samples/views/sample18.haml +13 -7
  110. data/examples/api-samples/views/sample19.haml +37 -8
  111. data/examples/api-samples/views/sample20.haml +13 -8
  112. data/examples/api-samples/views/sample21.haml +71 -13
  113. data/examples/api-samples/views/sample22.haml +53 -16
  114. data/examples/api-samples/views/sample23.haml +9 -4
  115. data/examples/api-samples/views/sample24.haml +9 -4
  116. data/examples/api-samples/views/sample25.haml +18 -13
  117. data/examples/api-samples/views/sample26.haml +8 -3
  118. data/examples/api-samples/views/sample27.haml +20 -14
  119. data/examples/api-samples/views/sample28.haml +16 -10
  120. data/examples/api-samples/views/sample29.haml +4 -4
  121. data/examples/api-samples/views/sample30.haml +16 -10
  122. data/examples/api-samples/views/sample31.haml +39 -32
  123. data/examples/api-samples/views/sample32.haml +25 -36
  124. data/examples/api-samples/views/sample33.haml +14 -17
  125. data/examples/api-samples/views/sample34.haml +48 -0
  126. data/examples/api-samples/views/sample35.haml +95 -0
  127. data/examples/api-samples/views/sample36.haml +64 -0
  128. data/examples/api-samples/views/sample37.haml +124 -0
  129. data/examples/api-samples/views/sample38.haml +115 -0
  130. data/examples/api-samples/views/sample39.haml +236 -0
  131. data/examples/api-samples/views/sample40.haml +95 -0
  132. data/examples/api-samples/views/{sample4.haml → sample41.haml} +90 -72
  133. data/examples/api-samples/views/sample42.haml +59 -0
  134. data/lib/groupdocs/api/helpers/rest_helper.rb +13 -1
  135. data/lib/groupdocs/datasource.rb +2 -1
  136. data/lib/groupdocs/document.rb +101 -13
  137. data/lib/groupdocs/document/annotation.rb +28 -13
  138. data/lib/groupdocs/document/annotation/marker.rb +18 -0
  139. data/lib/groupdocs/document/annotation/reply.rb +9 -2
  140. data/lib/groupdocs/document/field.rb +5 -1
  141. data/lib/groupdocs/job.rb +12 -2
  142. data/lib/groupdocs/questionnaire.rb +174 -4
  143. data/lib/groupdocs/questionnaire/collector.rb +21 -0
  144. data/lib/groupdocs/questionnaire/question.rb +19 -0
  145. data/lib/groupdocs/questionnaire/question/answer.rb +5 -0
  146. data/lib/groupdocs/questionnaire/question/conditions.rb +20 -0
  147. data/lib/groupdocs/signature.rb +36 -308
  148. data/lib/groupdocs/signature/envelope.rb +146 -4
  149. data/lib/groupdocs/signature/field.rb +20 -1
  150. data/lib/groupdocs/signature/field/location.rb +18 -7
  151. data/lib/groupdocs/signature/form.rb +199 -10
  152. data/lib/groupdocs/signature/shared/document_methods.rb +38 -0
  153. data/lib/groupdocs/signature/shared/entity_methods.rb +0 -1
  154. data/lib/groupdocs/signature/shared/field_methods.rb +13 -38
  155. data/lib/groupdocs/signature/shared/recipient_methods.rb +8 -0
  156. data/lib/groupdocs/signature/template.rb +3 -1
  157. data/lib/groupdocs/storage.rb +4 -1
  158. data/lib/groupdocs/storage/file.rb +18 -1
  159. data/lib/groupdocs/subscription.rb +8 -3
  160. data/lib/groupdocs/user.rb +8 -0
  161. data/lib/groupdocs/version.rb +1 -1
  162. data/spec/groupdocs/document/annotation_spec.rb +1 -14
  163. data/spec/groupdocs/subscription_spec.rb +2 -2
  164. metadata +86 -32
  165. checksums.yaml +0 -15
  166. data/examples/api-samples/public/docs/sample9.html +0 -200
  167. data/examples/api-samples/samples/sample1.rb +0 -25
  168. data/examples/api-samples/samples/sample2.rb +0 -29
  169. data/examples/api-samples/samples/sample3.rb +0 -33
  170. data/examples/api-samples/samples/sample4.rb +0 -51
  171. data/examples/api-samples/samples/sample6.rb +0 -49
  172. data/examples/api-samples/samples/sample7.rb +0 -42
  173. data/examples/api-samples/samples/sample8.rb +0 -61
  174. data/examples/api-samples/samples/sample9.rb +0 -48
  175. data/examples/api-samples/views/sample3.haml +0 -44
  176. data/examples/api-samples/views/sample6.haml +0 -49
  177. data/examples/api-samples/views/sample7.haml +0 -42
@@ -3,39 +3,152 @@ get '/sample21' do
3
3
  haml :sample21
4
4
  end
5
5
 
6
+ # POST request
7
+ post '/sample21/signature_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::Signature::Envelope.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[0].file.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 '/sample21/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 '/sample21/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
+
6
72
  # POST request
7
73
  post '/sample21' do
8
74
  # set variables
9
- set :client_id, params[:client_id]
10
- set :private_key, params[:private_key]
75
+ set :client_id, params[:clientId]
76
+ set :private_key, params[:privateKey]
11
77
  set :email, params[:email]
12
78
  set :name, params[:name]
13
79
  set :lastName, params[:lastName]
14
- set :file, params[:file]
80
+ set :fileId, params[:fileId]
81
+ set :callback, params[:callback]
82
+ set :base_path, params[:basePath]
83
+ set :url, params[:url]
84
+ set :source, params[:source]
85
+
86
+ # Set download path
87
+ downloads_path = "#{File.dirname(__FILE__)}/../public/downloads"
88
+
89
+ # Remove all files from download directory or create folder if it not there
90
+ if File.directory?(downloads_path)
91
+ Dir.foreach(downloads_path) { |f| fn = File.join(downloads_path, f); File.delete(fn) if f != '.' && f != '..' }
92
+ else
93
+ Dir::mkdir(downloads_path)
94
+ end
15
95
 
16
96
  begin
97
+ # Check required variables
98
+ 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?
99
+
100
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
17
101
 
18
- # check required variables
19
- 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? or settings.file.nil?
102
+ # Configure your access to API server
103
+ GroupDocs.configure do |groupdocs|
104
+ groupdocs.client_id = settings.client_id
105
+ groupdocs.private_key = settings.private_key
106
+ # Optionally specify API server and version
107
+ groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
108
+ end
20
109
 
21
- # construct path
22
- filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
23
- # open file
24
- File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
25
- # upload file
26
- file = GroupDocs::Storage::File.upload!(filepath, {}, client_id: settings.client_id, private_key: settings.private_key)
110
+ # Write client and private key to the file for callback job
111
+ if settings.callback
112
+ out_file = File.new("#{File.dirname(__FILE__)}/../public/user_info.txt", 'w')
113
+ # white space is required
114
+ out_file.write("#{settings.client_id} ")
115
+ out_file.write("#{settings.private_key}")
116
+ out_file.close
117
+ end
27
118
 
119
+ file = nil
120
+ # get document by file GUID
121
+ case settings.source
122
+ when 'guid'
123
+ # Create instance of File
124
+ file = GroupDocs::Storage::File.new({:guid => settings.fileId}).to_document.metadata!()
125
+ file = file.last_view.document.file.to_document
126
+ when 'local'
127
+ # construct path
128
+ file_path = "#{Dir.tmpdir}/#{params[:file][:filename]}"
129
+ # open file
130
+ File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
131
+ # make a request to API using client_id and private_key
132
+ file = GroupDocs::Storage::File.upload!(file_path, {}).to_document
133
+ when 'url'
134
+ # Upload file from defined url
135
+ file = GroupDocs::Storage::File.upload_web!(settings.url).to_document
136
+ else
137
+ raise 'Wrong GUID source.'
138
+ end
139
+
140
+ name = file.name
28
141
  # create envelope using user id and entered by user name
29
142
  envelope = GroupDocs::Signature::Envelope.new
30
- envelope.name = params[:file][:filename]
143
+ envelope.name = file.name
31
144
  envelope.email_subject = 'Sing this!'
32
- envelope.create!({}, client_id: settings.client_id, private_key: settings.private_key)
145
+ envelope.create!({})
33
146
 
34
147
  # Add uploaded document to envelope
35
- envelope.add_document!(file.to_document, {}, {client_id: settings.client_id, private_key: settings.private_key})
148
+ envelope.add_document!(file, {})
36
149
 
37
150
  # Get role list for current user
38
- roles = GroupDocs::Signature::Role.get!({}, {client_id: settings.client_id, private_key: settings.private_key})
151
+ roles = GroupDocs::Signature::Role.get!({})
39
152
 
40
153
  # Create new recipient
41
154
  recipient = GroupDocs::Signature::Recipient.new
@@ -45,21 +158,47 @@ post '/sample21' do
45
158
  recipient.role_id = roles.detect { |role| role.name == 'Signer' }.id
46
159
 
47
160
  # Add recipient to envelope
48
- add = envelope.add_recipient!(recipient, {client_id: settings.client_id, private_key: settings.private_key})
161
+ add = envelope.add_recipient!(recipient)
162
+
163
+ # Get recipient id
164
+ recipient.id = add[:recipient][:id]
165
+
166
+ # Get document id
167
+ document = envelope.documents!({})
168
+
169
+
170
+ # Get field and add the location to field
171
+ field = GroupDocs::Signature::Field.get!({}).detect { |f| f.type == :signature }
172
+ field.location = {:location_x => 0.15, :location_y => 0.73, :location_w => 150, :location_h => 50, :page => 1}
173
+ field.name = 'EMPLOYEE SIGNATURE'
174
+
175
+ # Add field to envelope
176
+ envelope.add_field!(field, document[0], recipient, {})
49
177
 
50
- # get recipient id
51
- recipient_id = add[:recipient][:id]
52
178
 
53
179
  # Send envelop
54
- envelope.send!(nil, {client_id: settings.client_id, private_key: settings.private_key})
180
+ envelope.send!({:callbackUrl => settings.callback})
55
181
 
56
- # Make iframe
57
- iframe = "<iframe src='https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient_id}' frameborder='0' width='720' height='600'></iframe>"
182
+ #Get url from request
183
+ case settings.base_path
184
+
185
+ when 'https://stage-api-groupdocs.dynabic.com'
186
+ url = "http://stage-apps-groupdocs.dynabic.com/signature/signembed/#{envelope.id}/#{recipient.id}"
187
+ when 'https://dev-api-groupdocs.dynabic.com'
188
+ url = "http://dev-apps-groupdocs.dynabic.com/signature/signembed/#{envelope.id}/#{recipient.id}"
189
+ else
190
+ url = "https://apps.groupdocs.com/signature/signembed/#{envelope.id}/#{recipient.id}"
191
+ end
58
192
 
193
+
194
+ iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
195
+ # Make iframe
196
+ iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
197
+ message = "<p>File was uploaded to GroupDocs. Here you can see your <strong>#{name}</strong> file in the GroupDocs Embedded Viewer.</p>"
59
198
  rescue Exception => e
60
199
  err = e.message
61
200
  end
62
201
 
63
- # set variables for template
64
- haml :sample21, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :email => settings.email, :name => settings.name, :lastName => settings.lastName, :iframe => iframe, :err => err}
202
+ # Set variables for template
203
+ haml :sample21, :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,}
65
204
  end
@@ -5,48 +5,99 @@ end
5
5
 
6
6
  # POST request
7
7
  post '/sample22' do
8
- # set variables
9
- set :client_id, params[:client_id]
10
- set :private_key, params[:private_key]
8
+ # Set variables
9
+ set :client_id, params[:clientId]
10
+ set :private_key, params[:privateKey]
11
11
  set :fileId, params[:fileId]
12
12
  set :email, params[:email]
13
- set :first_name, params[:first_name]
14
- set :last_name, params[:last_name]
13
+ set :first_name, params[:firstName]
14
+ set :last_name, params[:lastName]
15
+ set :base_path, params[:basePath]
16
+ set :url, params[:url]
17
+ set :source, params[:source]
18
+
15
19
 
16
20
  begin
17
21
 
18
- # check required variables
19
- raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.fileId.empty? or settings.email.empty? or settings.first_name.empty? or settings.last_name.empty?
22
+ # Check required variables
23
+ raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.email.empty? or settings.first_name.empty? or settings.last_name.empty?
24
+
25
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
26
+
27
+ # Configure your access to API server
28
+ GroupDocs.configure do |groupdocs|
29
+ groupdocs.client_id = settings.client_id
30
+ groupdocs.private_key = settings.private_key
31
+ # Optionally specify API server and version
32
+ groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
33
+ end
34
+ file = nil
20
35
 
21
- # create new user
36
+ # get document by file GUID
37
+ case settings.source
38
+ when 'guid'
39
+ # Create instance of File
40
+ file = GroupDocs::Storage::File.new({:guid => settings.fileId})
41
+ when 'local'
42
+ filepath = "#{Dir.tmpdir}/#{params[:file][:filename]}"
43
+ # Open file
44
+ File.open(filepath, 'wb') { |f| f.write(params[:file][:tempfile].read) }
45
+ # Make a request to API using client_id and private_key
46
+ file = GroupDocs::Storage::File.upload!(filepath, {})
47
+ when 'url'
48
+ # Upload file from defined url
49
+ file = GroupDocs::Storage::File.upload_web!(settings.url)
50
+ else
51
+ raise 'Wrong GUID source.'
52
+ end
53
+
54
+
55
+ file = file.to_document
56
+ # Create new user
22
57
  user = GroupDocs::User.new
58
+
23
59
  user.primary_email = settings.email
24
- user.nickname = settings.first_name
60
+ user.nickname = settings.email
25
61
  user.first_name = settings.first_name
26
62
  user.last_name = settings.last_name
27
63
 
28
- # update account
29
- GroupDocs::User.update_account!(user, {client_id: settings.client_id, private_key: settings.private_key})
64
+ user.roles = [{:id => '3', :name => 'User'}]
65
+ # Update account
66
+ new_user = GroupDocs::User.update_account!(user)
67
+
68
+
69
+
70
+ # Set new collaboration
71
+ file.set_collaborators!([settings.email], 2)
72
+
73
+ # Get all collaborations
74
+ collaborations = file.collaborators!()
75
+
76
+ # Set document reviewers
77
+ file.set_reviewers!(collaborations)
78
+
30
79
 
31
- # create file from GUID
32
- file = GroupDocs::Storage::File.new(guid: settings.fileId)
80
+ #Get url from request
81
+ case settings.base_path
33
82
 
34
- # create document from file
35
- document = GroupDocs::Document.new(file: file)
83
+ when 'https://stage-api-groupdocs.dynabic.com'
84
+ url = "http://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/#{file.file.guid}?uid = #{new_user.guid}&download=true"
85
+ when 'https://dev-api-groupdocs.dynabic.com'
86
+ url = "http://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/#{file.file.guid}?uid = #{new_user.guid}&download=true"
87
+ else
88
+ url = "https://apps.groupdocs.com/document-annotation2/embed/#{file.file.guid}?uid = #{new_user.guid}&download=true"
89
+ end
36
90
 
37
- # set new collaboration
38
- document.set_collaborators!([settings.email], 2, {:client_id => settings.client_id, :private_key => settings.private_key})
91
+ # Add the signature to url the request
39
92
 
40
- # get all collaborations
41
- collaborations = document.collaborators!({:client_id => settings.client_id, :private_key => settings.private_key})
93
+ iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
42
94
 
43
- # set document reviewers
44
- document.set_reviewers!(collaborations, {:client_id => settings.client_id, :private_key => settings.private_key})
95
+ iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
45
96
 
46
97
  rescue Exception => e
47
98
  err = e.message
48
99
  end
49
100
 
50
101
  # set variables for template
51
- haml :sample22, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.fileId, :email => settings.email, :first_name => settings.first_name, :last_name => settings.last_name, :err => err}
102
+ haml :sample22, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :fileId => settings.fileId, :email => settings.email, :firstName => settings.first_name, :lastName => settings.last_name, :iframe => iframe, :err => err}
52
103
  end
@@ -7,16 +7,27 @@ end
7
7
  post '/sample23' do
8
8
  # set variables
9
9
 
10
- set :client_id, params[:client_id]
11
- set :private_key, params[:private_key]
10
+ set :client_id, params[:clientId]
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 :base_path, params[:basePath]
15
16
 
16
17
  begin
17
18
  # check required variables
18
19
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty?
19
20
 
21
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
22
+
23
+ # Configure your access to API server
24
+ GroupDocs.configure do |groupdocs|
25
+ groupdocs.client_id = settings.client_id
26
+ groupdocs.private_key = settings.private_key
27
+ # Optionally specify API server and version
28
+ groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
29
+ end
30
+
20
31
  # get document by file GUID
21
32
  case settings.source
22
33
  when 'guid'
@@ -28,10 +39,10 @@ post '/sample23' do
28
39
  # Open file
29
40
  File.open(file_path, 'wb') { |f| f.write(params[:file][:tempfile].read) }
30
41
  # 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})
42
+ file = GroupDocs::Storage::File.upload!(file_path, {})
32
43
  when 'url'
33
44
  # Upload file from defined url
34
- file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
45
+ file = GroupDocs::Storage::File.upload_web!(settings.url)
35
46
  else
36
47
  raise 'Wrong GUID source.'
37
48
  end
@@ -43,8 +54,8 @@ post '/sample23' do
43
54
  document = file.to_document
44
55
 
45
56
  #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
57
+ page_image = document.page_images!(700, 700, {})
58
+
48
59
  rescue Exception => e
49
60
  err = e.message
50
61
  end
@@ -6,25 +6,52 @@ end
6
6
  # POST request
7
7
  post '/sample24' do
8
8
  # set variables
9
- set :client_id, params[:client_id]
10
- set :private_key, params[:private_key]
9
+ set :client_id, params[:clientId]
10
+ set :private_key, params[:privateKey]
11
11
  set :url, params[:url]
12
+ set :base_path, params[:basePath]
12
13
 
13
14
  begin
14
- # check required variables
15
+ # Check required variables
15
16
  raise 'Please enter all required parameters' if settings.client_id.empty? or settings.private_key.empty? or settings.url.nil?
16
17
 
17
- # upload web file
18
+ if settings.base_path.empty? then settings.base_path = 'https://api.groupdocs.com' end
19
+
20
+ # Configure your access to API server
21
+ GroupDocs.configure do |groupdocs|
22
+ groupdocs.client_id = settings.client_id
23
+ groupdocs.private_key = settings.private_key
24
+ # Optionally specify API server and version
25
+ groupdocs.api_server = settings.base_path # default is 'https://api.groupdocs.com'
26
+ end
27
+
28
+ # Upload web file
18
29
  file = GroupDocs::Storage::File.upload_web!(settings.url, {:client_id => settings.client_id, :private_key => settings.private_key})
19
30
 
20
- # construct result messages
31
+ # Construct result messages
21
32
  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>"
33
+
34
+ #Get url from request
35
+ case settings.base_path
36
+
37
+ when 'https://stage-api-groupdocs.dynabic.com'
38
+ url = "http://stage-apps-groupdocs.dynabic.com/document-viewer/embed/#{file.guid}"
39
+ when 'https://dev-api-groupdocs.dynabic.com'
40
+ url = "http://dev-apps-groupdocs.dynabic.com/document-viewer/embed/#{file.guid}"
41
+ else
42
+ url = "https://apps.groupdocs.com/document-viewer/embed/#{file.guid}"
43
+ end
44
+
45
+ # Add the signature to url te request
46
+ iframe = GroupDocs::Api::Request.new(:path => url).prepare_and_sign_url
47
+
48
+ # Construct result iframe
49
+ iframe = "<iframe src='#{iframe}' frameborder='0' width='720' height='600'></iframe>"
23
50
 
24
51
  rescue Exception => e
25
52
  err = e.message
26
53
  end
27
54
 
28
- # set variables for template
55
+ # Set variables for template
29
56
  haml :sample24, :locals => {:userId => settings.client_id, :privateKey => settings.private_key, :iframe => iframe, :message => message, :err => err}
30
57
  end