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
26
# File 'app/controllers/landable/api/assets_controller.rb', line 11

def create
  asset = Asset.new(asset_params)
  original = asset.duplicate_of

  if original
    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



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

def destroy
  @asset.try(:deactivate)

  respond_with @asset
end

#indexObject



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

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

#reactivateObject



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

def reactivate
  @asset.try(:reactivate)

  respond_with @asset
end

#showObject



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

def show
  respond_with @asset
end

#updateObject



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

def update
  @asset.update_attributes!(asset_params)

  respond_with @asset
end