Sha256: d447ebecf270bf3149f2b726b808087748fc90f9af96ab29e586b276ccfec562

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

require_dependency 'landable/api_controller'
require_dependency 'landable/asset_search_engine'

module Landable
  module Api
    class AssetsController < ApiController
      # filters
      before_filter :load_asset, except: [:create, :index]
      
      # RESTful methods
      def create
        asset = Asset.new(asset_params)

        if original = asset.duplicate_of
          head :moved_permanently, location: asset_url(original)
          return
        end
        
        Asset.transaction do
          asset.author = current_author
          asset.save!
        end
        
        respond_with asset, status: :created, location: asset_url(asset)
      end
      
      def destroy
        @asset.try(:deactivate)
        
        respond_with @asset
      end
      
      def index
        search = Landable::AssetSearchEngine.new(search_params.merge(ids: params[:ids]))
        respond_with search.results, meta: search.meta
      end

      def reactivate
        @asset.try(:reactivate)
        
        respond_with @asset
      end
      
      def show
        respond_with @asset
      end
      
      def update
        @asset.update_attributes!(asset_params)

        respond_with @asset
      end
      
      # custom methods
      private
        def asset_params
          params.require(:asset).permit(:id, :name, :description, :data, :file)
        end
      
        def load_asset
          @asset = Asset.find(params[:id])
        end
      
        def search_params
          @search_params ||=
            begin
              hash = params.permit(search: [:name])
              hash[:search] || {}
            end
        end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
landable-1.13.1 app/controllers/landable/api/assets_controller.rb
landable-1.12.3 app/controllers/landable/api/assets_controller.rb
landable-1.12.2 app/controllers/landable/api/assets_controller.rb
landable-1.12.1 app/controllers/landable/api/assets_controller.rb
landable-1.11.1 app/controllers/landable/api/assets_controller.rb
landable-1.11.0 app/controllers/landable/api/assets_controller.rb
landable-1.10.0.rc2 app/controllers/landable/api/assets_controller.rb
landable-1.10.0.rc1 app/controllers/landable/api/assets_controller.rb
landable-1.9.2 app/controllers/landable/api/assets_controller.rb
landable-1.9.1 app/controllers/landable/api/assets_controller.rb
landable-1.9.0 app/controllers/landable/api/assets_controller.rb
landable-1.9.0.rc2 app/controllers/landable/api/assets_controller.rb
landable-1.9.0.rc1 app/controllers/landable/api/assets_controller.rb
landable-1.8.0 app/controllers/landable/api/assets_controller.rb