class ProntoForms::Form

A form includes inputs, validations, logic, and other configuration that facilitates data capture for a specific purpose.

Public Class Methods

resource_name() click to toggle source
# File lib/prontoforms/form.rb, line 10
def self.resource_name
  'forms'
end

Public Instance Methods

active_version_id() click to toggle source
# File lib/prontoforms/form.rb, line 29
def active_version_id
  full_data.dig('activeVersion', 'identifier')
end
current_version() click to toggle source
# File lib/prontoforms/form.rb, line 33
def current_version
  res = client.connection.get do |req|
    req.url "#{url}/iterations/#{active_version_id}"
  end

  FormIteration.new(JSON.parse(res.body), client, self)
end
form_space_id() click to toggle source

Get the Form's form space ID @return [String] Form space identifier

# File lib/prontoforms/form.rb, line 25
def form_space_id
  parent.id
end
iteration(id) click to toggle source
# File lib/prontoforms/form.rb, line 41
def iteration(id)
  raise ArgumentError, 'id must be provided' if id.nil?

  res = client.connection.get do |req|
    req.url "#{url}/iterations/#{id}"
  end

  FormIteration.new(JSON.parse(res.body), client, self)
end
iterations(query: {}) click to toggle source
# File lib/prontoforms/form.rb, line 51
def iterations(query: {})
  res = client.connection.get do |req|
    req.url "#{url}/iterations"
  end

  ResourceList.new(JSON.parse(res.body), {
    'p' => 0,
    's' => 100
  }.merge(query), :iterations, FormIteration, client, self)
end

Private Instance Methods

full_data() click to toggle source
# File lib/prontoforms/form.rb, line 64
def full_data
  return @full_data unless @full_data.nil?

  @full_data = client.form_space(form_space_id).form(id).data
  @full_data
end
url() click to toggle source
# File lib/prontoforms/form.rb, line 71
def url
  "formspaces/#{form_space_id}/forms/#{id}"
end