api: support the expiry param on all GET requests.
This commit is contained in:
@@ -44,7 +44,6 @@ class ArtistsController < ApplicationController
|
|||||||
end
|
end
|
||||||
format.json do
|
format.json do
|
||||||
render :json => @artists.to_json(:include => [:urls])
|
render :json => @artists.to_json(:include => [:urls])
|
||||||
expires_in params[:expiry].to_i.days if params[:expiry]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,12 +18,7 @@ class PoolsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@pools = Pool.includes(:creator).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
@pools = Pool.includes(:creator).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||||
respond_with(@pools) do |format|
|
respond_with(@pools)
|
||||||
format.json do
|
|
||||||
render json: @pools.to_json
|
|
||||||
expires_in params[:expiry].to_i.days if params[:expiry]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def gallery
|
def gallery
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ class TagsController < ApplicationController
|
|||||||
@tags = Tag.names_matches_with_aliases(params[:search][:name_matches])
|
@tags = Tag.names_matches_with_aliases(params[:search][:name_matches])
|
||||||
end
|
end
|
||||||
|
|
||||||
expires_in params[:expiry].to_i.days if params[:expiry]
|
|
||||||
|
|
||||||
respond_with(@tags, root: "tags")
|
respond_with(@tags, root: "tags")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -30,12 +30,7 @@ class UsersController < ApplicationController
|
|||||||
redirect_to user_path(@user)
|
redirect_to user_path(@user)
|
||||||
else
|
else
|
||||||
@users = User.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
@users = User.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||||
respond_with(@users) do |format|
|
respond_with(@users)
|
||||||
format.json do
|
|
||||||
render json: @users.to_json
|
|
||||||
expires_in params[:expiry].to_i.days if params[:expiry]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ class WikiPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
format.json do
|
|
||||||
render json: @wiki_pages.to_json
|
|
||||||
expires_in params[:expiry].to_i.days if params[:expiry]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
class ApplicationResponder < ActionController::Responder
|
class ApplicationResponder < ActionController::Responder
|
||||||
# this is called by respond_with for non-html, non-js responses.
|
# this is called by respond_with for non-html, non-js responses.
|
||||||
def to_format
|
def to_format
|
||||||
|
if get?
|
||||||
|
expiry = request.params["expiry"]
|
||||||
|
controller.expires_in expiry.to_i.days if expiry.present?
|
||||||
|
end
|
||||||
|
|
||||||
if format == :xml
|
if format == :xml
|
||||||
options[:root] ||= resource.table_name.dasherize if resource.respond_to?(:table_name)
|
options[:root] ||= resource.table_name.dasherize if resource.respond_to?(:table_name)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -192,6 +192,13 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal(tags.first.id, response.parsed_body.first.fetch("id"))
|
assert_equal(tags.first.id, response.parsed_body.first.fetch("id"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "support the expiry parameter" do
|
||||||
|
get posts_path, as: :json, params: { expiry: "1" }
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_equal("max-age=#{1.day}, private", response.headers["Cache-Control"])
|
||||||
|
end
|
||||||
|
|
||||||
should "return the correct root element name for empty xml responses" do
|
should "return the correct root element name for empty xml responses" do
|
||||||
get tags_path, as: :xml
|
get tags_path, as: :xml
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user