sinatra-restful 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sinatra/restful.rb +52 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e7aa97f75b72ab6e1b8fd02953a9b5d842ce3ea
4
- data.tar.gz: 1b89cec7689184d28c4a6824f12b0ed8b2c0a340
3
+ metadata.gz: efb7107c1e7d9aa0e512fe1e3f471952f06e6eb6
4
+ data.tar.gz: f811ec3abd304ece145f1253083dc8fe784e591c
5
5
  SHA512:
6
- metadata.gz: fe441e2db76d8c54ff8f4649c65a3411ada1479fde51dd0e007895942b9f680b1b04a3bb281bab505a0dc323247dab8f6e410b94c2963c97ac55f8ab5e8f7eb5
7
- data.tar.gz: b8b073148415871336656a33c44bf36044cd2463ca1bc2f93dab9314ab4abbacadbb03cd79eefdc15fddd35e705c1c04c91c015103a54251b730054a7e619f02
6
+ metadata.gz: 3118601f440923f1d3d90f4aba93163d9e48dd4faf841c102178026d34d78d872a78e773b9153e8ed23e3b5a1446a6d6c4b34d176ab99bfe4ef225e15f7a6a42
7
+ data.tar.gz: ee2816f57b8de900ecbedcf74606c425ccbe0881f7b9bfda78501a4b7249cb191cc30fd4b3a8688dd1378faeff4610086127b4d4dc79926982de0bea21a394fb
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-restful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamal Fanaian