Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Add a /latest JSON endpoint. [#8697731]
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi committed Jan 19, 2011
1 parent 566b767 commit 60f2f82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ def settings
def publisher
@publisher = Publisher.where(:slug => params[:slug]).first
end


def latest
if params[:since_id] == 0
@activities = Activity.any_in(:publisher_ids => params[:following_ids].split(',')).
desc(:_id).
limit(20)
else
@activities = Activity.where(:_id.gt => BSON.ObjectId(params[:since_id])).
any_in(:publisher_ids => params[:following_ids].split(',')).
desc(:_id)
end
render :json => @activities
end

def activity
@activity = Activity.find(params[:id])
end

def comment
@activity = Activity.find(params[:id])
@activity.comments.create(:body => params[:body],
Expand All @@ -31,11 +44,10 @@ def comment
@activity.save
redirect_to :back
end

def user_agent_check
agent = Agent.new request.env["HTTP_USER_AGENT"]
redirect_to chrome_path unless agent.name == :Chrome
end



end
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
match 'auth' => 'sessions#new', :as => :auth
match 'out' => 'sessions#destroy', :as => :out

match 'latest' => 'main#latest', :as => :latest
match 's/:slug' => 'main#publisher', :as => :publisher
match 'a/:id' => 'main#activity', :as => :activity
match 'a/:id/comment' => 'main#comment', :as => :comment

resource :session

end

0 comments on commit 60f2f82

Please sign in to comment.