Class: ProntoForms::FormSubmission
- Defined in:
- lib/prontoforms/form_submission.rb
Overview
A FormSubmission represents submitted form data in ProntoForms. It includes various metadata about the submission as well.
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
Instance Method Summary collapse
-
#data_persisted ⇒ Boolean
(also: #data_persisted?)
Has the submission data been persisted on the server.
-
#data_state ⇒ String
Submission data state.
-
#dispatched? ⇒ Boolean
Check if the form was dispatched.
-
#dispatcher ⇒ User
Retrieve the dispatching User, if the form was dispatched.
-
#documents(populate: false) ⇒ Array
Retrieve all documents attached to this form submission.
-
#download_document(document) ⇒ IO
Download a specific document.
-
#form ⇒ Form
Retrieve the form for the form submission.
-
#form_id ⇒ String
The form’s identifier.
-
#form_space ⇒ FormSpace
Retrieve the form space for the form submission.
-
#form_version ⇒ FormIteration
Retrieve the current version of the form.
-
#form_version_id ⇒ String
The form’s version identifier.
-
#id ⇒ String
The FormSubmission identifier.
-
#pages ⇒ Hash
Retrieve the pages containing the form questions and answers.
-
#reference_number ⇒ String
Submission reference number.
-
#server_receive_date ⇒ DateTime
Timestamp the submission was received by the server.
-
#state ⇒ String
Submission state.
-
#user_id ⇒ String
(also: #submitter_id)
Submitter’s user identifier.
-
#username ⇒ String
(also: #submitter_username)
Submitter’s username.
Methods inherited from Resource
#initialize, property, #resource_name
Constructor Details
This class inherits a constructor from ProntoForms::Resource
Class Method Details
.resource_name ⇒ Object
10 11 12 |
# File 'lib/prontoforms/form_submission.rb', line 10 def self.resource_name 'data' end |
Instance Method Details
#data_persisted ⇒ Boolean Also known as: data_persisted?
Returns Has the submission data been persisted on the server.
24 |
# File 'lib/prontoforms/form_submission.rb', line 24 property :data_persisted, key: 'dataPersisted' |
#data_state ⇒ String
Returns Submission data state.
22 |
# File 'lib/prontoforms/form_submission.rb', line 22 property :data_state, key: 'dataState' |
#dispatched? ⇒ Boolean
Check if the form was dispatched
60 61 62 |
# File 'lib/prontoforms/form_submission.rb', line 60 def dispatched? !document.dig('dispatcher', 'identifier').nil? end |
#dispatcher ⇒ User
Retrieve the dispatching User, if the form was dispatched
52 53 54 55 56 |
# File 'lib/prontoforms/form_submission.rb', line 52 def dispatcher return nil unless dispatched? client.user(document.dig('dispatcher', 'identifier')) end |
#documents(populate: false) ⇒ Array
Retrieve all documents attached to this form submission
84 85 86 87 88 89 90 91 |
# File 'lib/prontoforms/form_submission.rb', line 84 def documents(populate: false) ids = form_version.document_ids if populate ids.map { |id| form_space.document(id) } else ids end end |
#download_document(document) ⇒ IO
Download a specific document. The Document must have been attached to the form’s current version at the time of submission.
96 97 98 99 100 101 102 103 104 |
# File 'lib/prontoforms/form_submission.rb', line 96 def download_document(document) io = StringIO.new client.connection.get do |req| req.url "#{url}/documents/#{document.id}" req..on_data = proc { |chunk| io << chunk } end io.rewind io end |
#form ⇒ Form
Retrieve the form for the form submission
72 73 74 |
# File 'lib/prontoforms/form_submission.rb', line 72 def form form_space.form(full_data.dig('form', 'formId')) end |
#form_id ⇒ String
Returns The form’s identifier.
28 |
# File 'lib/prontoforms/form_submission.rb', line 28 property :form_id, key: 'formId' |
#form_space ⇒ FormSpace
Retrieve the form space for the form submission
66 67 68 |
# File 'lib/prontoforms/form_submission.rb', line 66 def form_space client.form_space(full_data.dig('form', 'formSpaceId')) end |
#form_version ⇒ FormIteration
Retrieve the current version of the form
78 79 80 |
# File 'lib/prontoforms/form_submission.rb', line 78 def form_version form.current_version end |
#form_version_id ⇒ String
Returns The form’s version identifier.
26 |
# File 'lib/prontoforms/form_submission.rb', line 26 property :form_version_id, key: 'formVersionId' |
#id ⇒ String
Returns The FormSubmission identifier.
15 |
# File 'lib/prontoforms/form_submission.rb', line 15 property :id, key: 'identifier' |
#pages ⇒ Hash
Retrieve the pages containing the form questions and answers
46 47 48 |
# File 'lib/prontoforms/form_submission.rb', line 46 def pages document.fetch('pages') end |
#reference_number ⇒ String
Returns Submission reference number.
17 |
# File 'lib/prontoforms/form_submission.rb', line 17 property :reference_number, key: 'referenceNumber' |
#server_receive_date ⇒ DateTime
Returns Timestamp the submission was received by the server.
39 40 41 42 |
# File 'lib/prontoforms/form_submission.rb', line 39 property :server_receive_date do str = data.fetch('serverReceiveDate') str.nil? ? nil : DateTime.strptime(str) end |
#state ⇒ String
Returns Submission state. One of: Complete, Processing, Dispatched.
20 |
# File 'lib/prontoforms/form_submission.rb', line 20 property :state, key: 'state' |
#user_id ⇒ String Also known as: submitter_id
Returns Submitter’s user identifier.
30 |
# File 'lib/prontoforms/form_submission.rb', line 30 property :user_id, key: 'userId' |
#username ⇒ String Also known as: submitter_username
Returns Submitter’s username.
32 |
# File 'lib/prontoforms/form_submission.rb', line 32 property :username, key: 'username' |