groupdocs 0.1.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 (129) hide show
  1. data/.travis.yml +5 -0
  2. data/Gemfile +3 -0
  3. data/README.md +141 -0
  4. data/Rakefile +9 -0
  5. data/groupdocs.gemspec +28 -0
  6. data/lib/groupdocs.rb +53 -0
  7. data/lib/groupdocs/api.rb +3 -0
  8. data/lib/groupdocs/api/entity.rb +113 -0
  9. data/lib/groupdocs/api/helpers.rb +5 -0
  10. data/lib/groupdocs/api/helpers/access_helper.rb +56 -0
  11. data/lib/groupdocs/api/helpers/actions_helper.rb +48 -0
  12. data/lib/groupdocs/api/helpers/rest_helper.rb +89 -0
  13. data/lib/groupdocs/api/helpers/status_helper.rb +48 -0
  14. data/lib/groupdocs/api/helpers/url_helper.rb +89 -0
  15. data/lib/groupdocs/api/request.rb +73 -0
  16. data/lib/groupdocs/api/sugar/lookup.rb +48 -0
  17. data/lib/groupdocs/datasource.rb +162 -0
  18. data/lib/groupdocs/datasource/field.rb +44 -0
  19. data/lib/groupdocs/document.rb +513 -0
  20. data/lib/groupdocs/document/annotation.rb +215 -0
  21. data/lib/groupdocs/document/annotation/reply.rb +167 -0
  22. data/lib/groupdocs/document/change.rb +35 -0
  23. data/lib/groupdocs/document/field.rb +27 -0
  24. data/lib/groupdocs/document/metadata.rb +26 -0
  25. data/lib/groupdocs/document/rectangle.rb +24 -0
  26. data/lib/groupdocs/document/view.rb +36 -0
  27. data/lib/groupdocs/errors.rb +10 -0
  28. data/lib/groupdocs/job.rb +201 -0
  29. data/lib/groupdocs/questionnaire.rb +221 -0
  30. data/lib/groupdocs/questionnaire/execution.rb +120 -0
  31. data/lib/groupdocs/questionnaire/page.rb +43 -0
  32. data/lib/groupdocs/questionnaire/question.rb +75 -0
  33. data/lib/groupdocs/questionnaire/question/answer.rb +10 -0
  34. data/lib/groupdocs/storage.rb +37 -0
  35. data/lib/groupdocs/storage/file.rb +248 -0
  36. data/lib/groupdocs/storage/folder.rb +314 -0
  37. data/lib/groupdocs/storage/package.rb +42 -0
  38. data/lib/groupdocs/user.rb +50 -0
  39. data/lib/groupdocs/version.rb +3 -0
  40. data/spec/groupdocs/api/entity_spec.rb +54 -0
  41. data/spec/groupdocs/api/helpers/access_helper_spec.rb +89 -0
  42. data/spec/groupdocs/api/helpers/actions_helper_spec.rb +51 -0
  43. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +187 -0
  44. data/spec/groupdocs/api/helpers/status_helper_spec.rb +85 -0
  45. data/spec/groupdocs/api/helpers/url_helper_spec.rb +93 -0
  46. data/spec/groupdocs/api/request_spec.rb +85 -0
  47. data/spec/groupdocs/datasource/field_spec.rb +50 -0
  48. data/spec/groupdocs/datasource_spec.rb +156 -0
  49. data/spec/groupdocs/document/annotation/reply_spec.rb +179 -0
  50. data/spec/groupdocs/document/annotation_spec.rb +226 -0
  51. data/spec/groupdocs/document/change_spec.rb +35 -0
  52. data/spec/groupdocs/document/field_spec.rb +31 -0
  53. data/spec/groupdocs/document/metadata_spec.rb +26 -0
  54. data/spec/groupdocs/document/rectangle_spec.rb +34 -0
  55. data/spec/groupdocs/document/view_spec.rb +36 -0
  56. data/spec/groupdocs/document_spec.rb +509 -0
  57. data/spec/groupdocs/errors_spec.rb +7 -0
  58. data/spec/groupdocs/job_spec.rb +196 -0
  59. data/spec/groupdocs/questionnaire/execution_spec.rb +136 -0
  60. data/spec/groupdocs/questionnaire/page_spec.rb +50 -0
  61. data/spec/groupdocs/questionnaire/question/answer_spec.rb +11 -0
  62. data/spec/groupdocs/questionnaire/question_spec.rb +84 -0
  63. data/spec/groupdocs/questionnaire_spec.rb +217 -0
  64. data/spec/groupdocs/storage/file_spec.rb +242 -0
  65. data/spec/groupdocs/storage/folder_spec.rb +310 -0
  66. data/spec/groupdocs/storage/package_spec.rb +41 -0
  67. data/spec/groupdocs/storage_spec.rb +27 -0
  68. data/spec/groupdocs/user_spec.rb +53 -0
  69. data/spec/groupdocs_spec.rb +56 -0
  70. data/spec/spec_helper.rb +46 -0
  71. data/spec/support/files/resume.pdf +0 -0
  72. data/spec/support/json/annotation_collaborators_set.json +16 -0
  73. data/spec/support/json/annotation_create.json +12 -0
  74. data/spec/support/json/annotation_list.json +32 -0
  75. data/spec/support/json/annotation_remove.json +9 -0
  76. data/spec/support/json/annotation_replies_create.json +9 -0
  77. data/spec/support/json/annotation_replies_get.json +25 -0
  78. data/spec/support/json/comparison_changes.json +46 -0
  79. data/spec/support/json/comparison_compare.json +8 -0
  80. data/spec/support/json/comparison_document.json +10 -0
  81. data/spec/support/json/datasource_add.json +8 -0
  82. data/spec/support/json/datasource_get.json +22 -0
  83. data/spec/support/json/datasource_remove.json +8 -0
  84. data/spec/support/json/datasource_update.json +8 -0
  85. data/spec/support/json/document_access_info_get.json +14 -0
  86. data/spec/support/json/document_convert.json +8 -0
  87. data/spec/support/json/document_datasource.json +10 -0
  88. data/spec/support/json/document_fields.json +34 -0
  89. data/spec/support/json/document_formats.json +8 -0
  90. data/spec/support/json/document_metadata.json +15 -0
  91. data/spec/support/json/document_questionnaire_create.json +9 -0
  92. data/spec/support/json/document_questionnaires.json +23 -0
  93. data/spec/support/json/document_sharers_remove.json +8 -0
  94. data/spec/support/json/document_sharers_set.json +16 -0
  95. data/spec/support/json/document_views.json +32 -0
  96. data/spec/support/json/file_compress.json +8 -0
  97. data/spec/support/json/file_copy.json +14 -0
  98. data/spec/support/json/file_delete.json +5 -0
  99. data/spec/support/json/file_move.json +14 -0
  100. data/spec/support/json/file_upload.json +8 -0
  101. data/spec/support/json/folder_create.json +8 -0
  102. data/spec/support/json/folder_delete.json +5 -0
  103. data/spec/support/json/folder_list.json +21 -0
  104. data/spec/support/json/folder_move.json +8 -0
  105. data/spec/support/json/folder_sharers_get.json +16 -0
  106. data/spec/support/json/folder_sharers_remove.json +8 -0
  107. data/spec/support/json/folder_sharers_set.json +16 -0
  108. data/spec/support/json/job_add_url.json +8 -0
  109. data/spec/support/json/job_create.json +8 -0
  110. data/spec/support/json/job_documents.json +39 -0
  111. data/spec/support/json/job_file_add.json +8 -0
  112. data/spec/support/json/job_update.json +7 -0
  113. data/spec/support/json/jobs_get.json +52 -0
  114. data/spec/support/json/package_create.json +7 -0
  115. data/spec/support/json/questionnaire_create.json +8 -0
  116. data/spec/support/json/questionnaire_datasources.json +26 -0
  117. data/spec/support/json/questionnaire_execution_create.json +9 -0
  118. data/spec/support/json/questionnaire_execution_status_set.json +8 -0
  119. data/spec/support/json/questionnaire_execution_update.json +8 -0
  120. data/spec/support/json/questionnaire_executions.json +24 -0
  121. data/spec/support/json/questionnaire_get.json +14 -0
  122. data/spec/support/json/questionnaire_remove.json +8 -0
  123. data/spec/support/json/questionnaire_update.json +8 -0
  124. data/spec/support/json/questionnaires_get.json +22 -0
  125. data/spec/support/json/storage_info.json +10 -0
  126. data/spec/support/shared_examples/api/entity.rb +37 -0
  127. data/spec/support/shared_examples/api/helpers/status_helper.rb +12 -0
  128. data/spec/support/shared_examples/api/sugar/lookup.rb +57 -0
  129. metadata +356 -0
@@ -0,0 +1,44 @@
1
+ module GroupDocs
2
+ class DataSource::Field < GroupDocs::Api::Entity
3
+
4
+ TYPES = {
5
+ text: 0,
6
+ binary: 1,
7
+ }
8
+
9
+ # @attr [String] field
10
+ attr_accessor :field
11
+ # @attr [Integer] type
12
+ attr_accessor :type
13
+ # @attr [Array<String>] values
14
+ attr_accessor :values
15
+
16
+ # Compatibility with response JSON
17
+ alias_method :name=, :field=
18
+
19
+ #
20
+ # Updates type with machine-readable format.
21
+ #
22
+ # @param [Symbol] type
23
+ # @raise [ArgumentError] if type is unknown
24
+ #
25
+ def type=(type)
26
+ if type.is_a?(Symbol)
27
+ TYPES.keys.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
28
+ type = TYPES[type]
29
+ end
30
+
31
+ @type = type
32
+ end
33
+
34
+ #
35
+ # Returns field type in human-readable format.
36
+ #
37
+ # @return [Symbol]
38
+ #
39
+ def type
40
+ TYPES.invert[@type]
41
+ end
42
+
43
+ end # DataSource::Field
44
+ end # GroupDocs
@@ -0,0 +1,513 @@
1
+ module GroupDocs
2
+ class Document < GroupDocs::Api::Entity
3
+
4
+ require 'groupdocs/document/annotation'
5
+ require 'groupdocs/document/change'
6
+ require 'groupdocs/document/field'
7
+ require 'groupdocs/document/metadata'
8
+ require 'groupdocs/document/rectangle'
9
+ require 'groupdocs/document/view'
10
+
11
+ extend GroupDocs::Api::Sugar::Lookup
12
+ include GroupDocs::Api::Helpers::Access
13
+ include GroupDocs::Api::Helpers::Status
14
+
15
+ #
16
+ # Returns an array of all documents on server.
17
+ #
18
+ # @param [String] path Starting path to look for documents
19
+ # @param [Hash] access Access credentials
20
+ # @option access [String] :client_id
21
+ # @option access [String] :private_key
22
+ # @return [Array<GroupDocs::Storage::Document>]
23
+ #
24
+ def self.all!(path = '/', access = {})
25
+ GroupDocs::Storage::File.all!(path, access).map(&:to_document)
26
+ end
27
+
28
+ #
29
+ # Returns an array of views for all documents.
30
+ #
31
+ # @param [Hash] options
32
+ # @option options [Integer] :page_index Page to start with
33
+ # @option options [Integer] :page_size Total number of entries
34
+ # @param [Hash] access Access credentials
35
+ # @option access [String] :client_id
36
+ # @option access [String] :private_key
37
+ # @return [Array<GroupDocs::Document::View>]
38
+ #
39
+ def self.views!(options = { page_index: 0 }, access = {})
40
+ api = GroupDocs::Api::Request.new do |request|
41
+ request[:access] = access
42
+ request[:method] = :GET
43
+ request[:path] = "/doc/{{client_id}}/views"
44
+ end
45
+ api.add_params(options)
46
+ json = api.execute!
47
+
48
+ json[:views].map do |view|
49
+ GroupDocs::Document::View.new(view)
50
+ end
51
+ end
52
+
53
+ # @attr [GroupDocs::Storage::File] file
54
+ attr_accessor :file
55
+ # @attr [Time] process_date
56
+ attr_accessor :process_date
57
+ # @attr [Array] outputs
58
+ attr_accessor :outputs
59
+
60
+ #
61
+ # Converts timestamp which is return by API server to Time object.
62
+ #
63
+ # @return [Time]
64
+ #
65
+ def process_date
66
+ Time.at(@process_date)
67
+ end
68
+
69
+ # Compatibility with response JSON
70
+ alias_method :proc_date=, :process_date=
71
+
72
+ #
73
+ # Creates new GroupDocs::Document.
74
+ #
75
+ # You should avoid creating documents directly. Instead, use #to_document
76
+ # instance method of GroupDocs::Storage::File.
77
+ #
78
+ # @raise [ArgumentError] If file is not passed or is not an instance of GroupDocs::Storage::File
79
+ #
80
+ def initialize(options = {}, &blk)
81
+ super(options, &blk)
82
+ file.is_a?(GroupDocs::Storage::File) or raise ArgumentError,
83
+ "You have to pass GroupDocs::Storage::File object: #{file.inspect}."
84
+ end
85
+
86
+ #
87
+ # Returns access mode of document.
88
+ #
89
+ # @param [Hash] access Access credentials
90
+ # @option access [String] :client_id
91
+ # @option access [String] :private_key
92
+ # @return [Symbol] One of :private, :restricted or :public access modes
93
+ #
94
+ def access_mode!(access = {})
95
+ json = GroupDocs::Api::Request.new do |request|
96
+ request[:access] = access
97
+ request[:method] = :GET
98
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/accessinfo"
99
+ end.execute!
100
+
101
+ parse_access_mode(json[:access])
102
+ end
103
+
104
+ #
105
+ # Sets access mode of document.
106
+ #
107
+ # @param [Symbol] mode One of :private, :restricted or :public access modes
108
+ # @param [Hash] access Access credentials
109
+ # @option access [String] :client_id
110
+ # @option access [String] :private_key
111
+ # @return [Symbol] Set access mode
112
+ #
113
+ def access_mode_set!(mode, access = {})
114
+ api = GroupDocs::Api::Request.new do |request|
115
+ request[:access] = access
116
+ request[:method] = :PUT
117
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/accessinfo"
118
+ end
119
+ api.add_params(mode: parse_access_mode(mode))
120
+ json = api.execute!
121
+
122
+ parse_access_mode(json[:access])
123
+ end
124
+ # note that aliased version cannot accept access credentials hash
125
+ alias_method :access_mode=, :access_mode_set!
126
+
127
+ #
128
+ # Returns array of file formats document can be converted to.
129
+ #
130
+ # @param [Hash] access Access credentials
131
+ # @option access [String] :client_id
132
+ # @option access [String] :private_key
133
+ # @return [Array<Symbol>]
134
+ #
135
+ def formats!(access = {})
136
+ json = GroupDocs::Api::Request.new do |request|
137
+ request[:access] = access
138
+ request[:method] = :GET
139
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/formats"
140
+ end.execute!
141
+
142
+ json[:types].split(';').map do |format|
143
+ format.downcase.to_sym
144
+ end
145
+ end
146
+
147
+ #
148
+ # Returns document metadata.
149
+ #
150
+ # @param [Hash] access Access credentials
151
+ # @option access [String] :client_id
152
+ # @option access [String] :private_key
153
+ # @return [GroupDocs::Document::MetaData]
154
+ #
155
+ def metadata!(access = {})
156
+ json = GroupDocs::Api::Request.new do |request|
157
+ request[:access] = access
158
+ request[:method] = :GET
159
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/metadata"
160
+ end.execute!
161
+
162
+ GroupDocs::Document::MetaData.new do |metadata|
163
+ metadata.id = json[:id]
164
+ metadata.guid = json[:guid]
165
+ metadata.page_count = json[:page_count]
166
+ metadata.views_count = json[:views_count]
167
+ if json[:last_view]
168
+ metadata.last_view = json[:last_view]
169
+ metadata.last_view.document = self
170
+ end
171
+ end
172
+ end
173
+
174
+ #
175
+ # Returns an array of document fields.
176
+ #
177
+ # @param [Hash] options
178
+ # @option options [Boolean] :include_geometry Set to true if fields location and size should be returned
179
+ # @param [Hash] access Access credentials
180
+ # @option access [String] :client_id
181
+ # @option access [String] :private_key
182
+ # @return [Array<GroupDocs::Document::Field>]
183
+ #
184
+ def fields!(options = {}, access = {})
185
+ api = GroupDocs::Api::Request.new do |request|
186
+ request[:access] = access
187
+ request[:method] = :GET
188
+ request[:path] = "/doc/{{client_id}}/files/#{file.guid}/fields"
189
+ end
190
+ api.add_params(options)
191
+ json = api.execute!
192
+
193
+ json[:fields].map do |field|
194
+ GroupDocs::Document::Field.new(field)
195
+ end
196
+ end
197
+
198
+ #
199
+ # Returns an array of users a document is shared with.
200
+ #
201
+ # @param [Hash] access Access credentials
202
+ # @option access [String] :client_id
203
+ # @option access [String] :private_key
204
+ # @return [Array<GroupDocs::User>]
205
+ #
206
+ def sharers!(access = {})
207
+ json = GroupDocs::Api::Request.new do |request|
208
+ request[:access] = access
209
+ request[:method] = :GET
210
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/accessinfo"
211
+ end.execute!
212
+
213
+ json[:sharers].map do |user|
214
+ GroupDocs::User.new(user)
215
+ end
216
+ end
217
+
218
+ #
219
+ # Sets document sharers to given emails.
220
+ #
221
+ # If empty array or nil passed, clears sharers.
222
+ #
223
+ # @param [Array] emails List of email addresses to share with
224
+ # @param [Hash] access Access credentials
225
+ # @option access [String] :client_id
226
+ # @option access [String] :private_key
227
+ # @return [Array<GroupDocs::User>]
228
+ #
229
+ def sharers_set!(emails, access = {})
230
+ if emails.nil? || emails.empty?
231
+ sharers_clear!(access)
232
+ else
233
+ json = GroupDocs::Api::Request.new do |request|
234
+ request[:access] = access
235
+ request[:method] = :PUT
236
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/sharers"
237
+ request[:request_body] = emails
238
+ end.execute!
239
+
240
+ json[:shared_users].map do |user|
241
+ GroupDocs::User.new(user)
242
+ end
243
+ end
244
+ end
245
+
246
+ #
247
+ # Clears sharers list.
248
+ #
249
+ # @param [Hash] access Access credentials
250
+ # @option access [String] :client_id
251
+ # @option access [String] :private_key
252
+ # @return nil
253
+ #
254
+ def sharers_clear!(access = {})
255
+ GroupDocs::Api::Request.new do |request|
256
+ request[:access] = access
257
+ request[:method] = :DELETE
258
+ request[:path] = "/doc/{{client_id}}/files/#{file.id}/sharers"
259
+ end.execute![:shared_users]
260
+ end
261
+
262
+ #
263
+ # Converts document to given format.
264
+ #
265
+ # @param [Symbol] format
266
+ # @param [Hash] options
267
+ # @option options [Boolean] :email_results Set to true if converted document should be emailed
268
+ # @param [Hash] access Access credentials
269
+ # @option access [String] :client_id
270
+ # @option access [String] :private_key
271
+ # @return [GroupDocs::Job] Created job
272
+ #
273
+ def convert!(format, options = {}, access = {})
274
+ options.merge!(new_type: format)
275
+
276
+ api = GroupDocs::Api::Request.new do |request|
277
+ request[:access] = access
278
+ request[:method] = :POST
279
+ request[:path] = "/{{client_id}}/files/#{file.guid}"
280
+ end
281
+ api.add_params(options)
282
+ json = api.execute!
283
+
284
+ GroupDocs::Job.new(id: json[:job_id])
285
+ end
286
+
287
+ #
288
+ # Creates new job to merge datasource into document.
289
+ #
290
+ # @param [GroupDocs::DataSource] datasource
291
+ # @param [Hash] options
292
+ # @option options [Boolean] :new_type New file format type
293
+ # @option options [Boolean] :email_results Set to true if converted document should be emailed
294
+ # @param [Hash] access Access credentials
295
+ # @option access [String] :client_id
296
+ # @option access [String] :private_key
297
+ # @return [GroupDocs::Job]
298
+ #
299
+ # @raise [ArgumentError] if datasource is not GroupDocs::DataSource object
300
+ # @raise [ArgumentError] if options does not contain :new_type and/or :email_results
301
+ #
302
+ def datasource!(datasource, options, access = {})
303
+ datasource.is_a?(GroupDocs::DataSource) or raise ArgumentError,
304
+ "Datasource should be GroupDocs::DataSource object, received: #{datasource.inspect}"
305
+ (options[:new_type].nil? || options[:email_results].nil?) and raise ArgumentError,
306
+ "Both :new_type and :email_results should be passed, received: #{options.inspect}"
307
+
308
+ api = GroupDocs::Api::Request.new do |request|
309
+ request[:access] = access
310
+ request[:method] = :POST
311
+ request[:path] = "/merge/{{client_id}}/files/#{file.guid}/datasources/#{datasource.id}"
312
+ end
313
+ api.add_params(options)
314
+ json = api.execute!
315
+
316
+ GroupDocs::Job.new(id: json[:job_id])
317
+ end
318
+
319
+ #
320
+ # Returns an array of questionnaires.
321
+ #
322
+ # @param [Hash] access Access credentials
323
+ # @option access [String] :client_id
324
+ # @option access [String] :private_key
325
+ # @return [Array<GroupDocs::Questionnaire>]
326
+ #
327
+ def questionnaires!(access = {})
328
+ json = GroupDocs::Api::Request.new do |request|
329
+ request[:access] = access
330
+ request[:method] = :GET
331
+ request[:path] = "/merge/{{client_id}}/files/#{file.guid}/questionnaires"
332
+ end.execute!
333
+
334
+ json[:questionnaires].map do |questionnaire|
335
+ GroupDocs::Questionnaire.new(questionnaire)
336
+ end
337
+ end
338
+
339
+ #
340
+ # Adds questionnaire to document.
341
+ #
342
+ # @param [GroupDocs::Questionnaire] questionnaire
343
+ # @param [Hash] access Access credentials
344
+ # @option access [String] :client_id
345
+ # @option access [String] :private_key
346
+ #
347
+ # @raise [ArgumentError] if questionnaire is not GroupDocs::Questionnaire object
348
+ #
349
+ def add_questionnaire!(questionnaire, access = {})
350
+ questionnaire.is_a?(GroupDocs::Questionnaire) or raise ArgumentError,
351
+ "Questionnaire should be GroupDocs::Questionnaire object, received: #{questionnaire.inspect}"
352
+
353
+ GroupDocs::Api::Request.new do |request|
354
+ request[:access] = access
355
+ request[:method] = :PUT
356
+ request[:path] = "/merge/{{client_id}}/files/#{file.guid}/questionnaires/#{questionnaire.id}"
357
+ end.execute!
358
+ end
359
+
360
+ #
361
+ # Creates questionnaire and adds it to document.
362
+ #
363
+ # @param [GroupDocs::Questionnaire] questionnaire
364
+ # @param [Hash] access Access credentials
365
+ # @option access [String] :client_id
366
+ # @option access [String] :private_key
367
+ # @return [GroupDocs::Questionnaire]
368
+ #
369
+ # @raise [ArgumentError] if questionnaire is not GroupDocs::Questionnaire object
370
+ #
371
+ def create_questionnaire!(questionnaire, access = {})
372
+ questionnaire.is_a?(GroupDocs::Questionnaire) or raise ArgumentError,
373
+ "Questionnaire should be GroupDocs::Questionnaire object, received: #{questionnaire.inspect}"
374
+
375
+ json = GroupDocs::Api::Request.new do |request|
376
+ request[:access] = access
377
+ request[:method] = :POST
378
+ request[:path] = "/merge/{{client_id}}/files/#{file.guid}/questionnaires"
379
+ request[:request_body] = questionnaire.to_hash
380
+ end.execute!
381
+
382
+ questionnaire.id = json[:questionnaire_id]
383
+ questionnaire
384
+ end
385
+
386
+ #
387
+ # Detaches questionnaire from document.
388
+ #
389
+ # @param [GroupDocs::Questionnaire] questionnaire
390
+ # @param [Hash] access Access credentials
391
+ # @option access [String] :client_id
392
+ # @option access [String] :private_key
393
+ #
394
+ # @raise [ArgumentError] if questionnaire is not GroupDocs::Questionnaire object
395
+ #
396
+ def remove_questionnaire!(questionnaire, access = {})
397
+ questionnaire.is_a?(GroupDocs::Questionnaire) or raise ArgumentError,
398
+ "Questionnaire should be GroupDocs::Questionnaire object, received: #{questionnaire.inspect}"
399
+
400
+ GroupDocs::Api::Request.new do |request|
401
+ request[:access] = access
402
+ request[:method] = :DELETE
403
+ request[:path] = "/merge/{{client_id}}/files/#{file.guid}/questionnaires/#{questionnaire.id}"
404
+ end.execute!
405
+ end
406
+
407
+ #
408
+ # Returns an array of annotations.
409
+ #
410
+ # @param [Hash] access Access credentials
411
+ # @option access [String] :client_id
412
+ # @option access [String] :private_key
413
+ # @return [Array<GroupDocs::Document::Annotation>]
414
+ #
415
+ def annotations!(access = {})
416
+ json = GroupDocs::Api::Request.new do |request|
417
+ request[:access] = access
418
+ request[:method] = :GET
419
+ request[:path] = "/ant/{{client_id}}/files/#{file.guid}/annotations"
420
+ end.execute!
421
+
422
+ json[:annotations].map do |annotation|
423
+ annotation.merge!(document: self)
424
+ GroupDocs::Document::Annotation.new(annotation)
425
+ end
426
+ end
427
+
428
+ #
429
+ # Returns document details.
430
+ #
431
+ # @param [Hash] access Access credentials
432
+ # @option access [String] :client_id
433
+ # @option access [String] :private_key
434
+ # @return [Hash]
435
+ #
436
+ def details!(access = {})
437
+ api = GroupDocs::Api::Request.new do |request|
438
+ request[:access] = access
439
+ request[:method] = :GET
440
+ request[:path] = "/comparison/{{client_id}}/comparison/document"
441
+ end
442
+ api.add_params(guid: file.guid)
443
+ api.execute!
444
+ end
445
+
446
+ #
447
+ # Schedules a job for comparing document with given.
448
+ #
449
+ # @param [GroupDocs::Document] document
450
+ # @param [Hash] access Access credentials
451
+ # @option access [String] :client_id
452
+ # @option access [String] :private_key
453
+ # @return [GroupDocs::Job]
454
+ #
455
+ # @raise [ArgumentError] if document is not GroupDocs::Document object
456
+ #
457
+ def compare!(document, access = {})
458
+ document.is_a?(GroupDocs::Document) or raise ArgumentError,
459
+ "Document should be GroupDocs::Document object, received: #{document.inspect}"
460
+
461
+ api = GroupDocs::Api::Request.new do |request|
462
+ request[:access] = access
463
+ request[:method] = :GET
464
+ request[:path] = "/comparison/{{client_id}}/comparison/compare"
465
+ end
466
+ api.add_params(source: file.guid, target: document.file.guid)
467
+ json = api.execute!
468
+
469
+ GroupDocs::Job.new(id: json[:job_id])
470
+ end
471
+
472
+ #
473
+ # Returns an array of changes in document.
474
+ #
475
+ # @example
476
+ # document_one = GroupDocs::Document.find!(:name, 'CV.doc')
477
+ # document_two = GroupDocs::Document.find!(:name, 'Resume.doc')
478
+ # job = document_one.compare!(document_two)
479
+ # result = job.documents!.first
480
+ # result.changes!
481
+ #
482
+ # @param [Hash] access Access credentials
483
+ # @option access [String] :client_id
484
+ # @option access [String] :private_key
485
+ #
486
+ def changes!(access = {})
487
+ api = GroupDocs::Api::Request.new do |request|
488
+ request[:access] = access
489
+ request[:method] = :GET
490
+ request[:path] = "/comparison/{{client_id}}/comparison/changes"
491
+ end
492
+ api.add_params(resultFileId: file.guid)
493
+ json = api.execute!
494
+
495
+ json[:changes].map do |change|
496
+ GroupDocs::Document::Change.new(change)
497
+ end
498
+ end
499
+
500
+ #
501
+ # Pass all unknown methods to file.
502
+ #
503
+
504
+ def method_missing(method, *args, &blk)
505
+ file.respond_to?(method) ? file.send(method, *args, &blk) : super
506
+ end
507
+
508
+ def respond_to?(method)
509
+ super or file.respond_to?(method)
510
+ end
511
+
512
+ end # Document
513
+ end # GroupDocs