form_stalker 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83d69f88a214755316a6cfa5f014989aabb02d1c
4
+ data.tar.gz: ea5054f20c99e9c0b949a7a521b60560e35b2109
5
+ SHA512:
6
+ metadata.gz: 27ddfab878ab2b2c0e167cd61cb620a83a694c8b44fd56500b939353817770d8b4d5a08d2327c78f34bbf8a09a1189d89897f98665767a5fb05f6a5cab87db3c
7
+ data.tar.gz: e7fdd74b0234a2129cab3c9cf0ea5ba52ee7421e1ae327f6f3770e0f9f3f68bccd209b526362ba00c676c1f36744a850e4cefd6abd2e57be796ed53faa3150b8
data/.gitignore ADDED
@@ -0,0 +1,50 @@
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 ADDED
@@ -0,0 +1,4 @@
1
+ --tty
2
+ --color
3
+ --format documentation
4
+ --format html -o "tmp/rspec_result.html"
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
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 ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,79 @@
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 ADDED
@@ -0,0 +1,21 @@
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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # FormStalker
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:
4
+
5
+ [![Code Climate](https://codeclimate.com/github/Streetbees/form-stalker/badges/gpa.svg)](https://codeclimate.com/github/Streetbees/form-stalker)
6
+ [![Test Coverage](https://codeclimate.com/github/Streetbees/form-stalker/badges/coverage.svg)](https://codeclimate.com/github/Streetbees/form-stalker/coverage)
7
+ [![Build Status](https://travis-ci.org/Streetbees/form-stalker.svg?branch=master)](https://travis-ci.org/Streetbees/form-stalker)
8
+
9
+ ## 1) Usage
10
+ Create an initializer and set your your formstack oauth token.
11
+ ```ruby
12
+ FormStalker.configure do |config|
13
+ config.oauth_token = 'your formstack oauth token'
14
+ end
15
+ ```
16
+
17
+ Make requests to FormStack and receive a sanitized response
18
+ ```ruby
19
+ response = FormStalker.form(1)
20
+
21
+ if response.ok? # or (response.status == :ok)
22
+ form_data = response.data
23
+ else
24
+ response.status # will return a symbol representing FormStack's HTTP status
25
+ response.error # will return a message string explaining the error
26
+ end
27
+ ```
28
+
29
+ ## 2) Instalation
30
+
31
+ Add this to your Gemfile:
32
+ ```
33
+ gem 'form_stalker'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ ```
39
+ $> bundle install
40
+ ```
41
+
42
+ ## 3) F.A.Q.
43
+ wip
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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]
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,19 @@
1
+ require 'form_stalker/version'
2
+ require 'form_stalker/client'
3
+ require 'form_stalker/config'
4
+
5
+ module FormStalker
6
+ module_function
7
+
8
+ def configure
9
+ yield(config)
10
+ end
11
+
12
+ def config
13
+ client.config
14
+ end
15
+
16
+ def client
17
+ @client ||= Client.new(Config.new)
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'form_stalker/data/base'
2
+ require 'form_stalker/data/form'
3
+ require 'form_stalker/data/form_field'
4
+ require 'form_stalker/connection'
5
+ require 'form_stalker/request'
6
+
7
+ module FormStalker
8
+ class Client
9
+ attr_reader :connection
10
+
11
+ def initialize(config_or_options = nil)
12
+ @connection = Connection.new(config_or_options || {})
13
+ end
14
+
15
+ def config
16
+ connection.config
17
+ end
18
+
19
+ def form(form_id)
20
+ Data::Form.tap_into request.get("form/#{form_id}.json")
21
+ end
22
+
23
+ def form_fields(form_id)
24
+ Data::FormField.tap_into request.get("form/#{form_id}/field.json")
25
+ end
26
+
27
+ protected ######################## PROTECTED ###############################
28
+
29
+ def request
30
+ Request.new(connection)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module FormStalker
2
+ class Config
3
+ DEFAULT_VALUES = {
4
+ protocol: 'https',
5
+ base_uri: 'www.formstack.com/api/v2'
6
+ }.freeze
7
+
8
+ attr_accessor :protocol, :base_uri, :oauth_token
9
+
10
+ def initialize(attributes = nil)
11
+ DEFAULT_VALUES.merge(attributes || {}).each do |name, value|
12
+ send("#{name}=", value)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module FormStalker
2
+ class Connection
3
+ attr_reader :config
4
+
5
+ def initialize(config_or_options)
6
+ @config = config_or_options
7
+
8
+ @config = Config.new(@config) if @config.is_a?(Hash)
9
+ end
10
+
11
+ def build_url(path)
12
+ [config.protocol, '://', config.base_uri, '/', path,
13
+ "?oauth_token=#{config.oauth_token}"].join
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module FormStalker
2
+ module Data
3
+ class Base < OpenStruct
4
+ def self.tap_into(response)
5
+ return response unless response.ok?
6
+
7
+ response.data =
8
+ if response.data.is_a?(Array)
9
+ response.data.map { |subset| new(subset) }
10
+ else
11
+ new(response.data)
12
+ end
13
+
14
+ response
15
+ end
16
+
17
+ alias attributes marshal_dump
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+
2
+ module FormStalker
3
+ module Data
4
+ class Form < Base
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+
2
+ module FormStalker
3
+ module Data
4
+ class FormField < Base
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require 'form_stalker/response'
3
+
4
+ module FormStalker
5
+ class Request
6
+ attr_reader :response, :connection
7
+
8
+ def initialize(connection)
9
+ @connection = connection
10
+ end
11
+
12
+ def get(path)
13
+ make_the_call(:get, path)
14
+ end
15
+
16
+ protected ######################## PROTECTED ###############################
17
+
18
+ def make_the_call(http_verb, path)
19
+ uri = URI(connection.build_url(path))
20
+
21
+ http_response = Net::HTTP.send("#{http_verb}_response", uri)
22
+
23
+ @response = Response.new(http_response)
24
+ end
25
+ end
26
+ end