prontoforms 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d15ef56d13e8ea0e980e73be80c8a766b9d82ab5947899aea364e5e5f8562bd0
4
- data.tar.gz: 75e60d77da7d5bfabf8494029a5e80f24f8548fb1f8781847e4adf2e4b43b797
3
+ metadata.gz: cf9bb12142b5957e341f48804ce06b73f8842cdcbe8e2831e34823299ca73017
4
+ data.tar.gz: c3760f082616943fa75dd0fad8f4bf0554390d75bea741f448baead8ce97bdfc
5
5
  SHA512:
6
- metadata.gz: 7b3883d2eb0c2a740546ac2d9deb955dc90e68c66dec3409b3fa05ba025111b4fd8340c84b40861071a7a47851250df95062edcd08f43f3b24fb9b14954f1a90
7
- data.tar.gz: 0d483ea0b5b6cb8bf112a3c6097c6ff2af4180a8c5b6c859afc7b724a57e5a0999b14c49aecc03d887f3bf09d5de85668254f52ab9a87bb9131bceb83515c713
6
+ metadata.gz: 4a5da5f5afda87fd00f326deba55c97169aad8918347f308df002c2525420e92d8a22983199a2bf498afa0b8a55ea32be25549a5b20ce86fb0578123100733c8
7
+ data.tar.gz: 8f0312762f55f92b0a3d5383fef1cc1558b9e65a7ba8d7c2f770c63a97d0ef695976e542459b839bf76966f05daf776c4b8aff9dad5ca4dad690448ed64c31da
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'prontoforms/resource'
4
+ require 'prontoforms/form_iteration'
4
5
 
5
6
  module ProntoForms
6
7
  # A form includes inputs, validations, logic, and other configuration that
@@ -18,5 +19,57 @@ module ProntoForms
18
19
  property :description, key: 'description'
19
20
  # @return [String] Form state
20
21
  property :state, key: 'state'
22
+
23
+ # Get the Form's form space ID
24
+ # @return [String] Form space identifier
25
+ def form_space_id
26
+ parent.id
27
+ end
28
+
29
+ def active_version_id
30
+ full_data.dig('activeVersion', 'identifier')
31
+ end
32
+
33
+ def current_version
34
+ res = client.connection.get do |req|
35
+ req.url "#{url}/iterations/#{active_version_id}"
36
+ end
37
+
38
+ FormIteration.new(JSON.parse(res.body), client, self)
39
+ end
40
+
41
+ def iteration(id)
42
+ raise ArgumentError, 'id must be provided' if id.nil?
43
+
44
+ res = client.connection.get do |req|
45
+ req.url "#{url}/iterations/#{id}"
46
+ end
47
+
48
+ FormIteration.new(JSON.parse(res.body), client, self)
49
+ end
50
+
51
+ def iterations(query: {})
52
+ res = client.connection.get do |req|
53
+ req.url "#{url}/iterations"
54
+ end
55
+
56
+ ResourceList.new(JSON.parse(res.body), {
57
+ 'p' => 0,
58
+ 's' => 100
59
+ }.merge(query), :iterations, FormIteration, client, self)
60
+ end
61
+
62
+ private
63
+
64
+ def full_data
65
+ return @full_data unless @full_data.nil?
66
+
67
+ @full_data = client.form_space(form_space_id).form(id).data
68
+ @full_data
69
+ end
70
+
71
+ def url
72
+ "formspaces/#{form_space_id}/forms/#{id}"
73
+ end
21
74
  end
22
75
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'prontoforms/resource'
4
+
5
+ module ProntoForms
6
+ # A form iteration is a form configuration, distinct from a form version
7
+ # in that version numbers increment when a form iteration is deployed.
8
+ class FormIteration < Resource
9
+ def self.resource_name
10
+ 'iterations'
11
+ end
12
+
13
+ # @return [String] The form iteration identifier
14
+ property :id, key: 'identifier'
15
+ # @return [Integer] Version number
16
+ property :version, key: 'version'
17
+ # @return [String] Form iteration state
18
+ property :state, key: 'state'
19
+ # @return [String] Initiation method for the form iteration
20
+ property :initiation_method, key: 'initiationMethod'
21
+ # @return [String] Can dispatched forms of this iteration be declined
22
+ property :dispatched_declinable, key: 'dispatchDeclinable'
23
+
24
+ alias can_decline_dispatch? dispatched_declinable
25
+
26
+ # @return [Array] Array of document IDs attached to this iteration
27
+ def document_ids
28
+ full_data.fetch('documentIds')
29
+ end
30
+
31
+ private
32
+
33
+ def full_data
34
+ return @full_data unless @full_data.nil?
35
+
36
+ @full_data = parent.iteration(id).data
37
+ @full_data
38
+ end
39
+ end
40
+ end
@@ -31,6 +31,15 @@ module ProntoForms
31
31
  }, :documents, Document, self)
32
32
  end
33
33
 
34
+ def form(form_id)
35
+ res = client.connection.get do |req|
36
+ req.url "formspaces/#{id}/forms/#{form_id}"
37
+ end
38
+
39
+ data = JSON.parse(res.body)
40
+ Form.new(data, client, self)
41
+ end
42
+
34
43
  # Get all forms in the form space
35
44
  # @return [ResourceList] A ResourceList containing Form objects
36
45
  def forms(query: {})
@@ -42,7 +51,7 @@ module ProntoForms
42
51
  ResourceList.new(JSON.parse(res.body), {
43
52
  'p' => 0,
44
53
  's' => 100
45
- }.merge(query), :forms, Form, self)
54
+ }.merge(query), :forms, Form, client, self)
46
55
  end
47
56
  end
48
57
  end
@@ -64,43 +64,56 @@ module ProntoForms
64
64
  # Retrieve the form space for the form submission
65
65
  # @return [FormSpace] Form space for the submission's form
66
66
  def form_space
67
- client.form_space(data.dig('form', 'formSpaceId'))
67
+ client.form_space(full_data.dig('form', 'formSpaceId'))
68
68
  end
69
69
 
70
70
  # Retrieve the form for the form submission
71
71
  # @return [Form] Form for the submission
72
72
  def form
73
- client.form(data.dig('form', 'formId'))
73
+ form_space.form(full_data.dig('form', 'formId'))
74
74
  end
75
75
 
76
- # Retrieve the standard PDF document for the form submission
77
- # @return [IO] Readable stream containing the PDF contents
78
- def pdf
76
+ # Retrieve the current version of the form
77
+ # @return [FormIteration] The form iteration
78
+ def form_version
79
+ form.current_version
80
+ end
81
+
82
+ # Retrieve all documents attached to this form submission
83
+ # @return [Array] Documents attached to the form submission
84
+ def documents(populate: false)
85
+ ids = form_version.document_ids
86
+ if populate
87
+ ids.map { |id| form.iteration(id) }
88
+ else
89
+ ids
90
+ end
91
+ end
92
+
93
+ # Download a specific document. The Document must have been attached to
94
+ # the form's current version at the time of submission.
95
+ # @return [IO] Data stream for the document
96
+ def download_document(document)
79
97
  io = StringIO.new
80
98
  client.connection.get do |req|
81
- req.url "#{resource_name}/#{id}/documents/#{pdf_document.id}"
82
- req.options.on_data = proc do |chunk|
83
- io << chunk
84
- end
99
+ req.url "#{url}/documents/#{document.id}"
100
+ req.options.on_data = proc { |chunk| io << chunk }
85
101
  end
86
-
87
102
  io.rewind
88
103
  io
89
104
  end
90
105
 
91
106
  private
92
107
 
93
- # Retrieve the standard PDF document for the form submission
94
- # @return [Document] PDF document for the form submission
95
- # @raises RuntimeError
96
- def pdf_document
97
- document = form_space.documents.items.find do |doc|
98
- doc.type == 'Pdf' && doc.standard?
99
- end
108
+ def url
109
+ "#{resource_name}/#{id}"
110
+ end
100
111
 
101
- raise "No PDF document found for form space #{fs.id}" if document.nil?
112
+ def full_data
113
+ return @full_data unless @full_data.nil?
102
114
 
103
- document
115
+ @full_data = client.form_submission(id).data
116
+ @full_data
104
117
  end
105
118
 
106
119
  # Returns additional data about the submission. Uses cached data,
@@ -20,7 +20,8 @@ module ProntoForms
20
20
  if block_given?
21
21
  instance_eval(&block)
22
22
  elsif !key.nil?
23
- data.fetch(key)
23
+ key = [key] unless key.is_a?(Array)
24
+ key.inject(data) { |obj, k| obj.fetch(k) }
24
25
  end
25
26
  end
26
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProntoForms
4
- VERSION = '1.0.1'
4
+ VERSION = '2.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prontoforms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Holden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-01 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -159,6 +159,7 @@ files:
159
159
  - lib/prontoforms/client.rb
160
160
  - lib/prontoforms/document.rb
161
161
  - lib/prontoforms/form.rb
162
+ - lib/prontoforms/form_iteration.rb
162
163
  - lib/prontoforms/form_space.rb
163
164
  - lib/prontoforms/form_submission.rb
164
165
  - lib/prontoforms/resource.rb