Class: ProntoForms::FormSubmission

Inherits:
Resource
  • Object
show all
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

#client, #data, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#initialize, property, #resource_name

Constructor Details

This class inherits a constructor from ProntoForms::Resource

Class Method Details

.resource_nameObject



10
11
12
# File 'lib/prontoforms/form_submission.rb', line 10

def self.resource_name
  'data'
end

Instance Method Details

#data_persistedBoolean Also known as: data_persisted?

Returns Has the submission data been persisted on the server.

Returns:

  • (Boolean)

    Has the submission data been persisted on the server



24
# File 'lib/prontoforms/form_submission.rb', line 24

property :data_persisted, key: 'dataPersisted'

#data_stateString

Returns Submission data state.

Returns:

  • (String)

    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

Returns:

  • (Boolean)

    True if the form was dispatched; false otherwise



60
61
62
# File 'lib/prontoforms/form_submission.rb', line 60

def dispatched?
  !document.dig('dispatcher', 'identifier').nil?
end

#dispatcherUser

Retrieve the dispatching User, if the form was dispatched

Returns:

  • (User)

    The user that dispatched the form, or nil



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

Returns:

  • (Array)

    Documents attached to the 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.

Returns:

  • (IO)

    Data stream for the document



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.options.on_data = proc { |chunk| io << chunk }
  end
  io.rewind
  io
end

#formForm

Retrieve the form for the form submission

Returns:

  • (Form)

    Form for the submission



72
73
74
# File 'lib/prontoforms/form_submission.rb', line 72

def form
  form_space.form(full_data.dig('form', 'formId'))
end

#form_idString

Returns The form’s identifier.

Returns:

  • (String)

    The form’s identifier



28
# File 'lib/prontoforms/form_submission.rb', line 28

property :form_id, key: 'formId'

#form_spaceFormSpace

Retrieve the form space for the form submission

Returns:

  • (FormSpace)

    Form space for the submission’s form



66
67
68
# File 'lib/prontoforms/form_submission.rb', line 66

def form_space
  client.form_space(full_data.dig('form', 'formSpaceId'))
end

#form_versionFormIteration

Retrieve the current version of the form

Returns:



78
79
80
# File 'lib/prontoforms/form_submission.rb', line 78

def form_version
  form.current_version
end

#form_version_idString

Returns The form’s version identifier.

Returns:

  • (String)

    The form’s version identifier



26
# File 'lib/prontoforms/form_submission.rb', line 26

property :form_version_id, key: 'formVersionId'

#idString

Returns The FormSubmission identifier.

Returns:

  • (String)

    The FormSubmission identifier



15
# File 'lib/prontoforms/form_submission.rb', line 15

property :id, key: 'identifier'

#pagesHash

Retrieve the pages containing the form questions and answers

Returns:

  • (Hash)

    Hash of questions and answers for the FormSubmission



46
47
48
# File 'lib/prontoforms/form_submission.rb', line 46

def pages
  document.fetch('pages')
end

#reference_numberString

Returns Submission reference number.

Returns:

  • (String)

    Submission reference number



17
# File 'lib/prontoforms/form_submission.rb', line 17

property :reference_number, key: 'referenceNumber'

#server_receive_dateDateTime

Returns Timestamp the submission was received by the server.

Returns:

  • (DateTime)

    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

#stateString

Returns Submission state. One of: Complete, Processing, Dispatched.

Returns:

  • (String)

    Submission state. One of: Complete, Processing, Dispatched



20
# File 'lib/prontoforms/form_submission.rb', line 20

property :state, key: 'state'

#user_idString Also known as: submitter_id

Returns Submitter’s user identifier.

Returns:

  • (String)

    Submitter’s user identifier



30
# File 'lib/prontoforms/form_submission.rb', line 30

property :user_id, key: 'userId'

#usernameString Also known as: submitter_username

Returns Submitter’s username.

Returns:

  • (String)

    Submitter’s username



32
# File 'lib/prontoforms/form_submission.rb', line 32

property :username, key: 'username'