groupdocs 1.3.0 → 1.4.0

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.
Files changed (40) hide show
  1. data/.travis.yml +4 -0
  2. data/CHANGELOG.md +32 -0
  3. data/examples/api-samples/public/css/style.css +123 -67
  4. data/examples/api-samples/public/images/help.png +0 -0
  5. data/examples/api-samples/public/images/info.png +0 -0
  6. data/examples/api-samples/public/templates/base-simple_source.html +192 -0
  7. data/examples/api-samples/public/templates/testdocument.html +101 -0
  8. data/examples/api-samples/public/templates/welcome.htm +137 -0
  9. data/examples/api-samples/samples/sample18.rb +134 -31
  10. data/examples/api-samples/views/sample18.haml +127 -9
  11. data/lib/groupdocs/api/request.rb +1 -1
  12. data/lib/groupdocs/document.rb +6 -3
  13. data/lib/groupdocs/signature.rb +6 -0
  14. data/lib/groupdocs/signature/contact.rb +42 -0
  15. data/lib/groupdocs/signature/envelope.rb +71 -0
  16. data/lib/groupdocs/signature/field.rb +21 -2
  17. data/lib/groupdocs/signature/form.rb +162 -9
  18. data/lib/groupdocs/signature/role.rb +5 -31
  19. data/lib/groupdocs/signature/shared/document_methods.rb +2 -1
  20. data/lib/groupdocs/signature/shared/entity_fields.rb +6 -16
  21. data/lib/groupdocs/signature/shared/entity_methods.rb +2 -2
  22. data/lib/groupdocs/signature/shared/field_methods.rb +56 -2
  23. data/lib/groupdocs/storage.rb +1 -0
  24. data/lib/groupdocs/storage/provider.rb +32 -0
  25. data/lib/groupdocs/user.rb +66 -0
  26. data/lib/groupdocs/version.rb +1 -1
  27. data/spec/groupdocs/signature/contact_spec.rb +21 -0
  28. data/spec/groupdocs/signature/envelope_spec.rb +53 -1
  29. data/spec/groupdocs/signature/field_spec.rb +19 -1
  30. data/spec/groupdocs/signature/form_spec.rb +47 -11
  31. data/spec/groupdocs/signature/role_spec.rb +4 -47
  32. data/spec/groupdocs/signature_spec.rb +4 -0
  33. data/spec/groupdocs/storage/provider_spec.rb +22 -0
  34. data/spec/groupdocs/user_spec.rb +54 -0
  35. data/spec/support/json/user_embed_key.json +39 -0
  36. data/spec/support/json/user_providers.json +31 -0
  37. data/spec/support/json/user_roles.json +25 -0
  38. data/spec/support/shared_examples/signature/shared/entity_fields.rb +14 -26
  39. data/spec/support/shared_examples/signature/shared/field_methods.rb +58 -34
  40. metadata +18 -4
@@ -21,7 +21,7 @@ module GroupDocs
21
21
  # @example
22
22
  # api = GroupDocs::Api::Request.new do |request|
23
23
  # request[:method] = :POST
24
- # request[:path] = "/storage/#{GroupDocs.client_id}/info"
24
+ # request[:path] = "/storage/{{client_id}}/info"
25
25
  # end
26
26
  #
27
27
  # @param [Hash] options
@@ -485,13 +485,16 @@ module GroupDocs
485
485
  # document = GroupDocs::Storage::Folder.list!.first.to_document
486
486
  # job = document.convert!(:docx)
487
487
  # sleep(5) # wait for server to finish converting
488
- # original_document = job.documents!.first
488
+ # original_document = job.documents![:inputs].first
489
489
  # converted_file = original_file.outputs.first
490
490
  # converted_file.download!(File.dirname(__FILE__))
491
491
  #
492
492
  # @param [Symbol] format
493
493
  # @param [Hash] options
494
- # @option options [Boolean] :email_results Set to true if converted document should be emailed
494
+ # @option options [Boolean] :email_results
495
+ # @option options [String] :new_description
496
+ # @option options [String] :print_script
497
+ # @option options [String] :callback
495
498
  # @param [Hash] access Access credentials
496
499
  # @option access [String] :client_id
497
500
  # @option access [String] :private_key
@@ -716,7 +719,7 @@ module GroupDocs
716
719
  api = Api::Request.new do |request|
717
720
  request[:access] = access
718
721
  request[:method] = :GET
719
- request[:path] = "/comparison/{{client_id}}/comparison/changes"
722
+ request[:path] = '/comparison/{{client_id}}/comparison/changes'
720
723
  end
721
724
  api.add_params(:resultFileId => file.guid)
722
725
  json = api.execute!
@@ -61,6 +61,10 @@ module GroupDocs
61
61
  attr_accessor :signatureImageUrl
62
62
  # @attr [String] initialsImageUrl
63
63
  attr_accessor :initialsImageUrl
64
+ # @attr [String] signatureData
65
+ attr_accessor :signatureData
66
+ # @attr [String] initialsData
67
+ attr_accessor :initialsData
64
68
  # @attr [String] createdTimeStamp
65
69
  attr_accessor :createdTimeStamp
66
70
  # @attr [String] image_path
@@ -78,6 +82,8 @@ module GroupDocs
78
82
  alias_accessor :initials_image_file_id, :initialsImageFileId
79
83
  alias_accessor :signature_image_url, :signatureImageUrl
80
84
  alias_accessor :initials_image_url, :initialsImageUrl
85
+ alias_accessor :signature_data, :signatureData
86
+ alias_accessor :initials_data, :initialsData
81
87
  alias_accessor :created_time_stamp, :createdTimeStamp
82
88
 
83
89
  #
@@ -1,6 +1,12 @@
1
1
  module GroupDocs
2
2
  class Signature::Contact < Api::Entity
3
3
 
4
+ INTEGRATION_PROVIDERS = {
5
+ :local => 0,
6
+ :groupdocs => 1,
7
+ :google => 2,
8
+ }
9
+
4
10
  #
5
11
  # Returns a list of all contacts.
6
12
  #
@@ -62,6 +68,42 @@ module GroupDocs
62
68
  end.execute!
63
69
  end
64
70
 
71
+ #
72
+ # Adds contact integration.
73
+ #
74
+ # @example Add Google contacts integration
75
+ # integration = {
76
+ # provider: :google,
77
+ # refresh_token: 'token',
78
+ # access_token: 'token',
79
+ # access_token_expiration: '2014-12-12'
80
+ # }
81
+ #
82
+ # @param [Hash] integration
83
+ # @option integration [Symbol] provider One of :local, :groupdocs or :google
84
+ # @option integration [String] refresh_token
85
+ # @option integration [String] access_token
86
+ # @option integration [String] access_token_exipration
87
+ # @param [Hash] access Access credentials
88
+ # @option access [String] :client_id
89
+ # @option access [String] :private_key
90
+ #
91
+ def self.add_integration!(integration, access = {})
92
+ payload = {
93
+ :provider => INTEGRATION_PROVIDERS[integration[:provider]],
94
+ :refreshToken => integration[:refresh_token],
95
+ :accessToken => integration[:access_token],
96
+ :accessTokenExpiration => integration[:access_token_expiration],
97
+ }
98
+
99
+ Api::Request.new do |request|
100
+ request[:access] = access
101
+ request[:method] = :POST
102
+ request[:path] = '/signature/{{client_id}}/integration'
103
+ request[:request_body] = payload
104
+ end.execute!
105
+ end
106
+
65
107
  # @attr [String] id
66
108
  attr_accessor :id
67
109
  # @attr [String] firstName
@@ -12,6 +12,7 @@ module GroupDocs
12
12
  :failed => 4,
13
13
  :completed => 5,
14
14
  :archived => 6,
15
+ :scheduled => 99,
15
16
  }
16
17
 
17
18
  include Signature::DocumentMethods
@@ -88,6 +89,8 @@ module GroupDocs
88
89
  attr_accessor :statusDateTime
89
90
  # @attr [Integer] envelopeExpireTime
90
91
  attr_accessor :envelopeExpireTime
92
+ # @attr [Boolean] isDemo
93
+ attr_accessor :isDemo
91
94
  # @attr [Symbol] status
92
95
  attr_accessor :status
93
96
 
@@ -95,6 +98,7 @@ module GroupDocs
95
98
  alias_accessor :creation_date_time, :creationDateTime
96
99
  alias_accessor :status_date_time, :statusDateTime
97
100
  alias_accessor :envelope_expire_time, :envelopeExpireTime
101
+ alias_accessor :is_demo, :isDemo
98
102
 
99
103
  #
100
104
  # Converts status to human-readable format.
@@ -172,6 +176,44 @@ module GroupDocs
172
176
  api.execute!
173
177
  end
174
178
 
179
+ #
180
+ # Delegates recipient to another one.
181
+ #
182
+ # @example
183
+ # envelope = GroupDocs::Signature::Envelope.get!("g94h5g84hj9g4gf23i40j")
184
+ # old = envelope.recipients!.first
185
+ # old.first_name = 'Johnny'
186
+ # new = GroupDocs::Signature::Recipient.new
187
+ # new.email = 'john@smith.com'
188
+ # new.first_name = 'John'
189
+ # new.last_name = 'Smith'
190
+ # envelope.delegate_recipient! old, new
191
+ #
192
+ # @param [GroupDocs::Signature::Recipient] old
193
+ # @param [GroupDocs::Signature::Recipient] new
194
+ # @param [Hash] access Access credentials
195
+ # @option access [String] :client_id
196
+ # @option access [String] :private_key
197
+ # @raise [ArgumentError] if old recipient is not GroupDocs::Signature::Recipient
198
+ # @raise [ArgumentError] if new recipient is not GroupDocs::Signature::Recipient
199
+ #
200
+ def delegate_recipient!(old, new, access = {})
201
+ old.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
202
+ "Old recipient should be GroupDocs::Signature::Recipient object, received: #{old.inspect}"
203
+ new.is_a?(GroupDocs::Signature::Recipient) or raise ArgumentError,
204
+ "New recipient should be GroupDocs::Signature::Recipient object, received: #{new.inspect}"
205
+
206
+ api = Api::Request.new do |request|
207
+ request[:access] = access
208
+ request[:method] = :POST
209
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/recipient/#{old.id}/delegate"
210
+ end
211
+ api.add_params(:email => new.email,
212
+ :firstname => new.first_name,
213
+ :lastname => new.last_name)
214
+ api.execute!
215
+ end
216
+
175
217
  #
176
218
  # Fills field with value.
177
219
  #
@@ -312,6 +354,35 @@ module GroupDocs
312
354
  filepath
313
355
  end
314
356
 
357
+ #
358
+ # Downloads signed document to given path.
359
+ #
360
+ # @param [GroupDocs::Document] document Signed document
361
+ # @param [String] path Directory to download file to
362
+ # @param [Hash] access Access credentials
363
+ # @option access [String] :client_id
364
+ # @option access [String] :private_key
365
+ # @return [String] path to file
366
+ #
367
+ def signed_document!(document, path, access = {})
368
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
369
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
370
+
371
+ response = Api::Request.new do |request|
372
+ request[:access] = access
373
+ request[:method] = :DOWNLOAD
374
+ request[:path] = "/signature/{{client_id}}/envelopes/#{id}/document/#{document.file.guid}"
375
+ end.execute!
376
+
377
+ filepath = "#{path}/#{name}.pdf"
378
+
379
+ Object::File.open(filepath, 'wb') do |file|
380
+ file.write(response)
381
+ end
382
+
383
+ filepath
384
+ end
385
+
315
386
  #
316
387
  # Returns a list of audit logs.
317
388
  #
@@ -72,7 +72,7 @@ module GroupDocs
72
72
  attr_accessor :mandatory
73
73
  # @attr [Symbol] fieldType
74
74
  attr_accessor :fieldType
75
- # @attr [Boolean] acceptableValues
75
+ # @attr [Array<String>] acceptableValues
76
76
  attr_accessor :acceptableValues
77
77
  # @attr [String] defaultValue
78
78
  attr_accessor :defaultValue
@@ -109,7 +109,6 @@ module GroupDocs
109
109
  alias_accessor :font_italic, :fontItalic
110
110
  alias_accessor :font_underline, :fontUnderline
111
111
  alias_accessor :is_system, :isSystem
112
- alias_accessor :acceptable_values, :acceptableValues
113
112
  alias_accessor :default_value, :defaultValue
114
113
  alias_accessor :text_rows, :textRows
115
114
  alias_accessor :text_columns, :textColumns
@@ -165,6 +164,26 @@ module GroupDocs
165
164
  end
166
165
  alias_method :type, :field_type
167
166
 
167
+ #
168
+ # Converts array of acceptable values to machine-readable format.
169
+ # @param [Array<String>] values
170
+ #
171
+ def acceptable_values=(values)
172
+ if values.is_a?(Array)
173
+ values = values.join(';')
174
+ end
175
+
176
+ @acceptableValues = values
177
+ end
178
+
179
+ #
180
+ # Converts acceptable values to human-readable format.
181
+ # @return [Array<String>]
182
+ #
183
+ def acceptable_values
184
+ @acceptableValues.split(';') if @acceptableValues
185
+ end
186
+
168
187
  #
169
188
  # Creates signature field.
170
189
  #
@@ -2,8 +2,13 @@ module GroupDocs
2
2
  class Signature::Form < Api::Entity
3
3
 
4
4
  include Signature::EntityMethods
5
+ include Signature::DocumentMethods
6
+ include Signature::FieldMethods
5
7
  extend Signature::ResourceMethods
6
8
 
9
+ # form doesn't have recipients
10
+ undef_method :assign_field!
11
+
7
12
  STATUSES = {
8
13
  :draft => -1,
9
14
  :in_progress => 1,
@@ -67,6 +72,10 @@ module GroupDocs
67
72
  attr_accessor :canParticipantDownloadForm
68
73
  # @attr [Symbol] status
69
74
  attr_accessor :status
75
+ # @attr [String] watermarkText
76
+ attr_accessor :watermarkText
77
+ # @attr [String] watermarkImage
78
+ attr_accessor :watermarkImage
70
79
 
71
80
  # Human-readable accessors
72
81
  alias_accessor :owner_guid, :ownerGuid
@@ -76,8 +85,9 @@ module GroupDocs
76
85
  alias_accessor :documents_count, :documentsCount
77
86
  alias_accessor :documents_pages, :documentsPages
78
87
  alias_accessor :participants_count, :participantsCount
79
- alias_accessor :fields_in_final_file_name, :fieldsInFinalFileName
80
88
  alias_accessor :can_participant_download_form, :canParticipantDownloadForm
89
+ alias_accessor :watermark_text, :watermarkText
90
+ alias_accessor :watermark_image, :watermarkImage
81
91
 
82
92
  #
83
93
  # Converts status to human-readable format.
@@ -87,28 +97,46 @@ module GroupDocs
87
97
  STATUSES.invert[@status]
88
98
  end
89
99
 
100
+ #
101
+ # Converts array of field names to machine-readable format.
102
+ # @param [Array<String>] fields
103
+ #
104
+ def fields_in_final_file_name=(fields)
105
+ if fields.is_a?(Array)
106
+ fields = fields.join(',')
107
+ end
108
+
109
+ @fieldsInFinalFileName = fields
110
+ end
111
+
112
+ #
113
+ # Converts field names to human-readable format.
114
+ # @return [Array<String>]
115
+ #
116
+ def fields_in_final_file_name
117
+ @fieldsInFinalFileName.split(',') if @fieldsInFinalFileName
118
+ end
119
+
90
120
  #
91
121
  # Creates form.
92
122
  #
93
123
  # @example
94
- # template = GroupDocs::Singature::Template!.get!('09662aab7187f31444476288ebaf7da4')
95
124
  # form = GroupDocs::Signature::Form.new
96
125
  # form.name = "Form"
97
126
  # form.create! template
98
127
  #
99
- # @param [GroupDocs::Signature::Template] template
100
128
  # @param [Hash] options Hash of options
101
- # @option options [Integer] :assembly_id Assembly GUID to use
129
+ # @option options [String] :template_id Template GUID to create form from
130
+ # @option options [Integer] :assembly_id Questionnaire identifier to create form from
102
131
  # @param [Hash] access Access credentials
103
132
  # @option access [String] :client_id
104
133
  # @option access [String] :private_key
105
134
  # @raise [ArgumentError] if template is not GroupDocs::Signature::Template
106
135
  #
107
- def create!(template, options = {}, access = {})
108
- template.is_a?(GroupDocs::Signature::Template) or raise ArgumentError,
109
- "Template should be GroupDocs::Signature::Template object, received: #{template.inspect}"
110
-
136
+ def create!(options = {}, access = {})
137
+ template_id = options.delete(:template_id)
111
138
  assembly_id = options.delete(:assembly_id)
139
+ options[:templateId] = template_id if template_id
112
140
  options[:assemblyId] = assembly_id if assembly_id
113
141
 
114
142
  api = Api::Request.new do |request|
@@ -117,7 +145,7 @@ module GroupDocs
117
145
  request[:path] = '/signature/{{client_id}}/form'
118
146
  request[:request_body] = to_hash
119
147
  end
120
- api.add_params(options.merge(:name => name, :templateId => template.id))
148
+ api.add_params(options.merge(:name => name))
121
149
  json = api.execute!
122
150
 
123
151
  self.id = json[:form][:id]
@@ -189,5 +217,130 @@ module GroupDocs
189
217
  end.execute!
190
218
  end
191
219
 
220
+ #
221
+ # Returns an array of fields for document per participant.
222
+ #
223
+ # @param [GroupDocs::Document] document
224
+ # @param [Hash] access Access credentials
225
+ # @option access [String] :client_id
226
+ # @option access [String] :private_key
227
+ # @raise [ArgumentError] if document is not GroupDocs::Document
228
+ #
229
+ def fields!(document, access = {})
230
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
231
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
232
+
233
+ json = Api::Request.new do |request|
234
+ request[:access] = access
235
+ request[:method] = :GET
236
+ request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/#{document.file.guid}/fields"
237
+ end.execute!
238
+
239
+ json[:fields].map do |field|
240
+ Signature::Field.new(field)
241
+ end
242
+ end
243
+
244
+ #
245
+ # Adds field for document.
246
+ #
247
+ # @example
248
+ # form = GroupDocs::Signature::Form.get!("g94h5g84hj9g4gf23i40j")
249
+ # field = GroupDocs::Signature::Field.get!.detect { |f| f.type == :signature }
250
+ # field.location = { location_x: 0.1, location_y: 0.1, page: 1 }
251
+ # document = form.documents!.first
252
+ # form.add_field! field, document
253
+ #
254
+ # @param [GroupDocs::Signature::Field] field
255
+ # @param [GroupDocs::Document] document
256
+ # @param [Hash] options
257
+ # @option options [Boolean] :force_new_field Set to true to force new field create
258
+ # @param [Hash] access Access credentials
259
+ # @option access [String] :client_id
260
+ # @option access [String] :private_key
261
+ # @raise [ArgumentError] if field is not GroupDocs::Signature::Field
262
+ # @raise [ArgumentError] if document is not GroupDocs::Document
263
+ # @raise [ArgumentError] if field does not specify location
264
+ #
265
+ def add_field!(field, document, opts = {}, access = {})
266
+ field.is_a?(GroupDocs::Signature::Field) or raise ArgumentError,
267
+ "Field should be GroupDocs::Signature::Field object, received: #{field.inspect}"
268
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
269
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
270
+ field.location or raise ArgumentError,
271
+ "You have to specify field location, received: #{field.location.inspect}"
272
+
273
+ opts[:force_new_field] = true if opts[:force_new_field].nil?
274
+ payload = field.to_hash # field itself
275
+ payload.merge!(field.location.to_hash) # location should added in plain view (i.e. not "location": {...})
276
+ payload.merge!(:forceNewField => opts[:force_new_field]) # create new field flag
277
+
278
+ Api::Request.new do |request|
279
+ request[:access] = access
280
+ request[:method] = :POST
281
+ request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/#{document.file.guid}/field/#{field.id}"
282
+ request[:request_body] = payload
283
+ end.execute!
284
+ end
285
+
286
+ #
287
+ # Modifies field location.
288
+ #
289
+ # @example Modify field location in template
290
+ # form = GroupDocs::Signature::Form.get!("g94h5g84hj9g4gf23i40j")
291
+ # document = form.documents!.first
292
+ # field = form.fields!(document).first
293
+ # location = field.locations.first
294
+ # location.x = 0.123
295
+ # location.y = 0.123
296
+ # location.page = 2
297
+ # form.modify_field_location! location, field, document
298
+ #
299
+ # @param [GroupDocs::Signature::Field::Location] location
300
+ # @param [GroupDocs::Signature::Field] field
301
+ # @param [GroupDocs::Document] document
302
+ # @param [Hash] access Access credentials
303
+ # @option access [String] :client_id
304
+ # @option access [String] :private_key
305
+ # @raise [ArgumentError] if location is not GroupDocs::Signature::Field::Location
306
+ # @raise [ArgumentError] if field is not GroupDocs::Signature::Field
307
+ # @raise [ArgumentError] if document is not GroupDocs::Document
308
+ #
309
+ def modify_field_location!(location, field, document, recipient, access = {})
310
+ location.is_a?(GroupDocs::Signature::Field::Location) or raise ArgumentError,
311
+ "Location should be GroupDocs::Signature::Field::Location object, received: #{location.inspect}"
312
+ field.is_a?(GroupDocs::Signature::Field) or raise ArgumentError,
313
+ "Field should be GroupDocs::Signature::Field object, received: #{field.inspect}"
314
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
315
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
316
+
317
+ Api::Request.new do |request|
318
+ request[:access] = access
319
+ request[:method] = :PUT
320
+ request[:path] = "/signature/{{client_id}}/forms/#{id}/documents/#{document.file.guid}/fields/#{field.id}/locations/#{location.id}"
321
+ request[:request_body] = location.to_hash
322
+ end.execute!
323
+ end
324
+
325
+ #
326
+ # Updates form adding fields from template.
327
+ #
328
+ # @param [GroupDocs::Signature::Template] template
329
+ # @param [Hash] access Access credentials
330
+ # @option access [String] :client_id
331
+ # @option access [String] :private_key
332
+ # @raise [ArgumentError] if template is not GroupDocs::Signature::Template
333
+ #
334
+ def update_from_template!(template, access = {})
335
+ template.is_a?(GroupDocs::Signature::Template) or raise ArgumentError,
336
+ "Template should be GroupDocs::Signature::Template object, received: #{template.inspect}"
337
+
338
+ Api::Request.new do |request|
339
+ request[:access] = access
340
+ request[:method] = :POST
341
+ request[:path] = "/signature/{{client_id}}/forms/#{form.id}/templates/#{template.id}"
342
+ end.execute!
343
+ end
344
+
192
345
  end # Signature::Form
193
346
  end # GroupDocs