lib/prontoforms/form_submission.rb in prontoforms-0.2.0 vs lib/prontoforms/form_submission.rb in prontoforms-0.3.0

- old
+ new

@@ -16,21 +16,41 @@ property :username, key: 'username' # Aliases property :data_persisted?, key: 'dataPersisted' property :submitter_id, key: 'userId' property :submitter_username, key: 'username' + property :dispatcher, key: 'dispatcher' property :server_receive_date do str = data.fetch('serverReceiveDate') str.nil? ? nil : DateTime.strptime(str) end def pages + document.fetch('pages') + end + + def dispatcher + client.user(document.dig('dispatcher', 'identifier')) + end + + private + + # Returns additional data about the submission. Uses cached data, + # otherwise it loads and returns the data via #document! + def document + return @document if !@document.nil? + document! + end + + # Force loads the submission document + def document! res = client.connection.get do |req| req.url "#{resource_name}/#{id}/document.json" end if res.success? - JSON.parse(res.body).fetch('pages') + @document = JSON.parse(res.body) + @document end end end end