Class: TypedForm::Form
- Inherits:
-
Object
- Object
- TypedForm::Form
- Extended by:
- Forwardable
- Defined in:
- lib/typed_form/form.rb
Overview
A representation of the Typeform Form Data for a single form response.
Instance Attribute Summary collapse
-
#raw_json ⇒ String
readonly
Unformatted JSON data from an incoming Typeform Webhook.
Class Method Summary collapse
-
.find_form_by(client:, form_id:, token:) ⇒ Form
Uses the Typeform API client to query/find the form based on the form_id and token, then builds a new Form from that JSON request.
Instance Method Summary collapse
-
#initialize(json:) ⇒ Form
constructor
Creates a new instance of a Form, to allow querying.
- #json ⇒ Object
- #questions ⇒ Object
- #response ⇒ Object
- #responses ⇒ Object
-
#to_hash ⇒ Hash
Builds a hash of Questions matched with Answers.
Constructor Details
#initialize(json:) ⇒ Form
Creates a new instance of a Form, to allow querying
22 23 24 |
# File 'lib/typed_form/form.rb', line 22 def initialize(json:) @raw_json = json end |
Instance Attribute Details
#raw_json ⇒ String (readonly)
Unformatted JSON data from an incoming Typeform Webhook.
6 7 8 |
# File 'lib/typed_form/form.rb', line 6 def raw_json @raw_json end |
Class Method Details
.find_form_by(client:, form_id:, token:) ⇒ Form
Uses the Typeform API client to query/find the form based on the form_id and token, then builds a new Form from that JSON request.
36 37 38 39 |
# File 'lib/typed_form/form.rb', line 36 def self.find_form_by(client:, form_id:, token:) json = client.find_form_by(form_id: form_id, token: token) new(json: json) end |
Instance Method Details
#json ⇒ Object
26 27 28 |
# File 'lib/typed_form/form.rb', line 26 def json @_json ||= Util.normalize_spaces(@raw_json) end |
#questions ⇒ Object
15 |
# File 'lib/typed_form/form.rb', line 15 def_delegators :submission, :questions |
#response ⇒ Object
47 48 49 50 |
# File 'lib/typed_form/form.rb', line 47 def response raise StandardError, "Form expects a single response" if multi_response? responses.first end |
#responses ⇒ Object
11 |
# File 'lib/typed_form/form.rb', line 11 def_delegators :parsed_json, :responses |
#to_hash ⇒ Hash
Builds a hash of Questions matched with Answers.
43 44 45 |
# File 'lib/typed_form/form.rb', line 43 def to_hash questions.each_with_object({}) { |q, hash| hash[q.text] = q.answer } end |