sinatra-restful 0.0.4 → 0.0.5
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/sinatra/restful.rb +52 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efb7107c1e7d9aa0e512fe1e3f471952f06e6eb6
|
4
|
+
data.tar.gz: f811ec3abd304ece145f1253083dc8fe784e591c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3118601f440923f1d3d90f4aba93163d9e48dd4faf841c102178026d34d78d872a78e773b9153e8ed23e3b5a1446a6d6c4b34d176ab99bfe4ef225e15f7a6a42
|
7
|
+
data.tar.gz: ee2816f57b8de900ecbedcf74606c425ccbe0881f7b9bfda78501a4b7249cb191cc30fd4b3a8688dd1378faeff4610086127b4d4dc79926982de0bea21a394fb
|
data/lib/sinatra/restful.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'zlib'
|
2
3
|
require 'rack/deflater'
|
3
4
|
require 'rack/throttle'
|
@@ -65,6 +66,48 @@ module Sinatra
|
|
65
66
|
class Compress < Rack::Deflater
|
66
67
|
end
|
67
68
|
|
69
|
+
module OAuth2
|
70
|
+
class Bearer
|
71
|
+
def initialize(app, &authenticator)
|
72
|
+
@app, @authenticator = app, authenticator
|
73
|
+
end
|
74
|
+
|
75
|
+
def unauthorized
|
76
|
+
[401, {}, []]
|
77
|
+
end
|
78
|
+
|
79
|
+
def valid?(auth)
|
80
|
+
parts = auth.authorization.split(' ', 2)
|
81
|
+
if parts[0] == 'Bearer'
|
82
|
+
@authenticator.call(parts[1])
|
83
|
+
elsif parts[0] == 'MAC'
|
84
|
+
# Not implemented
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def call(env)
|
89
|
+
auth = Request.new(env)
|
90
|
+
return unauthorized unless auth.provided?
|
91
|
+
|
92
|
+
if valid?(auth)
|
93
|
+
return @app.call(env)
|
94
|
+
end
|
95
|
+
|
96
|
+
unauthorized
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Request < Rack::Request
|
101
|
+
def authorization
|
102
|
+
@env['HTTP_AUTHORIZATION']
|
103
|
+
end
|
104
|
+
|
105
|
+
def provided?
|
106
|
+
@env.has_key?('HTTP_AUTHORIZATION')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
68
111
|
def self.registered(app)
|
69
112
|
# Condition for matching Accept-Encoding
|
70
113
|
def accept_encoding(type, version = nil)
|
@@ -107,6 +150,15 @@ module Sinatra
|
|
107
150
|
# Encode the response as json
|
108
151
|
app.after do
|
109
152
|
content_type :json
|
153
|
+
puts "After"
|
154
|
+
puts body
|
155
|
+
begin
|
156
|
+
puts(JSON.generate(body))
|
157
|
+
rescue Exception => e
|
158
|
+
p e
|
159
|
+
puts "Oops"
|
160
|
+
end
|
161
|
+
puts "asdf"
|
110
162
|
body JSON.generate(body)
|
111
163
|
end
|
112
164
|
end
|