Class: Api::PresetsController

Inherits:
ApiController show all
Defined in:
app/controllers/api/presets_controller.rb

Overview

Presets Controller

A preset represents command line options for ffmpeg sent to the Transcoder

Instance Method Summary (collapse)

Instance Method Details

- (Object) create

Creates a preset

Creates a preset using the specified parameters, which are all required. If the request was valid, the created preset is returned. If the request could not be completed, a list of errors will be returned.

Parameters

All parameters are required

name

Name of the preset

params

Parameters to use

Response codes

success

201 created

failed

406 Unprocessable Entity

Example

$ curl -d 'name=webm&parameters=params' http://localhost:3000/api/presets

{"preset":{
  "created_at":"2011-05-10T14:44:07Z",
  "id":3,
  "name":"webm",
  "parameters":
  "params",
  "updated_at":"2011-05-10T14:44:07Z"}
}


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/api/presets_controller.rb', line 48

def create
  preset = Preset.from_api(params)
  
  if preset.valid?
    respond_with preset, :location => api_preset_url(preset) do |format|
      format.html { redirect_to presets_path }
    end
  else
    respond_with preset do |format|
      format.html { @preset = preset; render "/presets/new"}
    end
  end
end

- (Object) destroy

Deletes a preset

Parameters

id

Id of the preset to delete

Example

$ curl -XDELETE http://localhost:3000/api/presets/1
{} # HTTP Status: 200 OK


115
116
117
118
119
120
121
# File 'app/controllers/api/presets_controller.rb', line 115

def destroy
  preset = Preset.find(params[:id])
  preset.destroy
  respond_with preset, :location => api_preset_url(preset) do |format|
    format.html { redirect_to presets_path }
  end
end

- (Object) index

Returns a list of presets

Example:

$ curl http://localhost:3000/api/presets

[
  {"preset":{
    "created_at":"2011-05-09T11:59:53Z",
    "id":1,
    "name":"h264",
    "parameters":"-acodec libfaac -ab 96k -ar 44100 -vcodec libx264 -vb 416k -vpre slow -vpre baseline -s 320x180 -y",
    "updated_at":"2011-05-09T11:59:53Z"}
  }
]


19
20
21
# File 'app/controllers/api/presets_controller.rb', line 19

def index
  respond_with Preset.all
end

- (Object) show

Displays a preset

Parameters

id

Id of the preset to display

Example

$ curl http://localhost:3000/api/presets/1

{"preset":{
  "created_at":"2011-05-10T14:44:07Z",
  "id":3,
  "name":"webm",
  "parameters":
  "params",
  "updated_at":"2011-05-10T14:44:07Z"}
}


78
79
80
# File 'app/controllers/api/presets_controller.rb', line 78

def show
  respond_with Preset.find(params[:id])
end

- (Object) update

Updates a preset

Paramdeters

id

Id of the preset to update

name

Name of the preset

parameters

Parameters of the preset

Example

$ curl -XPUT -d 'name=h264&parameters=params' http://localhost:3000/api/presets/1
{} # HTTP Status: 200 OK


93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/api/presets_controller.rb', line 93

def update
  preset = Preset.find(params[:id])
  if preset.update_attributes(:name => params[:name], :parameters => params[:parameters])
    respond_with preset, :location => api_preset_url(preset) do |format|
      format.html { redirect_to presets_path }
    end
  else
    respond_with preset do |format|
      format.html { @preset = preset; render "/presets/edit" }
    end
  end
end