Browse files

pass current user down to the model when fetching statuses

  • Loading branch information...
1 parent 5c85b6a commit 9df30e9b412388a8b07a8902e36965a0ba6b1d8f @mislav committed Nov 29, 2010
Showing with 8 additions and 4 deletions.
  1. +6 −2 lib/twin.rb
  2. +1 −1 lib/twin/resources.rb
  3. +1 −1 test/app.rb
View
8 lib/twin.rb
@@ -41,9 +41,9 @@ def call(env)
if path != '/' and found = recognize_resource(path)
block, matches = found
- # TODO: bail out early if authentication failed
twin_token = env[AUTHORIZATION] =~ / oauth_token="(.+?)"/ && $1
authenticated_user = twin_token && model.find_by_twin_token(twin_token)
+ return not_authenticated if twin_token and not authenticated_user
clone = self.dup
clone.request = Rack::Request.new env
@@ -85,7 +85,7 @@ def perform(block)
}
# later sent back as: oauth_token="..."
else
- [400, {'Content-Type' => 'text/plain'}, ['Bad credentials']]
+ not_authenticated
end
end
@@ -126,6 +126,10 @@ def not_implemented
[501, {'Content-Type' => 'text/plain'}, ['Not implemented']]
end
+ def not_authenticated
+ [400, {'Content-Type' => 'text/plain'}, ['Not authenticated']]
+ end
+
def normalize_statuses(statuses)
statuses.map do |status|
hash = convert_twin_hash(status)
View
2 lib/twin/resources.rb
@@ -1,6 +1,6 @@
class Twin
resource 'statuses/home_timeline' do
- statuses = self.model.statuses(params.with_indifferent_access)
+ statuses = self.model.statuses(params.with_indifferent_access, current_user)
respond_with('statuses', normalize_statuses(statuses))
end
View
2 test/app.rb
@@ -28,7 +28,7 @@ def self.twin_token(user)
user[:email]
end
- def self.statuses(params)
+ def self.statuses(params, current_user)
STATUSES
end

0 comments on commit 9df30e9

Please sign in to comment.