groupdocs 1.5.5 → 1.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/lib/groupdocs/datasource.rb +66 -1
  3. data/lib/groupdocs/document.rb +21 -31
  4. data/lib/groupdocs/document/annotation.rb +8 -5
  5. data/lib/groupdocs/job.rb +4 -3
  6. data/lib/groupdocs/post.rb +4 -12
  7. data/lib/groupdocs/questionnaire.rb +40 -44
  8. data/lib/groupdocs/signature.rb +47 -30
  9. data/lib/groupdocs/signature/envelope.rb +35 -7
  10. data/lib/groupdocs/signature/field.rb +1 -0
  11. data/lib/groupdocs/signature/field/location.rb +6 -0
  12. data/lib/groupdocs/signature/form.rb +33 -1
  13. data/lib/groupdocs/signature/shared/document_methods.rb +1 -0
  14. data/lib/groupdocs/storage/file.rb +19 -10
  15. data/lib/groupdocs/subscription.rb +3 -10
  16. data/lib/groupdocs/version.rb +1 -1
  17. data/spec/groupdocs/datasource_spec.rb +41 -0
  18. data/spec/groupdocs/document/annotation_spec.rb +38 -6
  19. data/spec/groupdocs/document_spec.rb +258 -25
  20. data/spec/groupdocs/job_spec.rb +52 -0
  21. data/spec/groupdocs/questionnaire_spec.rb +45 -9
  22. data/spec/groupdocs/signature_spec.rb +13 -0
  23. data/spec/groupdocs/storage/file_spec.rb +68 -0
  24. data/spec/groupdocs/subscription_spec.rb +119 -0
  25. data/spec/groupdocs/user_spec.rb +75 -3
  26. data/spec/support/json/annotation_collaborators_add.json +31 -0
  27. data/spec/support/json/annotation_collaborators_clear.json +22 -0
  28. data/spec/support/json/document_html_urls.json +12 -0
  29. data/spec/support/json/document_shared_documents_get.json +2 -1
  30. data/spec/support/json/job_resources_get.json +16 -0
  31. data/spec/support/json/jobs_documents.json +49 -30
  32. data/spec/support/json/subscription_billing_set.json +21 -0
  33. data/spec/support/json/subscription_countries_get.json +93 -0
  34. data/spec/support/json/subscription_get.json +23 -0
  35. data/spec/support/json/subscription_get_plan.json +48 -0
  36. data/spec/support/json/subscription_invoices_get.json +18 -0
  37. data/spec/support/json/subscription_states_get.json +93 -0
  38. data/spec/support/json/subscription_wizard_get.json +8 -0
  39. metadata +13 -2
@@ -51,7 +51,7 @@ module GroupDocs
51
51
  json = Api::Request.new do |request|
52
52
  request[:access] = access
53
53
  request[:method] = :PUT
54
- request[:path] = "/signature/public/envelopes/#{envelope}/documents/#{document}/recipient/#{recipient}/field/#{field}"
54
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/documents/#{document.guid}/recipient/#{recipient.guid}/field/#{field.guid}"
55
55
  request[:request_body] = post_data
56
56
  end.execute!
57
57
 
@@ -69,13 +69,11 @@ module GroupDocs
69
69
  # @return [Array]
70
70
  #
71
71
  def sign_envelope!(envelope, recipient, access = {})
72
- json = Api::Request.new do |request|
72
+ Api::Request.new do |request|
73
73
  request[:access] = access
74
74
  request[:method] = :PUT
75
- request[:path] = "/signature/public/envelopes/#{envelope}/recipient/#{recipient}/sign"
75
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/recipient/#{recipient.id}/sign"
76
76
  end.execute!
77
-
78
- new(json)
79
77
  end
80
78
 
81
79
  #
@@ -91,7 +89,7 @@ module GroupDocs
91
89
  json = Api::Request.new do |request|
92
90
  request[:access] = access
93
91
  request[:method] = :GET
94
- request[:path] = "/signature/public/envelopes/#{envelope}/recipient/"
92
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/recipient/"
95
93
  end.execute!
96
94
 
97
95
  json[:recipient]
@@ -102,8 +100,8 @@ module GroupDocs
102
100
  #
103
101
  # @param [String] envelope Envelope GUID
104
102
  # @param [Hash] options
105
- # @option [String] document Document GUID
106
- # @option [String] recipient Recipient GUID
103
+ # @option options [String] :document Document GUID
104
+ # @option options [String] :recipient Recipient GUID
107
105
  # @param [Hash] access Access credentials
108
106
  # @option access [String] :client_id
109
107
  # @option access [String] :private_key
@@ -113,7 +111,7 @@ module GroupDocs
113
111
  api = Api::Request.new do |request|
114
112
  request[:access] = access
115
113
  request[:method] = :GET
116
- request[:path] = "/signature/public/envelopes/#{envelope}/fields"
114
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/fields"
117
115
  end
118
116
  api.add_params(options)
119
117
  json = api.execute!
@@ -136,7 +134,7 @@ module GroupDocs
136
134
  Api::Request.new do |request|
137
135
  request[:access] = access
138
136
  request[:method] = :GET
139
- request[:path] = "/signature/public/envelopes/#{envelope}/fields/recipient/#{recipient}/field/#{field}"
137
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/fields/recipient/#{recipient.id}/field/#{field.id}"
140
138
  end.execute!
141
139
 
142
140
  end
@@ -155,7 +153,7 @@ module GroupDocs
155
153
  json = Api::Request.new do |request|
156
154
  request[:access] = access
157
155
  request[:method] = :GET
158
- request[:path] = "/signature/public/envelopes/#{envelope}/recipient/#{recipient}"
156
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/recipient/#{recipient.id}"
159
157
  end.execute!
160
158
 
161
159
  json[:envelope]
@@ -175,10 +173,8 @@ module GroupDocs
175
173
  json = Api::Request.new do |request|
176
174
  request[:access] = access
177
175
  request[:method] = :GET
178
- request[:path] = "/signature/public/envelopes/#{envelope}/recipient/#{recipient}/documents/get"
176
+ request[:path] = "/signature/public/envelopes/#{envelope.guid}/recipient/#{recipient.id}/documents/get"
179
177
  end.execute!
180
-
181
- new(json)
182
178
  end
183
179
 
184
180
  #
@@ -194,7 +190,7 @@ module GroupDocs
194
190
  json = Api::Request.new do |request|
195
191
  request[:access] = access
196
192
  request[:method] = :GET
197
- request[:path] = "/signature/public/forms/#{form}/fill"
193
+ request[:path] = "/signature/public/forms/#{form.id}/fill"
198
194
  end.execute!
199
195
 
200
196
  json[:participant]
@@ -217,7 +213,7 @@ module GroupDocs
217
213
  api = Api::Request.new do |request|
218
214
  request[:access] = access
219
215
  request[:method] = :PUT
220
- request[:path] = "/signature/public/forms/#{form}/documents/#{document}/participant/#{participant}/field/#{field}"
216
+ request[:path] = "/signature/public/forms/#{form.id}/documents/#{document.guid}/participant/#{participant.id}/field/#{field.id}"
221
217
  end
222
218
  api.add_params(:participantAuthSignature => authentication)
223
219
  json = api.execute!
@@ -264,7 +260,7 @@ module GroupDocs
264
260
  api = Api::Request.new do |request|
265
261
  request[:access] = access
266
262
  request[:method] = :GET
267
- request[:path] = "/signature/public/forms/#{form}/fields"
263
+ request[:path] = "/signature/public/forms/#{form.id}/fields"
268
264
  end
269
265
  api.add_params(options)
270
266
  json = api.execute!
@@ -282,14 +278,19 @@ module GroupDocs
282
278
  # @option access [String] :private_key
283
279
  # @return [Array]
284
280
  #
285
- def get_signed_documents_form!(form, participant, access = {})
286
- json = Api::Request.new do |request|
281
+ def get_signed_documents_form!(path, name, form, participant, access = {})
282
+ response = Api::Request.new do |request|
287
283
  request[:access] = access
288
284
  request[:method] = :GET
289
- request[:path] = "/signature/public/forms/#{form}/participant/#{participant}/documents/get"
285
+ request[:path] = "/signature/public/forms/#{form.id}/participant/#{participant.id}/documents/get"
290
286
  end.execute!
291
287
 
292
- new(json)
288
+ filepath = "#{path}/#{name}."
289
+ Object::File.open(filepath, 'wb') do |file|
290
+ file.write(response)
291
+ end
292
+
293
+ filepath
293
294
  end
294
295
 
295
296
  #
@@ -326,32 +327,48 @@ module GroupDocs
326
327
  json = Api::Request.new do |request|
327
328
  request[:access] = access
328
329
  request[:method] = :POST
329
- request[:path] = "/signature/public/documents/#{document}/sign"
330
+ request[:path] = "/signature/public/documents/#{document.guid}/sign"
330
331
  request[:request_body] = settings
331
332
  end.execute!
332
333
 
333
334
  json[:jobId]
334
335
  end
336
+
337
+ #
338
+ # Get document fields
339
+ #
340
+ # @param [String] document Document GUID
341
+ # @param [Hash] settings Settings of the signing document
342
+ # @param [Hash] access Access credentials
343
+ # @option access [String] :client_id
344
+ # @option access [String] :private_key
345
+ # @return [Array]
346
+ #
347
+ def self.get_document_fields!(document, access = {})
348
+ Api::Request.new do |request|
349
+ request[:access] = access
350
+ request[:method] = :GET
351
+ request[:path] = "/signature/public/documents/#{document}/fields"
352
+ end.execute!
353
+ end
335
354
 
336
355
  #
337
356
  # Verify to document
338
357
  #
339
- # @param [String] document Document GUID
358
+ # @param [String] path Path to document GUID
340
359
  # @param [Hash] settings Settings of the signing document
341
360
  # @param [Hash] access Access credentials
342
361
  # @option access [String] :client_id
343
362
  # @option access [String] :private_key
344
363
  # @return [Array]
345
364
  #
346
- def self.verify!(access = {})
347
- json = Api::Request.new do |request|
365
+ def self.verify!(path, access = {})
366
+ Api::Request.new do |request|
348
367
  request[:access] = access
349
368
  request[:method] = :POST
350
369
  request[:path] = "/signature/public/verify"
351
- request[:request_body] = streem
370
+ request[:request_body] = path
352
371
  end.execute!
353
-
354
- nev(json)
355
372
  end
356
373
 
357
374
  #
@@ -363,14 +380,14 @@ module GroupDocs
363
380
  # @option access [String] :private_key
364
381
  # @return [Array]
365
382
  #
366
- def sign_document_status!(job, access = {})
383
+ def self.sign_document_status!(job, access = {})
367
384
  json = Api::Request.new do |request|
368
385
  request[:access] = access
369
386
  request[:method] = :GET
370
387
  request[:path] = "/signature/public/documents/#{job}/status"
371
388
  end.execute!
372
389
 
373
- new(json)
390
+ Storage::File.new(:guid => json[:documents][0][:documentId])
374
391
  end
375
392
 
376
393
 
@@ -424,10 +424,7 @@ module GroupDocs
424
424
  request[:access] = access
425
425
  request[:method] = :PUT
426
426
  request[:path] = "/signature/{{client_id}}/envelopes/#{id}/send"
427
- if webhook
428
- request[:request_body] = webhook
429
- request[:plain] = true
430
- end
427
+ request[:request_body] = webhook
431
428
  end.execute!
432
429
  end
433
430
 
@@ -475,16 +472,28 @@ module GroupDocs
475
472
  # @option access [String] :private_key
476
473
  # @raise [ArgumentError] if document is not GroupDocs::Document
477
474
  #
478
- def get_envelope!(document, access = {})
475
+ def get_envelope!(path, document, access = {})
479
476
  document.is_a?(GroupDocs::Document) or raise ArgumentError,
480
477
  "Document should be GroupDocs::Document object, received: #{document.inspect}"
481
478
 
482
- Api::Request.new do |request|
479
+ response = Api::Request.new do |request|
483
480
  request[:access] = access
484
481
  request[:method] = :GET
485
- request[:path] = "/signature/{{client_id}}/#{class_name.pluralize}/#{id}/document/#{document.file.guid}"
482
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/document/#{document.file.guid}"
486
483
  end.execute!
487
484
 
485
+ filepath = "#{path}/#{name}."
486
+ if documents!.size == 1
487
+ filepath << 'pdf'
488
+ else
489
+ filepath << 'zip'
490
+ end
491
+
492
+ Object::File.open(filepath, 'wb') do |file|
493
+ file.write(response)
494
+ end
495
+
496
+ filepath
488
497
  end
489
498
 
490
499
  #
@@ -515,6 +524,25 @@ module GroupDocs
515
524
  request[:method] = :PUT
516
525
  request[:path] = "/signature/{{client_id}}/envelopes/#{id}/retry"
517
526
  end.execute!
527
+ end
528
+
529
+ #
530
+ # Update envelope.
531
+ #
532
+ # @param [Hash] access Access credentials
533
+ # @option access [String] :client_id
534
+ # @option access [String] :private_key
535
+ # @return [Array]
536
+ #
537
+ def update_envelope!(template, access = {})
538
+ json = Api::Request.new do |request|
539
+ request[:access] = access
540
+ request[:method] = :POST
541
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/templates/#{template}"
542
+ end.execute!
543
+
544
+ json[:envelope]
545
+
518
546
  end
519
547
 
520
548
  end # Signature::Envelope
@@ -91,6 +91,7 @@ module GroupDocs
91
91
  # @attr [Array<GroupDocs::Signature::Field::Location>] locations
92
92
  attr_accessor :locations
93
93
 
94
+
94
95
  # Human-readable accessors
95
96
  alias_accessor :template_id, :templateId
96
97
  alias_accessor :recipient_id, :recipientId
@@ -29,6 +29,10 @@ module GroupDocs
29
29
  attr_accessor :fontItalic
30
30
  # @attr [Boolean] fontUnderline
31
31
  attr_accessor :fontUnderline
32
+ # @attr [Boolean] forceNewField
33
+ attr_accessor :forceNewField
34
+ # @attr [String] page
35
+ attr_accessor :page
32
36
 
33
37
  # Human-readable accessors
34
38
  alias_accessor :document_id, :documentId
@@ -49,6 +53,8 @@ module GroupDocs
49
53
  alias_accessor :font_bold, :fontBold
50
54
  alias_accessor :font_italic, :fontItalic
51
55
  alias_accessor :font_underline, :fontUnderline
56
+ alias_accessor :forceNewField, :forceNewField
57
+ alias_accessor :page, :page
52
58
 
53
59
  end # Signature::Field::Location
54
60
  end # GroupDocs
@@ -411,10 +411,42 @@ module GroupDocs
411
411
  Api::Request.new do |request|
412
412
  request[:access] = access
413
413
  request[:method] = :PUT
414
- request[:path] = "/signature/{{client_id}}/forms/#{form}/document/#{document.file.guid}/"
414
+ request[:path] = "/signature/{{client_id}}/forms/#{id}/document/#{document.file.guid}/"
415
415
  request[:request_body] = options
416
416
  end.execute!
417
417
  end
418
418
 
419
+ #
420
+ # Downloads signed documents to given path.
421
+ # If there is only one file in envelope, it's saved as PDF.
422
+ # If there are two or more files in envelope, it's saved as ZIP.
423
+ #
424
+ # @param [String] path Directory to download file to
425
+ # @param [Hash] access Access credentials
426
+ # @option access [String] :client_id
427
+ # @option access [String] :private_key
428
+ # @return [String] path to file
429
+ #
430
+ def signed_documents!(path, access = {})
431
+ response = Api::Request.new do |request|
432
+ request[:access] = access
433
+ request[:method] = :DOWNLOAD
434
+ request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/get"
435
+ end.execute!
436
+
437
+ filepath = "#{path}/#{name}."
438
+ if documents!.size == 1
439
+ filepath << 'pdf'
440
+ else
441
+ filepath << 'zip'
442
+ end
443
+
444
+ Object::File.open(filepath, 'wb') do |file|
445
+ file.write(response)
446
+ end
447
+
448
+ filepath
449
+ end
450
+
419
451
  end # Signature::Form
420
452
  end # GroupDocs
@@ -48,6 +48,7 @@ module GroupDocs
48
48
  file = Storage::File.new(:guid => id, :name => document[:name])
49
49
  Document.new(document.merge(:file => file))
50
50
  end
51
+
51
52
  end
52
53
 
53
54
  #
@@ -57,21 +57,24 @@ module GroupDocs
57
57
  #
58
58
  # Get shared file.
59
59
  #
60
+ # @param [String] path Path save new file which receive in response
61
+ # @param [String] name Name new file
60
62
  # @param [String] file_path
61
63
  # @param [String] user_email
62
64
  #
63
- def get_shared_file!(user_email, file_path)
65
+ def self.get_shared_file!(path, name, user_email, file_path)
64
66
  response = Api::Request.new do |request|
65
67
  request[:access] = access
66
68
  request[:method] = :GET
67
69
  request[:path] = "/storage/shared/#{user_email}/#{file_path}"
68
70
  end.execute!
69
71
 
70
- Object::File.open(file_path, 'wb') do |file|
72
+ filepath = "#{path}/#{name}"
73
+ Object::File.open(filepath, 'wb') do |file|
71
74
  file.write(response)
72
75
  end
73
76
 
74
- file_path
77
+ filepath
75
78
  end
76
79
 
77
80
  #
@@ -104,11 +107,11 @@ module GroupDocs
104
107
  # @option access [String] :private_key
105
108
  # @return [GroupDocs::Storage::File]
106
109
  #
107
- def upload_google!(path, file_id, access = {})
110
+ def self.upload_google!(path, file_id, access = {})
108
111
  api = Api::Request.new do |request|
109
112
  request[:access] = access
110
113
  request[:method] = :POST
111
- request[:path] = "/storage/{{client_id}}/google/files/#{path}/"
114
+ request[:path] = "/storage/{{client_id}}/google/files/#{path}"
112
115
  end
113
116
 
114
117
  api.add_params(:file_id => file_id)
@@ -129,17 +132,23 @@ module GroupDocs
129
132
  # @option access [String] :private_key
130
133
  # @return [GroupDocs::Storage::File]
131
134
  #
132
- def decompress!(path, file_zip, options = {}, access = {})
135
+ def self.decompress!(filepath, options = {}, access = {})
136
+ options[:path] ||= ''
137
+ options[:name] ||= Object::File.basename(filepath)
138
+ path = prepare_path("#{options[:path]}/#{options[:name]}")
139
+
133
140
  api = Api::Request.new do |request|
134
141
  request[:access] = access
135
142
  request[:method] = :POST
136
143
  request[:path] = "/storage/{{client_id}}/decompress/#{path}/"
137
- request[:request_body] = file_zip
144
+ request[:request_body] = Object::File.new(filepath, 'rb')
138
145
  end
139
- api.add_params(options)
146
+ api.add_params(:archiveType => options[:archiveType]) if options[:archiveType]
140
147
  json = api.execute!
141
148
 
142
- Storage::File.new(json)
149
+ json[:files].map do |file|
150
+ File.new(file)
151
+ end
143
152
  end
144
153
 
145
154
  # @attr [Integer] id
@@ -384,7 +393,7 @@ module GroupDocs
384
393
  Api::Request.new do |request|
385
394
  request[:access] = access
386
395
  request[:method] = :DELETE
387
- request[:path] = "/storage/{{client_id}}/trash/#{path}/"
396
+ request[:path] = "/storage/{{client_id}}/trash/#{path}"
388
397
  end.execute!
389
398
  end
390
399
 
@@ -77,7 +77,6 @@ module GroupDocs
77
77
  request[:method] = :GET
78
78
  request[:path] = '/system/{{client_id}}/subscription'
79
79
  end.execute!
80
-
81
80
  end
82
81
 
83
82
  #
@@ -90,14 +89,12 @@ module GroupDocs
90
89
  # @return [GroupDocs::Subscription]
91
90
  #
92
91
  def self.set_subscription!(plan, product_id, access = {})
93
- json = Api::Request.new do |request|
92
+ Api::Request.new do |request|
94
93
  request[:access] = access
95
94
  request[:method] = :PUT
96
95
  request[:path] = "/system/{{client_id}}/subscriptions/#{product_id}"
97
96
  request[:request_body] = plan
98
97
  end.execute!
99
-
100
- new(json)
101
98
  end
102
99
 
103
100
  #
@@ -110,14 +107,12 @@ module GroupDocs
110
107
  # @return [GroupDocs::Subscription]
111
108
  #
112
109
  def self.update_subscription!(plan, product_id, access = {})
113
- json = Api::Request.new do |request|
110
+ Api::Request.new do |request|
114
111
  request[:access] = access
115
112
  request[:method] = :POST
116
113
  request[:path] = "/system/{{client_id}}/subscriptions/#{product_id}"
117
114
  request[:request_body] = plan
118
115
  end.execute!
119
-
120
- new(json)
121
116
  end
122
117
 
123
118
  #
@@ -208,13 +203,11 @@ module GroupDocs
208
203
  # @option access [String] :private_key
209
204
  #
210
205
  def self.get_plans!(access = {})
211
- json = Api::Request.new do |request|
206
+ Api::Request.new do |request|
212
207
  request[:access] = access
213
208
  request[:method] = :GET
214
209
  request[:path] = "/system/{{client_id}}/usage"
215
210
  end
216
-
217
- new(json)
218
211
  end
219
212
 
220
213
  #