app/controllers/locomotive/api/pages_controller.rb in locomotive_cms-2.0.0.rc12 vs app/controllers/locomotive/api/pages_controller.rb in locomotive_cms-2.0.0
- old
+ new
@@ -1,35 +1,82 @@
module Locomotive
module Api
class PagesController < BaseController
- load_and_authorize_resource :class => Locomotive::Page
+ load_and_authorize_resource class: Locomotive::Page, through: :current_site
def index
- @pages = current_site.pages.order_by([[:depth, :asc], [:position, :asc]])
+ @pages = @pages.order_by([[:depth, :asc], [:position, :asc]])
respond_with(@pages)
end
def show
- @page = current_site.pages.find(params[:id])
respond_with(@page)
end
def create
- @page = current_site.pages.create(params[:page])
- respond_with @page, :location => main_app.locomotive_api_pages_url
+ @page.from_presenter(params[:page])
+ @page.save
+ respond_with @page, location: main_app.locomotive_api_pages_url
end
def update
- @page = current_site.pages.find(params[:id])
- @page.update_attributes(params[:page])
- respond_with @page, :location => main_app.locomotive_api_pages_url
+ @page.from_presenter(params[:page])
+ @page.save
+ respond_with @page, location: main_app.locomotive_api_pages_url
end
def destroy
- @page = current_site.pages.find(params[:id])
@page.destroy
respond_with @page
+ end
+
+ protected
+
+ def self.description
+ {
+ overall: %{Manage the pages},
+ actions: {
+ index: {
+ description: %{Return all the pages ordered by the depth and position},
+ example: {
+ command: %{curl 'http://mysite.com/locomotive/api/pages.json?auth_token=dtsjkqs1TJrWiSiJt2gg'},
+ response: %(TODO)
+ }
+ },
+ show: {
+ description: %{Return the attributes of a page},
+ response: Locomotive::PagePresenter.getters_to_hash,
+ example: {
+ command: %{curl 'http://mysite.com/locomotive/api/pages/4244af4ef0000002.json?auth_token=dtsjkqs1TJrWiSiJt2gg'},
+ response: %(TODO)
+ }
+ },
+ create: {
+ description: %{Create a page},
+ params: Locomotive::PagePresenter.setters_to_hash,
+ example: {
+ command: %{curl -d '...' 'http://mysite.com/locomotive/api/pages.json?auth_token=dtsjkqs1TJrWiSiJt2gg'},
+ response: %(TODO)
+ }
+ },
+ update: {
+ description: %{Update a page},
+ params: Locomotive::PagePresenter.setters_to_hash,
+ example: {
+ command: %{curl -d '...' -X UPDATE 'http://mysite.com/locomotive/api/pages/4244af4ef0000002.json?auth_token=dtsjkqs1TJrWiSiJt2gg'},
+ response: %(TODO)
+ }
+ },
+ destroy: {
+ description: %{Delete a page},
+ example: {
+ command: %{curl -X DELETE 'http://mysite.com/locomotive/api/pages/4244af4ef0000002.json?auth_token=dtsjkqs1TJrWiSiJt2gg'},
+ response: %(TODO)
+ }
+ }
+ }
+ }
end
end
end