waitress-core 0.3.0 → 0.4.0
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/waitress.rb +1 -0
- data/lib/waitress/restful/restbuilder.rb +79 -0
- data/lib/waitress/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5fa1729728798da3d7a4ec0949db1a3fe2deae3
|
4
|
+
data.tar.gz: 667594fb143c6d05c2ce4b158f3b35eb388aadf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83b1ecfba256a594a6e99b7610656257dfdb83445f889ab907e952c3757c7745e447da388e8be16335f62d483f1c88c013d2c306b23be2f1335b0b762654ed3a
|
7
|
+
data.tar.gz: 2fe5debcbbc9770416491d0a876d5190e7d6ab802858ed10654dac67b9f033d327d24fe32be8612e2954433a88704dc9cfee05e09e03acbb3c3259d136a9f52c
|
data/lib/waitress.rb
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Waitress
|
2
|
+
class REST < Handler
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'scon'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
attr_accessor :priority
|
9
|
+
|
10
|
+
SUPPORTED_FORMATS = [:json, :scon, :yaml, :yml]
|
11
|
+
|
12
|
+
def self.build! schema, &call
|
13
|
+
pattern = /:([^\/:\?\[]+)(\?)?(\[[a-zA-Z0-9\-_\s,]+\])?\//
|
14
|
+
|
15
|
+
a = schema.gsub(pattern) do |match|
|
16
|
+
capture_name = $1
|
17
|
+
optional = ($2 == "?")
|
18
|
+
enumerations = nil
|
19
|
+
enumerations = $3.gsub(/\[|\]/, "").split(/,\s?/) unless $3.nil?
|
20
|
+
buildRe = "(?<#{capture_name}>"
|
21
|
+
if enumerations.nil?
|
22
|
+
buildRe << "[^\\/]+"
|
23
|
+
else
|
24
|
+
buildRe << enumerations.join("|")
|
25
|
+
end
|
26
|
+
buildRe << ")"
|
27
|
+
buildRe << "?" if optional
|
28
|
+
buildRe << "/"
|
29
|
+
buildRe << "?" if optional
|
30
|
+
|
31
|
+
buildRe
|
32
|
+
end
|
33
|
+
|
34
|
+
Waitress::REST.new(Regexp.new(a), &call)
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize regex, &call
|
38
|
+
@regex = regex
|
39
|
+
@call = call
|
40
|
+
@priority = 200
|
41
|
+
end
|
42
|
+
|
43
|
+
def respond? request, vhost
|
44
|
+
(request.uri =~ @regex) != nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def encode_format content_hash, request, response, type
|
48
|
+
ret = ""
|
49
|
+
if type == :json
|
50
|
+
if request.get_query.include? "pretty"
|
51
|
+
ret = JSON.pretty_generate(content_hash)
|
52
|
+
else
|
53
|
+
ret = JSON.generate(content_hash)
|
54
|
+
end
|
55
|
+
elsif type == :scon
|
56
|
+
ret = SCON.generate!(content_hash)
|
57
|
+
elsif type == :yaml || type == :yml
|
58
|
+
ret = content_hash.to_yaml
|
59
|
+
end
|
60
|
+
ret
|
61
|
+
end
|
62
|
+
|
63
|
+
def serve request, response, client, vhost
|
64
|
+
match = request.uri.match @regex
|
65
|
+
|
66
|
+
form = :json
|
67
|
+
if (request.get_query.include? "format")
|
68
|
+
val = request.get_query["format"].downcase.to_sym
|
69
|
+
form = val if SUPPORTED_FORMATS.include?(val)
|
70
|
+
end
|
71
|
+
|
72
|
+
response.mime ".#{form.to_s}"
|
73
|
+
|
74
|
+
content_hash = @call.call(match, request, response, vhost)
|
75
|
+
response.body encode_format(content_hash, request, response, form)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
data/lib/waitress/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waitress-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaci Brunning
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- lib/waitress/resources/http/img/404.png
|
227
227
|
- lib/waitress/resources/http/index.html
|
228
228
|
- lib/waitress/response.rb
|
229
|
+
- lib/waitress/restful/restbuilder.rb
|
229
230
|
- lib/waitress/server.rb
|
230
231
|
- lib/waitress/util/less_watcher.rb
|
231
232
|
- lib/waitress/util/util.rb
|