form_stalker 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83d69f88a214755316a6cfa5f014989aabb02d1c
4
- data.tar.gz: ea5054f20c99e9c0b949a7a521b60560e35b2109
3
+ metadata.gz: b32f1eee7efca73e34710b9180b5f1358b8ae1c6
4
+ data.tar.gz: 0c85f46173c155550830617e7acbe9bb274e62fb
5
5
  SHA512:
6
- metadata.gz: 27ddfab878ab2b2c0e167cd61cb620a83a694c8b44fd56500b939353817770d8b4d5a08d2327c78f34bbf8a09a1189d89897f98665767a5fb05f6a5cab87db3c
7
- data.tar.gz: e7fdd74b0234a2129cab3c9cf0ea5ba52ee7421e1ae327f6f3770e0f9f3f68bccd209b526362ba00c676c1f36744a850e4cefd6abd2e57be796ed53faa3150b8
6
+ metadata.gz: 5b06ab3be3ad932d756530d8d7cdeef49d3f431043847a10b8976197606de7260606bc53e4043ea2b05d6d601edaa0a67eed753b4a45a99ac595d864ff7ef72f
7
+ data.tar.gz: af92d5230619f03b7949a58bbd85ead871d5f3b995531a5c980a9a987f44812dda1089800dd2f0e67a665267169b1c01ed5434d6d1ed08436a63aeb2d4dc713e
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # FormStalker
2
2
  FormStack API client that can extract conditional logic.
3
- 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 :thumbsup:
3
+
4
+ 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 :thumbsup:
4
5
 
5
6
  [![Code Climate](https://codeclimate.com/github/Streetbees/form-stalker/badges/gpa.svg)](https://codeclimate.com/github/Streetbees/form-stalker)
6
7
  [![Test Coverage](https://codeclimate.com/github/Streetbees/form-stalker/badges/coverage.svg)](https://codeclimate.com/github/Streetbees/form-stalker/coverage)
7
8
  [![Build Status](https://travis-ci.org/Streetbees/form-stalker.svg?branch=master)](https://travis-ci.org/Streetbees/form-stalker)
9
+ [![Gem Version](https://badge.fury.io/rb/form_stalker.svg)](https://badge.fury.io/rb/form_stalker)
8
10
 
9
11
  ## 1) Usage
10
- Create an initializer and set your your formstack oauth token.
12
+ Create an initializer and set your formstack oauth token.
11
13
  ```ruby
12
14
  FormStalker.configure do |config|
13
15
  config.oauth_token = 'your formstack oauth token'
@@ -18,7 +20,8 @@ Make requests to FormStack and receive a sanitized response
18
20
  ```ruby
19
21
  response = FormStalker.form(1)
20
22
 
21
- if response.ok? # or (response.status == :ok)
23
+ # don't trust (response.status == :ok) because Formstack API does not respect the HTTP error status
24
+ if response.ok?
22
25
  form_data = response.data
23
26
  else
24
27
  response.status # will return a symbol representing FormStack's HTTP status
@@ -40,4 +43,4 @@ $> bundle install
40
43
  ```
41
44
 
42
45
  ## 3) F.A.Q.
43
- wip
46
+ - wip
@@ -1,4 +1,3 @@
1
- require 'form_stalker/data/base'
2
1
  require 'form_stalker/data/form'
3
2
  require 'form_stalker/data/form_field'
4
3
  require 'form_stalker/connection'
@@ -1,6 +1,22 @@
1
+ require 'form_stalker/data/parser'
2
+
1
3
  module FormStalker
2
4
  module Data
3
5
  class Base < OpenStruct
6
+ def self.schema(options = nil)
7
+ type_cast_schema.merge! options
8
+ end
9
+
10
+ def self.type_cast_schema
11
+ @type_cast_schema ||= { id: :integer }
12
+ end
13
+
14
+ def self.inherited(base)
15
+ base.type_cast_schema.merge! type_cast_schema.clone
16
+
17
+ super
18
+ end
19
+
4
20
  def self.tap_into(response)
5
21
  return response unless response.ok?
6
22
 
@@ -15,6 +31,18 @@ module FormStalker
15
31
  end
16
32
 
17
33
  alias attributes marshal_dump
34
+
35
+ attr_reader :parser
36
+
37
+ def initialize(attributes = nil)
38
+ attributes ||= {}
39
+
40
+ instance_variable_set('@table', attributes)
41
+
42
+ @parser = Parser.new(self, self.class.type_cast_schema, attributes)
43
+
44
+ super(@parser.parse_attributes)
45
+ end
18
46
  end
19
47
  end
20
48
  end
@@ -1,7 +1,24 @@
1
+ require 'form_stalker/data/base'
1
2
 
2
3
  module FormStalker
3
4
  module Data
4
5
  class Form < Base
6
+ schema db: :boolean,
7
+ views: :integer,
8
+ deleted: :boolean,
9
+ created: :datetime,
10
+ updated: :datetime,
11
+ inactive: :boolean,
12
+ encrypted: :boolean,
13
+ submissions: :integer,
14
+ submissions_today: :integer,
15
+ submissions_unread: :integer,
16
+ last_submission_id: :integer,
17
+ last_submission_time: :datetime
18
+
19
+ def parse_fields(fields_array)
20
+ (fields_array || []).map { |fields| FormField.new(fields) }
21
+ end
5
22
  end
6
23
  end
7
24
  end
@@ -1,7 +1,17 @@
1
+ require 'form_stalker/data/base'
1
2
 
2
3
  module FormStalker
3
4
  module Data
4
5
  class FormField < Base
6
+ schema sort: :integer,
7
+ uniq: :boolean,
8
+ hidden: :boolean,
9
+ colspan: :integer,
10
+ required: :boolean,
11
+ readonly: :boolean,
12
+ hide_label: :boolean,
13
+ option_other: :boolean,
14
+ description_callout: :boolean
5
15
  end
6
16
  end
7
17
  end
@@ -0,0 +1,47 @@
1
+ module FormStalker
2
+ module Data
3
+ class Parser
4
+ attr_reader :object, :type_cast_schema, :attributes_before_type_cast
5
+
6
+ def initialize(object, type_cast_schema, attributes)
7
+ @object = object
8
+ @type_cast_schema = type_cast_schema
9
+ @attributes_before_type_cast = attributes.dup
10
+ end
11
+
12
+ def parse_attributes
13
+ attributes = {}
14
+
15
+ attributes_before_type_cast.each do |key, value|
16
+ attributes[key] = parse_attribute key, value
17
+ end
18
+
19
+ attributes
20
+ end
21
+
22
+ def parse_attribute(key, value)
23
+ if object.respond_to?("parse_#{key}")
24
+ return object.send("parse_#{key}", value)
25
+ end
26
+
27
+ return value unless type_cast_schema[key.to_sym]
28
+
29
+ send("sanitize_#{type_cast_schema[key.to_sym]}", value)
30
+ end
31
+
32
+ def sanitize_boolean(value)
33
+ ![false, 0, '0', 'false', 'FALSE'].include?(value)
34
+ end
35
+
36
+ def sanitize_integer(value)
37
+ value.to_i if value.to_s =~ /\A[+-]?\d+\Z/
38
+ end
39
+
40
+ def sanitize_datetime(value)
41
+ DateTime.parse(value)
42
+ rescue
43
+ value
44
+ end
45
+ end
46
+ end
47
+ end
@@ -67,7 +67,7 @@ module FormStalker
67
67
  end
68
68
 
69
69
  def ok?
70
- status == :ok
70
+ status == :ok && (error.nil? || error == '')
71
71
  end
72
72
 
73
73
  protected ######################## PROTECTED ###############################
@@ -1,3 +1,3 @@
1
1
  module FormStalker
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
data/lib/form_stalker.rb CHANGED
@@ -16,4 +16,12 @@ module FormStalker
16
16
  def client
17
17
  @client ||= Client.new(Config.new)
18
18
  end
19
+
20
+ def form(*args)
21
+ client.form(*args)
22
+ end
23
+
24
+ def form_fields(*args)
25
+ client.form_fields(*args)
26
+ end
19
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: form_stalker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - StreetBees Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vcr
@@ -128,17 +128,7 @@ executables: []
128
128
  extensions: []
129
129
  extra_rdoc_files: []
130
130
  files:
131
- - ".gitignore"
132
- - ".rspec"
133
- - ".rubocop.yml"
134
- - ".ruby-version"
135
- - ".travis.yml"
136
- - Gemfile
137
- - Gemfile.lock
138
- - LICENSE
139
131
  - README.md
140
- - Rakefile
141
- - form_stalker.gemspec
142
132
  - lib/form_stalker.rb
143
133
  - lib/form_stalker/client.rb
144
134
  - lib/form_stalker/config.rb
@@ -146,19 +136,10 @@ files:
146
136
  - lib/form_stalker/data/base.rb
147
137
  - lib/form_stalker/data/form.rb
148
138
  - lib/form_stalker/data/form_field.rb
139
+ - lib/form_stalker/data/parser.rb
149
140
  - lib/form_stalker/request.rb
150
141
  - lib/form_stalker/response.rb
151
142
  - lib/form_stalker/version.rb
152
- - spec/fixtures/vcr_cassettes/form_fields_invalid_id.yml
153
- - spec/fixtures/vcr_cassettes/form_fields_valid_id.yml
154
- - spec/fixtures/vcr_cassettes/form_invalid_id.yml
155
- - spec/fixtures/vcr_cassettes/form_valid_id.yml
156
- - spec/fixtures/vcr_cassettes/invalid_oauth_token.yml
157
- - spec/form_stalker/client_spec.rb
158
- - spec/form_stalker/form_stalker_spec.rb
159
- - spec/form_stalker/request_spec.rb
160
- - spec/spec_helper.rb
161
- - spec/support/helpers.rb
162
143
  homepage: https://github.com/streetbees/form-stalker
163
144
  licenses:
164
145
  - MIT
@@ -183,14 +164,4 @@ rubygems_version: 2.5.1
183
164
  signing_key:
184
165
  specification_version: 4
185
166
  summary: FormStack API client that can extract conditional logic
186
- test_files:
187
- - spec/fixtures/vcr_cassettes/form_fields_invalid_id.yml
188
- - spec/fixtures/vcr_cassettes/form_fields_valid_id.yml
189
- - spec/fixtures/vcr_cassettes/form_invalid_id.yml
190
- - spec/fixtures/vcr_cassettes/form_valid_id.yml
191
- - spec/fixtures/vcr_cassettes/invalid_oauth_token.yml
192
- - spec/form_stalker/client_spec.rb
193
- - spec/form_stalker/form_stalker_spec.rb
194
- - spec/form_stalker/request_spec.rb
195
- - spec/spec_helper.rb
196
- - spec/support/helpers.rb
167
+ test_files: []
data/.gitignore DELETED
@@ -1,50 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
-
13
- ## Specific to RubyMotion:
14
- .dat*
15
- .repl_history
16
- build/
17
-
18
- ## Documentation cache and generated files:
19
- /.yardoc/
20
- /_yardoc/
21
- /doc/
22
- /rdoc/
23
-
24
- ## Environment normalization:
25
- /.bundle/
26
- /vendor/bundle
27
- /lib/bundler/man/
28
-
29
- # for a library or gem, you might want to ignore these files since the code is
30
- # intended to run in multiple environments; otherwise, check them in:
31
- # Gemfile.lock
32
- # .ruby-version
33
- .ruby-gemset
34
-
35
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
- .rvmrc
37
-
38
- *.bundle
39
- *.so
40
- *.o
41
- *.a
42
- mkmf.log
43
-
44
- .DS_Store
45
-
46
- # Jetbrains Idea files
47
- .idea/
48
- api.iml
49
-
50
- db/schema.rb
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --tty
2
- --color
3
- --format documentation
4
- --format html -o "tmp/rspec_result.html"
data/.rubocop.yml DELETED
@@ -1,11 +0,0 @@
1
- Style/FrozenStringLiteralComment:
2
- Enabled: false
3
-
4
- AllCops:
5
- DisplayCopNames: true
6
- Exclude:
7
- - 'Gemfile*'
8
- - '*.gemspec'
9
-
10
- Documentation:
11
- Enabled: false
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.3.0
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.3.0
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,79 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- form_stalker (1.0.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- addressable (2.3.8)
10
- ast (2.2.0)
11
- codeclimate-test-reporter (0.4.8)
12
- simplecov (>= 0.7.1, < 1.0.0)
13
- coderay (1.1.1)
14
- crack (0.4.3)
15
- safe_yaml (~> 1.0.0)
16
- diff-lcs (1.2.5)
17
- docile (1.1.5)
18
- hashdiff (0.3.0)
19
- json (1.8.3)
20
- method_source (0.8.2)
21
- parser (2.3.0.6)
22
- ast (~> 2.2)
23
- powerpack (0.1.1)
24
- pry (0.10.3)
25
- coderay (~> 1.1.0)
26
- method_source (~> 0.8.1)
27
- slop (~> 3.4)
28
- rainbow (2.1.0)
29
- rake (11.2.2)
30
- rspec (3.4.0)
31
- rspec-core (~> 3.4.0)
32
- rspec-expectations (~> 3.4.0)
33
- rspec-mocks (~> 3.4.0)
34
- rspec-core (3.4.4)
35
- rspec-support (~> 3.4.0)
36
- rspec-expectations (3.4.0)
37
- diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.4.0)
39
- rspec-mocks (3.4.1)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.4.0)
42
- rspec-support (3.4.1)
43
- rubocop (0.37.2)
44
- parser (>= 2.3.0.4, < 3.0)
45
- powerpack (~> 0.1)
46
- rainbow (>= 1.99.1, < 3.0)
47
- ruby-progressbar (~> 1.7)
48
- unicode-display_width (~> 0.3)
49
- ruby-progressbar (1.7.5)
50
- safe_yaml (1.0.4)
51
- simplecov (0.11.2)
52
- docile (~> 1.1.0)
53
- json (~> 1.8)
54
- simplecov-html (~> 0.10.0)
55
- simplecov-html (0.10.0)
56
- slop (3.6.0)
57
- unicode-display_width (0.3.1)
58
- vcr (3.0.3)
59
- webmock (2.1.0)
60
- addressable (>= 2.3.6)
61
- crack (>= 0.3.2)
62
- hashdiff
63
-
64
- PLATFORMS
65
- ruby
66
-
67
- DEPENDENCIES
68
- codeclimate-test-reporter (= 0.4.8)
69
- form_stalker!
70
- pry (= 0.10.3)
71
- rake (= 11.2.2)
72
- rspec (= 3.4.0)
73
- rubocop (= 0.37.2)
74
- simplecov (= 0.11.2)
75
- vcr (= 3.0.3)
76
- webmock (= 2.1.0)
77
-
78
- BUNDLED WITH
79
- 1.12.5
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require 'bundler/gem_tasks'
2
-
3
- require 'rspec/core/rake_task'
4
- require 'rubocop/rake_task'
5
-
6
- RSpec::Core::RakeTask.new
7
- RuboCop::RakeTask.new
8
-
9
- task(:default).clear
10
- task default: [:rubocop, :spec]
data/form_stalker.gemspec DELETED
@@ -1,30 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
-
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
-
5
- require 'form_stalker/version'
6
-
7
- Gem::Specification.new do |gem|
8
- gem.name = 'form_stalker'
9
- gem.version = FormStalker::VERSION
10
- gem.license = 'MIT'
11
- gem.authors = ['StreetBees Dev Team']
12
- gem.email = 'dev@streetbees.com'
13
- gem.summary = 'FormStack API client that can extract conditional logic'
14
- gem.description = 'Ruby FormStack API gem that can extract conditional logic'
15
- gem.homepage = 'https://github.com/streetbees/form-stalker'
16
-
17
- gem.files = `git ls-files`.split($/)
18
- gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
19
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
- gem.require_paths = ['lib']
21
-
22
- gem.add_development_dependency 'vcr', '3.0.3'
23
- gem.add_development_dependency 'pry', '0.10.3'
24
- gem.add_development_dependency 'rake', '11.2.2'
25
- gem.add_development_dependency 'rspec', '3.4.0'
26
- gem.add_development_dependency 'webmock', '2.1.0'
27
- gem.add_development_dependency 'rubocop', '0.37.2'
28
- gem.add_development_dependency 'simplecov', '0.11.2'
29
- gem.add_development_dependency 'codeclimate-test-reporter', '0.4.8'
30
- end
@@ -1,58 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://www.formstack.com/api/v2/form/-1/field.json?oauth_token=valid_oauth_token
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- Accept-Encoding:
11
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
- Accept:
13
- - "*/*"
14
- User-Agent:
15
- - Ruby
16
- Host:
17
- - www.formstack.com
18
- response:
19
- status:
20
- code: 200
21
- message: OK
22
- headers:
23
- Cache-Control:
24
- - no-cache
25
- Content-Type:
26
- - application/json; charset=UTF-8
27
- Date:
28
- - Fri, 29 Jul 2016 14:12:04 GMT
29
- P3p:
30
- - CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI
31
- DSP COR"
32
- Server:
33
- - nginx
34
- Set-Cookie:
35
- - FormstackAdmin=rb6oq13q19asaln18lrnt9vjf5; path=/api/; secure; HttpOnly
36
- - rgemail=subs%40streetbees.com; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
37
- - rgfirstname=Queen; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
38
- - rgfullname=Bee; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
39
- - rgisanonymous=false; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
40
- - rgisanonymous=false; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
41
- - rgisanonymous=true; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
42
- - rguserid=642682; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
43
- - rguserid=6cddb9b1-409e-4e89-96d7-ff6e41f5d90d; expires=Sun, 28-Aug-2016 14:12:04
44
- GMT; Max-Age=2592000
45
- - rguuid=false; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
46
- - rguuid=true; expires=Sun, 28-Aug-2016 14:12:04 GMT; Max-Age=2592000
47
- X-Robots-Tag:
48
- - noindex, nofollow
49
- Content-Length:
50
- - '61'
51
- Connection:
52
- - keep-alive
53
- body:
54
- encoding: UTF-8
55
- string: '{"status":"error","error":"A valid form id was not supplied"}'
56
- http_version:
57
- recorded_at: Fri, 29 Jul 2016 14:12:04 GMT
58
- recorded_with: VCR 3.0.3