groupdocs 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/CHANGELOG.md +41 -0
  2. data/examples/README.md +2 -3
  3. data/examples/api-samples/Gemfile +5 -0
  4. data/examples/api-samples/Gemfile.lock +27 -0
  5. data/examples/api-samples/README.md +12 -0
  6. data/examples/api-samples/app.rb +17 -0
  7. data/examples/api-samples/public/css/style.css +166 -0
  8. data/examples/api-samples/samples/sample1.rb +17 -0
  9. data/examples/api-samples/samples/sample10.rb +36 -0
  10. data/examples/api-samples/samples/sample2.rb +19 -0
  11. data/examples/api-samples/samples/sample3.rb +23 -0
  12. data/examples/api-samples/samples/sample4.rb +31 -0
  13. data/examples/api-samples/samples/sample5.rb +44 -0
  14. data/examples/api-samples/samples/sample6.rb +3 -0
  15. data/examples/api-samples/samples/sample7.rb +33 -0
  16. data/examples/api-samples/samples/sample8.rb +40 -0
  17. data/examples/api-samples/samples/sample9.rb +22 -0
  18. data/examples/api-samples/views/index.haml +23 -0
  19. data/examples/api-samples/views/layout.haml +7 -0
  20. data/examples/api-samples/views/sample1.haml +71 -0
  21. data/examples/api-samples/views/sample10.haml +69 -0
  22. data/examples/api-samples/views/sample2.haml +59 -0
  23. data/examples/api-samples/views/sample3.haml +62 -0
  24. data/examples/api-samples/views/sample4.haml +58 -0
  25. data/examples/api-samples/views/sample5.haml +62 -0
  26. data/examples/api-samples/views/sample6.haml +145 -0
  27. data/examples/api-samples/views/sample7.haml +59 -0
  28. data/examples/api-samples/views/sample8.haml +75 -0
  29. data/examples/api-samples/views/sample9.haml +61 -0
  30. data/examples/{annotations → viewer}/Gemfile +0 -0
  31. data/examples/viewer/app.rb +52 -0
  32. data/groupdocs.gemspec +5 -4
  33. data/lib/groupdocs/api.rb +1 -0
  34. data/lib/groupdocs/api/entity.rb +2 -0
  35. data/lib/groupdocs/api/helpers.rb +2 -0
  36. data/lib/groupdocs/api/helpers/accessor_helper.rb +30 -0
  37. data/lib/groupdocs/api/helpers/mime_helper.rb +21 -0
  38. data/lib/groupdocs/api/helpers/rest_helper.rb +3 -2
  39. data/lib/groupdocs/api/request.rb +1 -3
  40. data/lib/groupdocs/datasource.rb +1 -2
  41. data/lib/groupdocs/document.rb +133 -3
  42. data/lib/groupdocs/document/annotation.rb +14 -13
  43. data/lib/groupdocs/document/annotation/reply.rb +4 -8
  44. data/lib/groupdocs/document/annotation/reviewer.rb +2 -4
  45. data/lib/groupdocs/document/field.rb +10 -8
  46. data/lib/groupdocs/document/rectangle.rb +10 -18
  47. data/lib/groupdocs/job.rb +1 -1
  48. data/lib/groupdocs/questionnaire.rb +138 -44
  49. data/lib/groupdocs/questionnaire/collector.rb +262 -0
  50. data/lib/groupdocs/questionnaire/execution.rb +93 -10
  51. data/lib/groupdocs/questionnaire/question.rb +1 -2
  52. data/lib/groupdocs/signature.rb +16 -24
  53. data/lib/groupdocs/signature/contact.rb +2 -4
  54. data/lib/groupdocs/signature/envelope.rb +3 -6
  55. data/lib/groupdocs/signature/envelope/log.rb +2 -4
  56. data/lib/groupdocs/signature/field.rb +21 -42
  57. data/lib/groupdocs/signature/field/location.rb +18 -36
  58. data/lib/groupdocs/signature/form.rb +9 -18
  59. data/lib/groupdocs/signature/list.rb +1 -2
  60. data/lib/groupdocs/signature/recipient.rb +3 -6
  61. data/lib/groupdocs/signature/role.rb +4 -8
  62. data/lib/groupdocs/signature/shared/entity_fields.rb +12 -20
  63. data/lib/groupdocs/signature/template.rb +1 -2
  64. data/lib/groupdocs/storage/file.rb +3 -1
  65. data/lib/groupdocs/storage/folder.rb +7 -1
  66. data/lib/groupdocs/subscription.rb +6 -12
  67. data/lib/groupdocs/subscription/limit.rb +4 -8
  68. data/lib/groupdocs/user.rb +3 -6
  69. data/lib/groupdocs/version.rb +1 -1
  70. data/spec/groupdocs/api/helpers/accessor_helper_spec.rb +16 -0
  71. data/spec/groupdocs/api/helpers/mime_helper_spec.rb +16 -0
  72. data/spec/groupdocs/api/helpers/rest_helper_spec.rb +4 -0
  73. data/spec/groupdocs/api/request_spec.rb +3 -5
  74. data/spec/groupdocs/datasource/field_spec.rb +3 -6
  75. data/spec/groupdocs/datasource_spec.rb +8 -15
  76. data/spec/groupdocs/document/annotation/reply_spec.rb +13 -24
  77. data/spec/groupdocs/document/annotation/reviewer_spec.rb +5 -9
  78. data/spec/groupdocs/document/annotation_spec.rb +35 -40
  79. data/spec/groupdocs/document/change_spec.rb +6 -11
  80. data/spec/groupdocs/document/field_spec.rb +13 -13
  81. data/spec/groupdocs/document/metadata_spec.rb +5 -10
  82. data/spec/groupdocs/document/rectangle_spec.rb +6 -18
  83. data/spec/groupdocs/document/view_spec.rb +3 -6
  84. data/spec/groupdocs/document_spec.rb +123 -10
  85. data/spec/groupdocs/job_spec.rb +9 -18
  86. data/spec/groupdocs/questionnaire/collector_spec.rb +201 -0
  87. data/spec/groupdocs/questionnaire/execution_spec.rb +91 -23
  88. data/spec/groupdocs/questionnaire/page_spec.rb +3 -6
  89. data/spec/groupdocs/questionnaire/question/answer_spec.rb +2 -4
  90. data/spec/groupdocs/questionnaire/question_spec.rb +7 -14
  91. data/spec/groupdocs/questionnaire_spec.rb +117 -41
  92. data/spec/groupdocs/signature/contact_spec.rb +9 -17
  93. data/spec/groupdocs/signature/envelope/log_spec.rb +8 -16
  94. data/spec/groupdocs/signature/envelope_spec.rb +9 -17
  95. data/spec/groupdocs/signature/field/location_spec.rb +32 -65
  96. data/spec/groupdocs/signature/field_spec.rb +48 -95
  97. data/spec/groupdocs/signature/form_spec.rb +22 -43
  98. data/spec/groupdocs/signature/list_spec.rb +6 -11
  99. data/spec/groupdocs/signature/recipient_spec.rb +11 -22
  100. data/spec/groupdocs/signature/role_spec.rb +11 -21
  101. data/spec/groupdocs/signature/template_spec.rb +2 -4
  102. data/spec/groupdocs/signature_spec.rb +28 -54
  103. data/spec/groupdocs/storage/file_spec.rb +14 -26
  104. data/spec/groupdocs/storage/folder_spec.rb +16 -22
  105. data/spec/groupdocs/storage/package_spec.rb +2 -4
  106. data/spec/groupdocs/subscription/limit_spec.rb +8 -16
  107. data/spec/groupdocs/subscription_spec.rb +11 -22
  108. data/spec/groupdocs/user_spec.rb +21 -41
  109. data/spec/groupdocs_spec.rb +4 -8
  110. data/spec/spec_helper.rb +12 -0
  111. data/spec/support/files/signature.png +0 -0
  112. data/spec/support/json/annotation_list.json +6 -6
  113. data/spec/support/json/comparison_changes.json +8 -8
  114. data/spec/support/json/document_fields.json +8 -8
  115. data/spec/support/json/document_page_images_get.json +20 -0
  116. data/spec/support/json/questionnaire_collector.json +17 -0
  117. data/spec/support/json/questionnaire_collectors.json +38 -0
  118. data/spec/support/json/questionnaire_collectors_add.json +10 -0
  119. data/spec/support/json/questionnaire_create.json +3 -1
  120. data/spec/support/json/{questionnaire_execution_create.json → questionnaire_execution_add.json} +1 -1
  121. data/spec/support/json/questionnaire_get.json +3 -0
  122. data/spec/support/json/questionnaires_get.json +36 -18
  123. data/spec/support/json/sign_documents.json +16 -0
  124. data/spec/support/json/templates_get.json +21 -0
  125. data/spec/support/shared_examples/api/entity.rb +2 -0
  126. data/spec/support/shared_examples/api/helpers/access_mode_helper.rb +1 -2
  127. data/spec/support/shared_examples/api/helpers/status_helper.rb +1 -2
  128. data/spec/support/shared_examples/signature/shared/entity_fields.rb +22 -43
  129. metadata +82 -16
  130. data/examples/annotations/app.rb +0 -67
data/lib/groupdocs/job.rb CHANGED
@@ -244,7 +244,7 @@ module GroupDocs
244
244
  Api::Request.new do |request|
245
245
  request[:access] = access
246
246
  request[:method] = :PUT
247
- request[:path] = "/async/{{client_id}}/jobs/#{id}/files/#{document.file.guid}/datasources/#{datasource.id}"
247
+ request[:path] = "/async/{{client_id}}/jobs/#{id}/files/#{document.file.id}/datasources/#{datasource.id}"
248
248
  end.execute!
249
249
  end
250
250
 
@@ -1,27 +1,41 @@
1
1
  module GroupDocs
2
2
  class Questionnaire < Api::Entity
3
3
 
4
+ require 'groupdocs/questionnaire/collector'
4
5
  require 'groupdocs/questionnaire/execution'
5
6
  require 'groupdocs/questionnaire/page'
6
7
  require 'groupdocs/questionnaire/question'
7
8
 
9
+ include Api::Helpers::Status
10
+
8
11
  #
9
12
  # Returns an array of all questionnaires.
10
13
  #
14
+ # @param [Hash] options Hash of options
15
+ # @option options [Symbol] :status Filter questionnaires by status
16
+ # @option options [Integer] :page_number Page to start with
17
+ # @option options [Integer] :page_size How many items to list
11
18
  # @param [Hash] access Access credentials
12
19
  # @option access [String] :client_id
13
20
  # @option access [String] :private_key
14
21
  # @return [Array<GroupDocs::Questionnaire>]
15
22
  #
16
- def self.all!(access = {})
17
- json = Api::Request.new do |request|
23
+ def self.all!(options = {}, access = {})
24
+ if options[:status]
25
+ # TODO find better way to parse status
26
+ options[:status] = new.send(:parse_status, options[:status])
27
+ end
28
+
29
+ api = Api::Request.new do |request|
18
30
  request[:access] = access
19
31
  request[:method] = :GET
20
32
  request[:path] = '/merge/{{client_id}}/questionnaires'
21
- end.execute!
33
+ end
34
+ api.add_params(options)
35
+ json = api.execute!
22
36
 
23
37
  json[:questionnaires].map do |questionnaire|
24
- Questionnaire.new(questionnaire)
38
+ new(questionnaire)
25
39
  end
26
40
  end
27
41
 
@@ -41,43 +55,38 @@ module GroupDocs
41
55
  request[:path] = "/merge/{{client_id}}/questionnaires/#{id}"
42
56
  end.execute!
43
57
 
44
- Questionnaire.new(json[:questionnaire])
58
+ new(json[:questionnaire])
45
59
  rescue RestClient::ResourceNotFound
46
60
  nil
47
61
  end
48
62
 
49
- #
50
- # Returns an array of all executions.
51
- #
52
- # @param [Hash] access Access credentials
53
- # @option access [String] :client_id
54
- # @option access [String] :private_key
55
- # @return [Array<GroupDocs::Questionnaire::Execution>]
56
- #
57
- def self.executions!(access = {})
58
- json = Api::Request.new do |request|
59
- request[:access] = access
60
- request[:method] = :GET
61
- request[:path] = '/merge/{{client_id}}/questionnaires/executions'
62
- end.execute!
63
-
64
- json[:executions].map do |execution|
65
- Questionnaire::Execution.new(execution)
66
- end
67
- end
68
-
69
63
  # @attr [Integer] id
70
64
  attr_accessor :id
65
+ # @attr [String] guid
66
+ attr_accessor :guid
71
67
  # @attr [String] name
72
68
  attr_accessor :name
69
+ # @attr [Symbol] status
70
+ attr_accessor :status
73
71
  # @attr [String] descr
74
72
  attr_accessor :descr
75
73
  # @attr [Array<GroupDocs::Questionnaire::Page>] pages
76
74
  attr_accessor :pages
75
+ # @attr [Integer] resolved_executions
76
+ attr_accessor :resolved_executions
77
+ # @attr [Integer] assigned_questions
78
+ attr_accessor :assigned_questions
79
+ # @attr [Integer] total_questions
80
+ attr_accessor :total_questions
81
+ # @attr [Integer] modified
82
+ attr_accessor :modified
83
+ # @attr [Integer] expires
84
+ attr_accessor :expires
85
+ # @attr [Array<String>] document_ids
86
+ attr_accessor :document_ids
77
87
 
78
88
  # Human-readable accessors
79
- alias_method :description, :descr
80
- alias_method :description=, :descr=
89
+ alias_accessor :description, :descr
81
90
 
82
91
  #
83
92
  # Converts each page to GroupDocs::Questionnaire::Page object.
@@ -96,6 +105,15 @@ module GroupDocs
96
105
  end
97
106
  end
98
107
 
108
+ #
109
+ # Converts status to human-readable format.
110
+ #
111
+ # @return [Symbol]
112
+ #
113
+ def status
114
+ parse_status(@status)
115
+ end
116
+
99
117
  #
100
118
  # Adds page to questionnaire.
101
119
  #
@@ -126,6 +144,8 @@ module GroupDocs
126
144
  end.execute!
127
145
 
128
146
  self.id = json[:questionnaire_id]
147
+ self.guid = json[:questionnaire_guid]
148
+ self.name = json[:adjusted_name]
129
149
  end
130
150
 
131
151
  #
@@ -183,36 +203,110 @@ module GroupDocs
183
203
  end
184
204
 
185
205
  #
186
- # Creates new questionnaire execution.
206
+ # Returns an array of questionnaire executions.
207
+ #
208
+ # @param [Hash] access Access credentials
209
+ # @option access [String] :client_id
210
+ # @option access [String] :private_key
211
+ # @return [Array<GroupDocs::Questionnaire::Execution>]
212
+ #
213
+ def executions!(access = {})
214
+ json = Api::Request.new do |request|
215
+ request[:access] = access
216
+ request[:method] = :GET
217
+ request[:path] = "/merge/{{client_id}}/questionnaires/#{guid}/executions"
218
+ end.execute!
219
+
220
+ json[:executions].map do |execution|
221
+ Execution.new(execution)
222
+ end
223
+ end
224
+
225
+ #
226
+ # Returns an array of questionnaire collectors.
227
+ #
228
+ # @param [Hash] access Access credentials
229
+ # @option access [String] :client_id
230
+ # @option access [String] :private_key
231
+ # @return [Array<GroupDocs::Questionnaire::Collector>]
232
+ #
233
+ def collectors!(access = {})
234
+ json = Api::Request.new do |request|
235
+ request[:access] = access
236
+ request[:method] = :GET
237
+ request[:path] = "/merge/{{client_id}}/questionnaires/#{guid}/collectors"
238
+ end.execute!
239
+
240
+ json[:collectors].map do |collector|
241
+ collector.merge!(questionnaire: self)
242
+ Collector.new(collector)
243
+ end
244
+ end
245
+
246
+ #
247
+ # Returns questionnaire metadata.
248
+ #
249
+ # @param [Hash] access Access credentials
250
+ # @option access [String] :client_id
251
+ # @option access [String] :private_key
252
+ # @return [GroupDocs::Questionnaire]
253
+ #
254
+ def metadata!(access = {})
255
+ json = Api::Request.new do |request|
256
+ request[:access] = access
257
+ request[:method] = :GET
258
+ request[:path] = "/merge/{{client_id}}/questionnaires/#{guid}/metadata"
259
+ end.execute!
260
+
261
+ Questionnaire.new(json[:questionnaire])
262
+ end
263
+
264
+ #
265
+ # Updates questionnaire metadata.
187
266
  #
188
267
  # @example
189
- # execution = GroupDocs::Questionnaire::Execution.new
190
268
  # questionnaire = GroupDocs::Questionnaire.get!(1)
191
- # execution = questionnaire.create_execution!(execution, 'user@email.com')
192
- # #=> #<GroupDocs::Questionnaire::Execution @id=1, @questionnaire_id=1>
269
+ # metadata = questionnaire.metadata!
270
+ # metadata.name = 'New questionnaire name'
271
+ # questionnaire.update_metadata! metadata
193
272
  #
194
- # @param [GroupDocs::Questionnaire::Execution] execution
195
- # @param [String] email
196
273
  # @param [Hash] access Access credentials
197
274
  # @option access [String] :client_id
198
275
  # @option access [String] :private_key
199
- # @return [GroupDocs::Questionnaire::Execution] updated execution
276
+ # @raise [ArgumentError] if metadata is not GroupDocs::Questionnaire
200
277
  #
201
- def create_execution!(execution, email, access = {})
202
- execution.is_a?(GroupDocs::Questionnaire::Execution) or raise ArgumentError,
203
- "Execution should be GroupDocs::Questionnaire::Execution object, received: #{execution.inspect}"
278
+ def update_metadata!(metadata, access = {})
279
+ metadata.is_a?(GroupDocs::Questionnaire) or raise ArgumentError,
280
+ "Metadata should be GroupDocs::Questionnaire object, received: #{metadata.inspect}"
204
281
 
205
- json = Api::Request.new do |request|
282
+ Api::Request.new do |request|
206
283
  request[:access] = access
207
- request[:method] = :POST
208
- request[:path] = "/merge/{{client_id}}/questionnaires/#{id}/executions"
209
- request[:request_body] = execution.to_hash.merge(executive: { primary_email: email })
284
+ request[:method] = :PUT
285
+ request[:path] = "/merge/{{client_id}}/questionnaires/#{guid}/metadata"
286
+ request[:request_body] = metadata.to_hash
210
287
  end.execute!
288
+ end
211
289
 
212
- execution.id = json[:execution_id]
213
- execution.questionnaire_id = json[:questionnaire_id]
290
+ #
291
+ # Returns an array of document fields for questionnaire.
292
+ #
293
+ # @param [Hash] access Access credentials
294
+ # @option access [String] :client_id
295
+ # @option access [String] :private_key
296
+ # @return [Array<GroupDocs::Document::Field>]
297
+ #
298
+ def fields!(access = {})
299
+ api = Api::Request.new do |request|
300
+ request[:access] = access
301
+ request[:method] = :GET
302
+ request[:path] = "/merge/{{client_id}}/questionnaires/#{guid}/fields"
303
+ end
304
+ api.add_params(include_geometry: true)
305
+ json = api.execute!
214
306
 
215
- execution
307
+ json[:fields].map do |field|
308
+ Document::Field.new(field)
309
+ end
216
310
  end
217
311
 
218
312
  end # Questionnaire
@@ -0,0 +1,262 @@
1
+ module GroupDocs
2
+ class Questionnaire::Collector < Api::Entity
3
+
4
+ include Api::Helpers::Status
5
+
6
+ #
7
+ # Returns collector by its guid.
8
+ #
9
+ # @param [String] guid
10
+ # @param [Hash] access Access credentials
11
+ # @option access [String] :client_id
12
+ # @option access [String] :private_key
13
+ # @return [GroupDocs::Questionnaire::Collector]
14
+ #
15
+ def self.get!(guid, access = {})
16
+ json = Api::Request.new do |request|
17
+ request[:access] = access
18
+ request[:method] = :GET
19
+ request[:path] = "/merge/{{client_id}}/questionnaires/collectors/#{guid}"
20
+ end.execute!
21
+
22
+ collector = json[:collector]
23
+ collector.merge!(questionnaire: Questionnaire.new(id: collector[:questionnaire_id]))
24
+
25
+ new(collector)
26
+ end
27
+
28
+ # @attr [Integer] id
29
+ attr_accessor :id
30
+ # @attr [String] guid
31
+ attr_accessor :guid
32
+ # @attr [GroupDocs::Questionnaire] questionnaire
33
+ attr_accessor :questionnaire
34
+ # @attr [Integer] questionnaire_id
35
+ attr_accessor :questionnaire_id
36
+ # @attr [Symbol] status
37
+ attr_accessor :status
38
+ # @attr [Symbol] type
39
+ attr_accessor :type
40
+ # @attr [Integer] resolved_executions
41
+ attr_accessor :resolved_executions
42
+ # @attr [Array<String>] emails
43
+ attr_accessor :emails
44
+ # @attr [Time] modified
45
+ attr_accessor :modified
46
+
47
+ #
48
+ # Creates new GroupDocs::Questionnaire::Collector.
49
+ #
50
+ # @raise [ArgumentError] If questionnaire is not passed or is not an instance of GroupDocs::Questionnaire
51
+ #
52
+ def initialize(options = {}, &blk)
53
+ super(options, &blk)
54
+ questionnaire.is_a?(GroupDocs::Questionnaire) or raise ArgumentError,
55
+ "You have to pass GroupDocs::Questionnaire object: #{questionnaire.inspect}."
56
+ end
57
+
58
+ #
59
+ # Converts status to human-readable format.
60
+ # @return [Symbol]
61
+ #
62
+ def status
63
+ parse_status(@status)
64
+ end
65
+
66
+ #
67
+ # Updates type with machine-readable format.
68
+ #
69
+ # @param [Symbol] type
70
+ #
71
+ def type=(type)
72
+ @type = type.is_a?(Symbol) ? type.to_s.capitalize : type
73
+ end
74
+
75
+ #
76
+ # Converts type to human-readable format.
77
+ # @return [Symbol]
78
+ #
79
+ def type
80
+ parse_status(@type)
81
+ end
82
+
83
+ #
84
+ # Converts timestamp which is return by API server to Time object.
85
+ # @return [Time]
86
+ #
87
+ def modified
88
+ Time.at(@modified / 1000)
89
+ end
90
+
91
+ #
92
+ # Adds collector.
93
+ #
94
+ # @example
95
+ # questionnaire = GroupDocs::Questionnaire.get!(1)
96
+ # collector = GroupDocs::Questionnaire::Collector.new(questionnaire: questionnaire)
97
+ # collector.type = :link
98
+ # collector.add!
99
+ #
100
+ # @param [Hash] access Access credentials
101
+ # @option access [String] :client_id
102
+ # @option access [String] :private_key
103
+ #
104
+ def add!(access = {})
105
+ json = Api::Request.new do |request|
106
+ request[:access] = access
107
+ request[:method] = :POST
108
+ request[:path] = "/merge/{{client_id}}/questionnaires/#{questionnaire.guid}/collectors"
109
+ request[:request_body] = to_hash
110
+ end.execute!
111
+
112
+ self.id = json[:collector_id]
113
+ self.guid = json[:collector_guid]
114
+ end
115
+
116
+ #
117
+ # Updates collector.
118
+ #
119
+ # @example
120
+ # questionnaire = GroupDocs::Questionnaire.get!(1)
121
+ # collector = questionnaire.collectors!.first
122
+ # collector.type = :embedded
123
+ # collector.update!
124
+ #
125
+ # @param [Hash] access Access credentials
126
+ # @option access [String] :client_id
127
+ # @option access [String] :private_key
128
+ #
129
+ def update!(access = {})
130
+ Api::Request.new do |request|
131
+ request[:access] = access
132
+ request[:method] = :PUT
133
+ request[:path] = "/merge/{{client_id}}/questionnaires/collectors/#{guid}"
134
+ request[:request_body] = to_hash
135
+ end.execute!
136
+ end
137
+
138
+ #
139
+ # Removes collector.
140
+ #
141
+ # @param [Hash] access Access credentials
142
+ # @option access [String] :client_id
143
+ # @option access [String] :private_key
144
+ #
145
+ def remove!(access = {})
146
+ Api::Request.new do |request|
147
+ request[:access] = access
148
+ request[:method] = :DELETE
149
+ request[:path] = "/merge/{{client_id}}/questionnaires/collectors/#{guid}"
150
+ end.execute!
151
+ end
152
+
153
+ #
154
+ # Returns an array of questionnaire collector executions.
155
+ #
156
+ # @param [Hash] access Access credentials
157
+ # @option access [String] :client_id
158
+ # @option access [String] :private_key
159
+ # @return [Array<GroupDocs::Questionnaire::Execution>]
160
+ #
161
+ def executions!(access = {})
162
+ json = Api::Request.new do |request|
163
+ request[:access] = access
164
+ request[:method] = :GET
165
+ request[:path] = "/merge/{{client_id}}/questionnaires/collectors/#{guid}/executions"
166
+ end.execute!
167
+
168
+ json[:executions].map do |execution|
169
+ Questionnaire::Execution.new(execution)
170
+ end
171
+ end
172
+
173
+ #
174
+ # Adds new questionnaire execution.
175
+ #
176
+ # @example
177
+ # questionnaire = GroupDocs::Questionnaire.get!(1)
178
+ # collector = questionnaire.collectors!.first
179
+ # execution = GroupDocs::Questionnaire::Execution.new
180
+ # execution.executive = GroupDocs::User.new(primary_email: 'john@smith.com')
181
+ # # make sure to save execution as it has updated attributes
182
+ # execution = collector.add_execution!(execution)
183
+ # #=> #<GroupDocs::Questionnaire::Execution @id=1, @questionnaire_id=1>
184
+ #
185
+ # @param [GroupDocs::Questionnaire::Execution] execution
186
+ # @param [Hash] access Access credentials
187
+ # @option access [String] :client_id
188
+ # @option access [String] :private_key
189
+ # @return [GroupDocs::Questionnaire::Execution] updated execution
190
+ #
191
+ def add_execution!(execution, access = {})
192
+ execution.is_a?(GroupDocs::Questionnaire::Execution) or raise ArgumentError,
193
+ "Execution should be GroupDocs::Questionnaire::Execution object, received: #{execution.inspect}"
194
+
195
+ json = Api::Request.new do |request|
196
+ request[:access] = access
197
+ request[:method] = :POST
198
+ request[:path] = "/merge/{{client_id}}/questionnaires/collectors/#{guid}/executions"
199
+ request[:request_body] = execution.to_hash
200
+ end.execute!
201
+
202
+ execution.id = json[:execution_id]
203
+ execution.guid = json[:execution_guid]
204
+ execution.collector_id = json[:collector_id]
205
+
206
+ execution
207
+ end
208
+
209
+ #
210
+ # Creates new job to merge datasource into questionnaire collector.
211
+ #
212
+ # @example
213
+ # # get template and its first field
214
+ # document = GroupDocs::Document.templates!.first
215
+ # field = document.fields!.first
216
+ # # create questionnaire
217
+ # answer = GroupDocs::Questionnaire::Question::Answer.new(text: 'Text', value: 'Value1')
218
+ # question = GroupDocs::Questionnaire::Question.new(field: field.name, text: 'Question', answers: [answer])
219
+ # page = GroupDocs::Questionnaire::Page.new(number: field.page, questions: [question])
220
+ # questionnaire = GroupDocs::Questionnaire.new(name: 'Questionnaire', description: 'Description', pages: [page])
221
+ # questionnaire.create!
222
+ # # add questionnaire to document
223
+ # document.add_questionnaire! questionnaire
224
+ # # create collector
225
+ # collector = GroupDocs::Questionnaire::Collector.new(questionnaire: questionnaire)
226
+ # collector.type = :link
227
+ # collector.add!
228
+ # # create datasource and its field
229
+ # field = GroupDocs::DataSource::Field.new(field: field.name, values: %w(test1 test2))
230
+ # datasource = GroupDocs::DataSource.new(fields: [field])
231
+ # datasource.add!
232
+ # # fill collector with datasrouce and send results to email
233
+ # collector.fill!(datasource, email_results: true)
234
+ #
235
+ # @param [GroupDocs::DataSource] datasource
236
+ # @param [Hash] options
237
+ # @option options [Boolean] :new_type New file format type
238
+ # @option options [Boolean] :email_results Set to true if converted document should be emailed
239
+ # @param [Hash] access Access credentials
240
+ # @option access [String] :client_id
241
+ # @option access [String] :private_key
242
+ # @return [GroupDocs::Job]
243
+ #
244
+ # @raise [ArgumentError] if datasource is not GroupDocs::DataSource object
245
+ #
246
+ def fill!(datasource, options = {}, access = {})
247
+ datasource.is_a?(GroupDocs::DataSource) or raise ArgumentError,
248
+ "Datasource should be GroupDocs::DataSource object, received: #{datasource.inspect}"
249
+
250
+ api = Api::Request.new do |request|
251
+ request[:access] = access
252
+ request[:method] = :POST
253
+ request[:path] = "/merge/{{client_id}}/questionnaires/collectors/#{guid}/datasources/#{datasource.id}"
254
+ end
255
+ api.add_params(options)
256
+ json = api.execute!
257
+
258
+ Job.new(id: json[:job_id])
259
+ end
260
+
261
+ end # Questionnaire::Collector
262
+ end # GroupDocs