oxy 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 +4 -4
- data/lib/oxy.rb +3 -1
- data/lib/oxy/google_contact.rb +6 -0
- data/lib/oxy/middleware/rsvp.rb +39 -0
- data/lib/oxy/server.rb +29 -9
- data/lib/oxy/version.rb +2 -2
- data/oxy.gemspec +3 -0
- metadata +47 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a7625f338127548d91d41d4e8b764a6e3a1014
|
4
|
+
data.tar.gz: e89478f9b9d9c9d4d3fc3edea133212c0a403151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a17585335722e4519d79197fe7856bcc6b2a099b7fb836cf20797b94d8a63fb57e61bd288d5e1c32778aac2ca7102200719b32d6950559f0f8fb15dc7a3f76ee
|
7
|
+
data.tar.gz: 6c01096e3f53919248603bdf4c8f1ab69164729883fa288a23431224f415fe6a9659f7ed1d2cac9d6431553e16ea78ecc30ee320af533e953c794d023ce09aa9
|
data/lib/oxy.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "threaded"
|
2
|
+
|
3
|
+
# RSVP middleware to transform 'RSVP' requests into corresponding
|
4
|
+
# contacts in your Google Contacts via Google People API.
|
5
|
+
class Oxy::RSVP
|
6
|
+
# The set of allowed fields. Requests that do not have fields
|
7
|
+
# present in this list will not be eligible to be enqueued.
|
8
|
+
ELIGIBLE_FORMS_FIELDS = ['email_address']
|
9
|
+
|
10
|
+
# ctor.
|
11
|
+
def initialize(app, logger = $stderr)
|
12
|
+
@app = app
|
13
|
+
@logger = logger
|
14
|
+
end
|
15
|
+
|
16
|
+
# Middleware's entry point
|
17
|
+
def call(env)
|
18
|
+
# instantiate the request object
|
19
|
+
req = Rack::Request.new(env)
|
20
|
+
if req.path == "/rsvp" && req.post? && valid_form(req.POST)
|
21
|
+
# enqueue the new registration request
|
22
|
+
Threaded.enqueue(GoogleContact, req.POST["email_address"], @logger)
|
23
|
+
# redirect
|
24
|
+
[302, { "Location" => "/thank-you" }, []]
|
25
|
+
else
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
# only request with eligible form fields are valid
|
32
|
+
def valid_form(form)
|
33
|
+
unless ELIGIBLE_FORMS_FIELDS.all? { |field| form.include?(field) }
|
34
|
+
@logger.write("[RSVP]: Received an invalid form ~> #{form.inspect}\n")
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
return true
|
38
|
+
end
|
39
|
+
end
|
data/lib/oxy/server.rb
CHANGED
@@ -6,7 +6,7 @@ require "fileutils"
|
|
6
6
|
|
7
7
|
module Oxy
|
8
8
|
class Server
|
9
|
-
attr_accessor :options
|
9
|
+
attr_accessor :options, :status
|
10
10
|
|
11
11
|
attr_reader :stdout
|
12
12
|
|
@@ -35,13 +35,17 @@ module Oxy
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def static_site_app
|
38
|
-
# pin
|
39
|
-
|
38
|
+
# pin options and logger
|
39
|
+
options, logger = @options, @stdout
|
40
40
|
# pin not_found_path file path
|
41
|
-
not_found_path = File.join(
|
41
|
+
not_found_path = File.join(options.document_root, "404.html")
|
42
42
|
# build new app
|
43
43
|
stack = Rack::Builder.new {
|
44
|
-
|
44
|
+
# middleware to handle RSVP features
|
45
|
+
use Oxy::RSVP, logger if options.rsvp
|
46
|
+
# middleware to handle static resources
|
47
|
+
use Rack::TryStatic, :root => options.document_root, :urls => %w[/], :try => [".html", "index.html", "/index.html"]
|
48
|
+
# fallback to 404 middleware as the main application
|
45
49
|
run Rack::NotFound.new(not_found_path)
|
46
50
|
}
|
47
51
|
return stack.to_app
|
@@ -51,12 +55,14 @@ module Oxy
|
|
51
55
|
# instantiate our Rack server
|
52
56
|
@server = Rack::Server.new({
|
53
57
|
:app => static_site_app,
|
54
|
-
:pid => File.join(oxy_home_path,"oxy.pid"),
|
58
|
+
:pid => File.join(oxy_home_path, "oxy.pid"),
|
55
59
|
:Port => @options.port,
|
56
60
|
:Host => @options.address,
|
57
|
-
:environment =>
|
58
|
-
:server =>
|
59
|
-
:daemonize => false
|
61
|
+
:environment => "deployment",
|
62
|
+
:server => "puma",
|
63
|
+
:daemonize => false,
|
64
|
+
:quiet => @options.quiet,
|
65
|
+
:directory => @options.document_root
|
60
66
|
})
|
61
67
|
# spin the server
|
62
68
|
Thread.new { @server.start }
|
@@ -69,6 +75,8 @@ module Oxy
|
|
69
75
|
# set option defaults
|
70
76
|
@options.document_root = Dir.pwd unless @options.document_root
|
71
77
|
@options.port = 4000 unless @options.port
|
78
|
+
@options.quiet = false unless @options.quiet
|
79
|
+
@options.rsvp = false unless @options.rsvp
|
72
80
|
rescue OptionParser::ParseError => pe
|
73
81
|
msg = ["#{@parser.program_name}: #{pe}", "Try `#{@parser.program_name} --help` for more information"]
|
74
82
|
@options.error_message = msg.join("\n")
|
@@ -109,6 +117,18 @@ module Oxy
|
|
109
117
|
op.on("-p", "--port PORT", Integer, "Define the TCP port to bind to", "Use -b for more advanced options") do |port|
|
110
118
|
@options.port = port
|
111
119
|
end
|
120
|
+
# parse document root
|
121
|
+
op.on("--directory PATH", "PATH to serve files from") do |path|
|
122
|
+
@options.document_root = path
|
123
|
+
end
|
124
|
+
# parse quiet mode
|
125
|
+
op.on("--quiet", "Do not display any logs to STDOUT") do
|
126
|
+
@options.quiet = true
|
127
|
+
end
|
128
|
+
# parse rsvp middleware option
|
129
|
+
op.on("--rsvp", "Enable RSVP middleware to handle form submissions") do
|
130
|
+
@options.rsvp = true
|
131
|
+
end
|
112
132
|
end
|
113
133
|
end
|
114
134
|
end
|
data/lib/oxy/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Oxy
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
2
|
+
VERSION = "0.1.4"
|
3
|
+
end
|
data/oxy.gemspec
CHANGED
@@ -22,10 +22,13 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "rack", "~> 2.0"
|
23
23
|
spec.add_runtime_dependency "rack-contrib", "~> 1.2"
|
24
24
|
spec.add_runtime_dependency "puma", "~> 3.10"
|
25
|
+
spec.add_runtime_dependency "threaded", "~> 0.0.4"
|
25
26
|
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.15"
|
27
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
29
|
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
spec.add_development_dependency "httparty"
|
31
|
+
spec.add_development_dependency "rack-test"
|
29
32
|
|
30
33
|
spec.add_development_dependency "pry"
|
31
34
|
spec.add_development_dependency "pry-byebug"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxy
|
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
|
- Pavel Tsurbeleu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: threaded
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.4
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,34 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '5.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: httparty
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rack-test
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: pry
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,6 +225,8 @@ files:
|
|
183
225
|
- bin/oxy
|
184
226
|
- bin/setup
|
185
227
|
- lib/oxy.rb
|
228
|
+
- lib/oxy/google_contact.rb
|
229
|
+
- lib/oxy/middleware/rsvp.rb
|
186
230
|
- lib/oxy/server.rb
|
187
231
|
- lib/oxy/version.rb
|
188
232
|
- oxy.gemspec
|
@@ -206,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
250
|
version: '0'
|
207
251
|
requirements: []
|
208
252
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.6.
|
253
|
+
rubygems_version: 2.6.14
|
210
254
|
signing_key:
|
211
255
|
specification_version: 4
|
212
256
|
summary: Oxy is a web server for static sites
|