typed_form 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/typed_form/form.rb +6 -3
- data/lib/typed_form/util.rb +10 -0
- data/lib/typed_form/version.rb +1 -1
- data/lib/typed_form/virtual_model.rb +3 -1
- data/lib/typed_form/webhook.rb +9 -3
- data/lib/typed_form.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab5449edccd43bad3e14733d9b82bb90de304bf8
|
4
|
+
data.tar.gz: 6b073c538628ecc3c444c0f74831ebf8517dcff4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0c5d90fedf79764a064b5afd998cf7eea2560ac29eaff4bf83ab16791186bbf30269f60a4963ace0f2a9f7b6390ad477334e1bf80c976091b3ade1c91b0913
|
7
|
+
data.tar.gz: 0b51cd19c52a243fca662e09a24f822d037f82d0d4493231dae920f0b091c69cbb8425657447d9566314ef22b3d96bb6516e9d6d3598c335b8b408307b9ba18f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### [0.1.4] - 2017-03-16
|
4
|
+
|
5
|
+
Strips additional whitespace and isolates whitespace stripping behavior to a Util class, to allow for easier test coverage. Adds raw_json accessors to models where we normalize JSON input to allow for end-users to determine whether they want clean/normalized JSON or the original results from Typeform. This prevents mismatches in the regular expression => attribute matching in VirtualModel, which were running into issues when `" " != " "`, preventing the regular expressions from matching.
|
6
|
+
|
3
7
|
### [0.1.3] - 2017-03-16
|
4
8
|
|
5
9
|
Adds support for typecasting Yes/No and Terms of Service fields in TypedForm::VirtualModel. Adds "original_answer" field to Questions to preserve original values, either for debugging purposes or for situations where typecasting is not desirable.
|
data/lib/typed_form/form.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module TypedForm
|
2
2
|
# A representation of the Typeform Form Data for a single form response.
|
3
|
+
#
|
4
|
+
# @attr_reader [String] raw_json Unformatted JSON data from an incoming
|
5
|
+
# Typeform Webhook.
|
3
6
|
class Form
|
4
7
|
extend Forwardable
|
5
8
|
|
@@ -11,6 +14,8 @@ module TypedForm
|
|
11
14
|
# @see FormSubmission#questions
|
12
15
|
def_delegators :submission, :questions
|
13
16
|
|
17
|
+
attr_reader :raw_json
|
18
|
+
|
14
19
|
# Creates a new instance of a Form, to allow querying
|
15
20
|
#
|
16
21
|
# @params [String] json Typeform Data API JSON input for form.
|
@@ -18,10 +23,8 @@ module TypedForm
|
|
18
23
|
@raw_json = json
|
19
24
|
end
|
20
25
|
|
21
|
-
# Removes non-breaking spaces (character point 160) from TypeForm data
|
22
|
-
# before beginning processing.
|
23
26
|
def json
|
24
|
-
@_json ||= @raw_json
|
27
|
+
@_json ||= Util.normalize_spaces(@raw_json)
|
25
28
|
end
|
26
29
|
|
27
30
|
# Uses the Typeform API client to query/find the form based on the form_id
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module TypedForm
|
2
|
+
# General utility functions used in multiple areas in the gem.
|
3
|
+
class Util
|
4
|
+
# Removes non-breaking spaces (character point 160) from TypeForm data
|
5
|
+
# before beginning processing.
|
6
|
+
def self.normalize_spaces(text)
|
7
|
+
text.gsub("\\u00a0", " ").gsub(/[[:space:]]/, " ")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/typed_form/version.rb
CHANGED
@@ -54,7 +54,9 @@ module TypedForm
|
|
54
54
|
private
|
55
55
|
|
56
56
|
def find_answer_to(text)
|
57
|
-
question = form.questions.detect
|
57
|
+
question = form.questions.detect do |q|
|
58
|
+
q.text.match Regexp.new Util.normalize_spaces(text)
|
59
|
+
end
|
58
60
|
return unless question
|
59
61
|
question.answer
|
60
62
|
end
|
data/lib/typed_form/webhook.rb
CHANGED
@@ -4,7 +4,8 @@ module TypedForm
|
|
4
4
|
#
|
5
5
|
# @see https://www.typeform.com/help/webhooks/ Typeform Webhook Docs
|
6
6
|
#
|
7
|
-
# @attr_reader [String]
|
7
|
+
# @attr_reader [String] raw_json Unformatted JSON data from an incoming
|
8
|
+
# Typeform Webhook.
|
8
9
|
class Webhook
|
9
10
|
extend Forwardable
|
10
11
|
|
@@ -16,12 +17,17 @@ module TypedForm
|
|
16
17
|
# @!method form_id
|
17
18
|
# @return [String] The form ID from the webhook submission.
|
18
19
|
def_delegators :form_response, :form_id
|
19
|
-
|
20
|
+
|
21
|
+
attr_reader :raw_json
|
20
22
|
|
21
23
|
# Creates a new webhook object from an incoming Typeform Data stream.
|
22
24
|
# @param [String] json JSON Data from a Typeform Webhook
|
23
25
|
def initialize(json:)
|
24
|
-
@
|
26
|
+
@raw_json = json
|
27
|
+
end
|
28
|
+
|
29
|
+
def json
|
30
|
+
@_json ||= Util.normalize_spaces(@raw_json).freeze
|
25
31
|
end
|
26
32
|
|
27
33
|
# Retrieves the Token from the Webhook JSON data.
|
data/lib/typed_form.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Cole
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-03-
|
12
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/typed_form/form_data/form_submission.rb
|
142
142
|
- lib/typed_form/form_data/parsed_json.rb
|
143
143
|
- lib/typed_form/form_data/question.rb
|
144
|
+
- lib/typed_form/util.rb
|
144
145
|
- lib/typed_form/version.rb
|
145
146
|
- lib/typed_form/virtual_model.rb
|
146
147
|
- lib/typed_form/webhook.rb
|