Class: Landable::Api::AssetsController

Inherits:
Landable::ApiController show all
Defined in:
app/controllers/landable/api/assets_controller.rb

Constant Summary

Constants inherited from Landable::ApiController

Landable::ApiController::API_MEDIA_REGEX

Instance Method Summary collapse

Methods inherited from Landable::ApiController

#api_media

Instance Method Details

#createObject

RESTful methods



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/landable/api/assets_controller.rb', line 11

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

#destroyObject



27
28
29
30
31
# File 'app/controllers/landable/api/assets_controller.rb', line 27

def destroy
  @asset.try(:deactivate)
  
  respond_with @asset
end

#indexObject



33
34
35
36
# File 'app/controllers/landable/api/assets_controller.rb', line 33

def index
  search = Landable::AssetSearchEngine.new(search_params.merge(ids: params[:ids]))
  respond_with search.results, meta: search.meta
end

#reactivateObject



38
39
40
41
42
# File 'app/controllers/landable/api/assets_controller.rb', line 38

def reactivate
  @asset.try(:reactivate)
  
  respond_with @asset
end

#showObject



44
45
46
# File 'app/controllers/landable/api/assets_controller.rb', line 44

def show
  respond_with @asset
end

#updateObject



48
49
50
51
52
# File 'app/controllers/landable/api/assets_controller.rb', line 48

def update
  @asset.update_attributes!(asset_params)

  respond_with @asset
end