lib/micropub/server/rails/middleware.rb in micropub-server-rails-0.1.3 vs lib/micropub/server/rails/middleware.rb in micropub-server-rails-0.1.4

- old
+ new

@@ -11,47 +11,37 @@ def initialize(app) @app = app end def call(env) - @env = env if env["PATH_INFO"] == "/micropub" - token = Micropub::Token.new(auth_token) + token = Micropub::Token.new(auth_token(env)) + puts token.inspect if token.valid? response else error_response end else @app.call env end end - def env - @env + def auth_token(env) + input = env["HTTP_AUTHORIZATION"] || request(env).params[:access_token] || "" + input.split("Bearer ").last end - def auth_token - @auth_token ||= begin - input = env["HTTP_AUTHORIZATION"] || params[:access_token] || "" - input.split("Bearer ").last - end - end - def response [201, headers, ["I am micropub."]] end def error_response [401, {}, [""]] end - def request - @request ||= Rack::Request.new(env) - end - - def params - request.params + def request(env) + Rack::Request.new(env) end def headers { "Location" => "http://bookisworthy.com/posts/1",