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 +4 -4
- data/lib/prontoforms/form.rb +53 -0
- data/lib/prontoforms/form_iteration.rb +40 -0
- data/lib/prontoforms/form_space.rb +10 -1
- data/lib/prontoforms/form_submission.rb +32 -19
- data/lib/prontoforms/resource.rb +2 -1
- data/lib/prontoforms/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf9bb12142b5957e341f48804ce06b73f8842cdcbe8e2831e34823299ca73017
|
4
|
+
data.tar.gz: c3760f082616943fa75dd0fad8f4bf0554390d75bea741f448baead8ce97bdfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a5da5f5afda87fd00f326deba55c97169aad8918347f308df002c2525420e92d8a22983199a2bf498afa0b8a55ea32be25549a5b20ce86fb0578123100733c8
|
7
|
+
data.tar.gz: 8f0312762f55f92b0a3d5383fef1cc1558b9e65a7ba8d7c2f770c63a97d0ef695976e542459b839bf76966f05daf776c4b8aff9dad5ca4dad690448ed64c31da
|
data/lib/prontoforms/form.rb
CHANGED
@@ -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(
|
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
|
-
|
73
|
+
form_space.form(full_data.dig('form', 'formId'))
|
74
74
|
end
|
75
75
|
|
76
|
-
# Retrieve the
|
77
|
-
# @return [
|
78
|
-
def
|
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 "#{
|
82
|
-
req.options.on_data = proc
|
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
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
112
|
+
def full_data
|
113
|
+
return @full_data unless @full_data.nil?
|
102
114
|
|
103
|
-
|
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,
|
data/lib/prontoforms/resource.rb
CHANGED
data/lib/prontoforms/version.rb
CHANGED
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:
|
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-
|
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
|