Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Streetbees/form-stalker

Repository files navigation

FormStalker

FormStack API client that can extract conditional logic.

Some missing methods like editing or deleting a form will be added along the way but we also encourage you do implement them and submitting a PR 👍

Code Climate Test Coverage Build Status Gem Version

1) Usage

Create an initializer and set your formstack oauth token.

FormStalker.configure do |config|
  config.oauth_token = 'your formstack oauth token'
end

Make requests to FormStack and receive a sanitized response

response = FormStalker.form(1)

# don't trust (response.status == :ok) because Formstack API does not respect the HTTP status codes
if response.ok?
  form_data = response.data # returns a FormStalker::Data::Form instance
else
  response.status # returns a symbol representing FormStack's HTTP status
  response.error # returns a message string explaining the error
end

2) FormStalker.form

response = FormStalker.form(1)

raise response.error unless response.ok?

form_data = response.data

form_data.id # returns an integer
form_data.created # returns a date
form_data.deleted # returns a boolean
form_data.fields # returns an array of FormStalker::Data::FormField instances
# etc.
form_data.attributes # returns a Hash with all of its data

# and the one your are probably looking for
form_data.logic # returns an instance of FormStalker::Data::FormFieldsLogic

form_data.logic.logic_field_ids # returns an array of field ids that have logic
form_data.logic.calc_field_ids # returns an array of field ids

form_data.logic.checks # returns an array of Hashes with the actual logic

# Example of what can be inside the #checks
[
  {
    target: 37314714,
    action: 'Show',
    bool: 'AND',
    fields: [41111633],
    checks: [{ field: 41111633, condition: '==', option: 'Option1' }]
  },
  {
    target: 40952921,
    action: 'Show',
    bool: 'AND',
    fields: [37314736],
    checks: [{ field: 37314736, condition: '!=', option: 'Option1' }]
  }
  {
    target: 37314784,
    action: 'Show',
    bool: 'AND',
    fields: [37314745],
    checks: [{ field: 37314745, condition: '==', option: '0' }]
  }
]

2) FormStalker.form_fields

response = FormStalker.form_fields(1)

raise response.error unless response.ok?

form_fields = response.data # returns an array of FormStalker::Data::FormField instances

form_fields.each do |form_fields_data|
  form_fields_data.id # returns an integer
  form_fields_data.required # returns an boolean
  # etc.
  form_fields_data.attributes # returns a Hash with all of its data
end

4) Instalation

Add this to your Gemfile:

gem 'form_stalker'

And then execute:

$> bundle install

3) F.A.Q.

  • wip