class ProntoForms::FormSubmission
A FormSubmission
represents submitted form data in ProntoForms
. It includes various metadata about the submission as well.
Public Class Methods
# File lib/prontoforms/form_submission.rb, line 10 def self.resource_name 'data' end
Public Instance Methods
Check if the form was dispatched @return [Boolean] True if the form was dispatched; false otherwise
# File lib/prontoforms/form_submission.rb, line 60 def dispatched? !document.dig('dispatcher', 'identifier').nil? end
Retrieve the dispatching User
, if the form was dispatched @return [User] The user that dispatched the form, or nil
# File lib/prontoforms/form_submission.rb, line 52 def dispatcher return nil unless dispatched? client.user(document.dig('dispatcher', 'identifier')) end
Retrieve all documents attached to this form submission @return [Array] Documents attached to the form submission
# 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 a specific document. The Document
must have been attached to the form's current version at the time of submission. @return [IO] Data stream for the document
# 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.options.on_data = proc { |chunk| io << chunk } end io.rewind io end
Retrieve the form for the form submission @return [Form] Form
for the submission
# File lib/prontoforms/form_submission.rb, line 72 def form form_space.form(full_data.dig('form', 'formId')) end
Retrieve the form space for the form submission @return [FormSpace] Form
space for the submission's form
# File lib/prontoforms/form_submission.rb, line 66 def form_space client.form_space(full_data.dig('form', 'formSpaceId')) end
Retrieve the current version of the form @return [FormIteration] The form iteration
# File lib/prontoforms/form_submission.rb, line 78 def form_version form.current_version end
Retrieve the pages containing the form questions and answers @return [Hash] Hash of questions and answers for the FormSubmission
# File lib/prontoforms/form_submission.rb, line 46 def pages document.fetch('pages') end
Private Instance Methods
Returns additional data about the submission. Uses cached data, otherwise it loads and returns the data via document!
# File lib/prontoforms/form_submission.rb, line 121 def document return @document unless @document.nil? document! end
Force loads the submission document
# File lib/prontoforms/form_submission.rb, line 128 def document! res = client.connection.get do |req| req.url "#{resource_name}/#{id}/document.json" end @document = JSON.parse(res.body) @document end
# File lib/prontoforms/form_submission.rb, line 112 def full_data return @full_data unless @full_data.nil? @full_data = client.form_submission(id).data @full_data end
# File lib/prontoforms/form_submission.rb, line 108 def url "#{resource_name}/#{id}" end