Class: Fogged::ResourcesController
- Inherits:
-
Object
- Object
- Fogged::ResourcesController
- Defined in:
- app/controllers/fogged/resources_controller.rb
Instance Method Summary collapse
-
#confirm ⇒ Object
Confirm a resource.
-
#create ⇒ Object
Create a new resource.
-
#destroy ⇒ Object
Destroy a resource.
-
#index ⇒ Object
List all resources.
-
#show ⇒ Object
Get the resource.
-
#update ⇒ Object
Update a Resource.
- #zencoder_notification ⇒ Object
Instance Method Details
#confirm ⇒ Object
Confirm a resource. You MUST confirm a resource before using it.
id - the resource id
Examples
PUT /api/v1/resources/1/confirm
Return the confirmed resource. Note that the upload_url will not be present in the response. Raises 500 if a server errors occurs
181 182 183 184 185 |
# File 'app/controllers/fogged/resources_controller.rb', line 181 def confirm @resource.process! @resource.update!(:uploading => false) show end |
#create ⇒ Object
Create a new resource. You must provide a filename (example: foo.png) and a content_type (example: “image/png”). This content_type must be the same as the one used with the upload_url.
resource - a hash with a name (optional), a filename and a content_type
Examples
POST /api/v1/resources {
"resource": {
"name": "The ultimate ruby"
"filename": "ruby.png"
"content_type": "image/png"
}
}
Return the created resource which will be marked as uploading. Raises 400 if resource params are not valid. Raises 500 if an error occurs.
134 135 136 137 138 139 140 141 142 143 |
# File 'app/controllers/fogged/resources_controller.rb', line 134 def create resource_attributes = resource_params.except(:filename) resource_attributes[:extension] = extension(resource_params.require(:filename)) resource = Resource.create!(resource_attributes.merge(:uploading => true)) render :json => resource, :serializer => ResourceSerializer, :include_upload_url => true end |
#destroy ⇒ Object
Destroy a resource. You can choose to destroy a resource. This will also destroy the content on S3.
id - the resource id
Examples
DELETE /api/v1/resources/1
Return an empty response with 204(No content) Raises 500 if a server errors occurs
198 199 200 201 |
# File 'app/controllers/fogged/resources_controller.rb', line 198 def destroy @resource.destroy! head :no_content end |
#index ⇒ Object
List all resources. Parameter type is mandatory. It indicates in which “context” you want all resources. You can refine the search, using using parameters type_id or type_ids, which will select the context objects before retrieving the resources. Pagination options are available. Search options are available.
type - the context/type in which the resources search is done. Mandatory type_id - the specific type id type_ids - the specific type ids query - text search (insensitive) on the resource’s name
Example
GET /api/v1/resources?type=group&ids[]=2&ids=3 GET /api/v1/resources?type=group
Returns an array of Resources found Raises 400 if the given type is unknown Raises 500 if an error occurs
87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/fogged/resources_controller.rb', line 87 def index resources = @resourceables.map do |resourceable| resourceable.resources.search(params) end render :json => paginate(resources.flatten.uniq), :meta => @meta, :each_serializer => ResourceSerializer end |
#show ⇒ Object
Get the resource.
id - the resource’s id
Example
GET /api/v1/resources/123
Returns the Resource Raises 404 if the Resource is not found Raises 500 if an error occurs
108 109 110 111 |
# File 'app/controllers/fogged/resources_controller.rb', line 108 def show render :json => @resource, :serializer => ResourceSerializer end |
#update ⇒ Object
Update a Resource. You can update the name of a Resource or its context object
id - the resource’s id resource - the resource params
Example
PUT /api/v1/resources/1 {
"resource": {
"name": "Updated"
}
}
Returns the updated Resource Raises 400 if the parameters are invalid Raises 404 if the resource or the context object can’t be found Raises 500 if an error occurs
164 165 166 167 168 |
# File 'app/controllers/fogged/resources_controller.rb', line 164 def update @resource.update!(resource_params.permit(:name)) show end |
#zencoder_notification ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/controllers/fogged/resources_controller.rb', line 203 def zencoder_notification if (resource = Resource.find_by(:encoding_job_id => job_params[:id])) && (file = params[:outputs].try(:first)) && job_params[:state] == "finished" resource.update!( :encoding_progress => 100, :width => file[:width], :height => file[:height], :duration => file[:duration_in_ms].to_f / 1000.0 ) end head :ok end |