form_bridge 0.0.1.alpha1 → 0.0.1.alpha2
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 +4 -4
- data/README.md +3 -35
- data/bin/form-bridge +1 -1
- data/lib/form_bridge/cli.rb +11 -3
- data/lib/form_bridge/endpoint/forms/new.rb +46 -3
- data/lib/form_bridge/endpoint/submissions/create.rb +5 -1
- data/lib/form_bridge/handler.rb +10 -2
- data/lib/form_bridge/models/submission.rb +0 -3
- data/lib/form_bridge/persistance.rb +10 -0
- data/lib/form_bridge/version.rb +1 -1
- data/lib/form_bridge.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a52ab854d71bfeab3745034b384f5c4d4010abd
|
4
|
+
data.tar.gz: d2197819f04c1ed57a078bf90dadd05701a51097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44120dc2bed757d7aae9654356a73512421c7d2ea2538cc1a89526831a68313175a4904b787112f5d82d7bffba73ba99f342795de3e4a4b737d8bd03f5904aa8
|
7
|
+
data.tar.gz: f083d57c256251af7a6fa2bee613cec2a3c5c57cc88286858fae59230bf9cdf300ab2c314c26f67cf23707b5726ed1cd87267283b204bdb3139c0ad54af69e2e
|
data/README.md
CHANGED
@@ -1,39 +1,7 @@
|
|
1
1
|
# FormBridge
|
2
2
|
|
3
|
-
|
3
|
+
`bin/form-bridge -d /path/to/database.db -p 8080`
|
4
4
|
|
5
|
-
|
5
|
+
## run in development ##
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'form_bridge'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install form_bridge
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
1. Fork it ( https://github.com/[my-github-username]/form_bridge/fork )
|
36
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
-
5. Create a new Pull Request
|
7
|
+
`ruby -Ilib bin/form-bridge -d /tmp/form-bridge-dev.db -p 8080`
|
data/bin/form-bridge
CHANGED
data/lib/form_bridge/cli.rb
CHANGED
@@ -3,18 +3,26 @@ module FormBridge
|
|
3
3
|
attr_accessor :options
|
4
4
|
|
5
5
|
def initialize(args)
|
6
|
-
self.options = {logger: Logger.new(STDOUT)}
|
6
|
+
self.options = {logger: Logger.new(STDOUT), port: 8080, host: 'localhost'}
|
7
7
|
|
8
8
|
OptionParser.new do |parser|
|
9
9
|
parser.banner = [
|
10
|
-
"Usage: #{@name} -
|
10
|
+
"Usage: #{@name} -d /tmp/database.db\n",
|
11
11
|
" #{@name} --help\n"
|
12
12
|
].compact.join
|
13
13
|
|
14
|
-
parser.on('-
|
14
|
+
parser.on('-d', '--database PATH') do |path|
|
15
15
|
self.options[:db] = FormBridge::Persistance.new(GDBM.new(path))
|
16
16
|
end
|
17
17
|
|
18
|
+
parser.on('-h', '--host HOST') do |host|
|
19
|
+
self.options[:host] = host
|
20
|
+
end
|
21
|
+
|
22
|
+
parser.on('-p', '--port PORT') do |port|
|
23
|
+
self.options[:port] = port
|
24
|
+
end
|
25
|
+
|
18
26
|
parser.on_tail("-?", "--help", "Display this usage information.") do
|
19
27
|
puts "#{parser}\n"
|
20
28
|
exit
|
@@ -2,18 +2,61 @@ module FormBridge
|
|
2
2
|
module Endpoint
|
3
3
|
module Forms
|
4
4
|
class New
|
5
|
+
INSTRUCTIONS = [
|
6
|
+
"Save this information!",
|
7
|
+
"Keep the private id and form url to yourself,",
|
8
|
+
"it accesses all the data submitted to the submission_url.",
|
9
|
+
"Use the submission_url for your form."
|
10
|
+
].join(' ')
|
11
|
+
|
5
12
|
def initialize(database)
|
6
13
|
@database = database
|
7
14
|
end
|
8
15
|
|
9
16
|
def call(request)
|
10
|
-
# make a securerandom
|
11
|
-
# display URL
|
17
|
+
# make a pair of securerandom uuids, public and private
|
18
|
+
# display URL for submissions
|
12
19
|
# display instructions
|
13
20
|
form = Form.new(@database)
|
14
21
|
form.save
|
15
22
|
|
16
|
-
|
23
|
+
# map public_id to form id (private)
|
24
|
+
public_id = SecureRandom.uuid
|
25
|
+
@database.map(public_id, form.id)
|
26
|
+
|
27
|
+
response = response_hash(public_id, form.id, base_uri_for(request))
|
28
|
+
|
29
|
+
[200, {"Content-Type" => "application/json"}, [JSON.dump(response)]]
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_uri_for(request)
|
33
|
+
URI(request.url).tap do |uri|
|
34
|
+
uri.path = ''
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def response_hash(public_id, private_id, base_uri)
|
39
|
+
submission_url = base_uri.dup.tap do |uri|
|
40
|
+
uri.path = '/submissions'
|
41
|
+
uri.query = URI.encode_www_form(form_id: public_id)
|
42
|
+
end
|
43
|
+
|
44
|
+
form_url = base_uri.dup.tap do |uri|
|
45
|
+
uri.path = '/forms'
|
46
|
+
uri.query = URI.encode_www_form(id: private_id)
|
47
|
+
end
|
48
|
+
|
49
|
+
{
|
50
|
+
private_id: private_id,
|
51
|
+
public_id: public_id,
|
52
|
+
submission_url: submission_url,
|
53
|
+
form_url: form_url,
|
54
|
+
instructions: instructions
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def instructions
|
59
|
+
INSTRUCTIONS
|
17
60
|
end
|
18
61
|
end
|
19
62
|
end
|
@@ -8,13 +8,17 @@ module FormBridge
|
|
8
8
|
|
9
9
|
def call(request)
|
10
10
|
location = request.params["_next"]
|
11
|
-
form =
|
11
|
+
form = form_for(request.params["form_id"])
|
12
12
|
|
13
13
|
form.submissions << Submission.from_params(request.params)
|
14
14
|
form.save
|
15
15
|
|
16
16
|
[302, {"Location" => location}, []]
|
17
17
|
end
|
18
|
+
|
19
|
+
def form_for(public_id)
|
20
|
+
@database.get(@database.lookup(public_id))
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
data/lib/form_bridge/handler.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
module FormBridge
|
2
2
|
class Handler
|
3
|
-
def initialize(app)
|
3
|
+
def initialize(options, app)
|
4
|
+
@options = options
|
4
5
|
@app = app
|
5
6
|
end
|
6
7
|
|
8
|
+
def puma_options
|
9
|
+
{
|
10
|
+
:Port => @options[:port],
|
11
|
+
:Host => @options[:host]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
7
15
|
def run
|
8
|
-
Rack::Handler::Puma.run @app
|
16
|
+
Rack::Handler::Puma.run @app, puma_options
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
@@ -12,6 +12,16 @@ module FormBridge
|
|
12
12
|
Form.from_persistance(self, JSON.load(raw(id)))
|
13
13
|
end
|
14
14
|
|
15
|
+
# the form id is kept private for accessing data
|
16
|
+
# so we map a public id for submission creation
|
17
|
+
def map(public_id, private_id)
|
18
|
+
@database["map:"+public_id.to_s] = private_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def lookup(public_id)
|
22
|
+
@database["map:"+public_id.to_s]
|
23
|
+
end
|
24
|
+
|
15
25
|
private
|
16
26
|
def raw(id)
|
17
27
|
@database[Form.key_for(id)]
|
data/lib/form_bridge/version.rb
CHANGED
data/lib/form_bridge.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "form_bridge/version"
|
2
2
|
require "logger"
|
3
|
+
require "uri"
|
3
4
|
require "optparse"
|
4
5
|
require "securerandom"
|
5
6
|
require "json"
|
@@ -9,7 +10,7 @@ require "rack/handler/puma"
|
|
9
10
|
|
10
11
|
module FormBridge
|
11
12
|
module_function def map(options, &block)
|
12
|
-
FormBridge::Handler.new(FormBridge::Router.build(options, &block))
|
13
|
+
FormBridge::Handler.new(options, FormBridge::Router.build(options, &block))
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: form_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|