typed_form 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53e20316dde02ffffb4d493a7f20b90f96aea947
4
- data.tar.gz: a420c807742102952a4b2a2af4e21105b69832d0
3
+ metadata.gz: ab5449edccd43bad3e14733d9b82bb90de304bf8
4
+ data.tar.gz: 6b073c538628ecc3c444c0f74831ebf8517dcff4
5
5
  SHA512:
6
- metadata.gz: 5490138b490865e105087be1be998b2f6b0e2ba2e78532f921ed13e5658ff16912828ba841491f995e9f7187cffe2bfa2027c2563a7cbf0c3af2167291d0d2d2
7
- data.tar.gz: '0659ee90598a0a52163129f1bfe606f656f6ad8fbc2ab999b5210ca869cca284058089063a7dc8fa7ba278693ae7d61ef1b59f3f2c97a775fe2db2bee5e47333'
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.
@@ -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.gsub("\\u00a0", " ")
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
@@ -1,4 +1,4 @@
1
1
  module TypedForm
2
2
  # Up-to-date version of gem.
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
@@ -54,7 +54,9 @@ module TypedForm
54
54
  private
55
55
 
56
56
  def find_answer_to(text)
57
- question = form.questions.detect { |q| q.text.match Regexp.new(text) }
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
@@ -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] json JSON data from an incoming Typeform Webhook
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
- attr_reader :json
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
- @json = json.freeze
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
@@ -3,6 +3,7 @@ require "forwardable"
3
3
  require "arendelle"
4
4
  require "date"
5
5
  require "typed_form/api/client"
6
+ require "typed_form/util"
6
7
  require "typed_form/form_data/parsed_json"
7
8
  require "typed_form/form_data/question"
8
9
  require "typed_form/form_data/answers"
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.3
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-16 00:00:00.000000000 Z
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