Permalink
Browse files

Oversight in feed api

  • Loading branch information...
1 parent 987eab0 commit 6afb87b0a3d114abac6ce4775d11acf39c8dddb1 @mattyoho mattyoho committed May 15, 2012
View
21 app/controllers/api/feed_items_controller.rb
@@ -1,22 +1,6 @@
module Api
class FeedItemsController < ApiController
- def all
- @feed_items = FeedItem.last_first(params[:page])
-
- last_page = FeedItem.items_page_count(10)
- next_page = [(params[:page] || 1).to_i + 1, last_page].min
-
- next_url = api_feed_items_url(page: next_page)
- last_url = api_feed_items_url(page: last_page)
- link_header = construct_link_header(next_url, last_url)
-
- respond_to do |format|
- headers["Link"] = link_header
- format.json
- end
- end
-
def index
feed = Feed.find_by_name!(params[:feed_id])
@feed_items = feed.feed_items.last_first(params[:page])
@@ -62,11 +46,6 @@ def update
end
end
- private
-
- def construct_link_header(next_url, last_url)
- "<#{next_url}>; rel=\"next\", <#{last_url}>; rel=\"last\""
- end
end
end
View
17 app/controllers/api/feeds_controller.rb
@@ -9,6 +9,23 @@ def show
end
end
+ def items
+ @feed_items = FeedItem.last_first(params[:page])
+
+ last_page = FeedItem.items_page_count(10)
+ next_page = [(params[:page] || 1).to_i + 1, last_page].min
+
+ next_url = api_feed_items_url(page: next_page)
+ last_url = api_feed_items_url(page: last_page)
+ link_header = construct_link_header(next_url, last_url)
+
+ respond_to do |format|
+ headers["Link"] = link_header
+ format.json
+ end
+ end
+
+
end
end
View
6 app/controllers/api_controller.rb
@@ -1,3 +1,9 @@
class ApiController < ActionController::Base
+ private
+
+ def construct_link_header(next_url, last_url)
+ "<#{next_url}>; rel=\"next\", <#{last_url}>; rel=\"last\""
+ end
+
end
View
18 app/views/api/feeds/items.json.jbuilder
@@ -0,0 +1,18 @@
+json.array!(@feed_items) do |json, item|
+ json.type item.type
+ json.image_url item.image_url if item.image_url.present?
+ json.link_url item.link_url if item.link_url.present?
+ json.text item.body
+ json.(item, :id, :created_at)
+ json.link api_feed_feed_item_url(item.feed, item, format: :json)
+ json.feed do |json|
+ json.link api_feed_url(item.feed, format: :json)
+ json.name item.feed.name
+ end
+ json.user do |json|
+ json.username item.feed.user.username
+ json.email item.feed.user.email
+ json.gravatar item.feed.user.gravatar
+ end
+end
+

0 comments on commit 6afb87b

Please sign in to comment.