Module: Fogged
- Defined in:
- app/controllers/fogged/resources_controller.rb,
lib/fogged.rb,
lib/fogged/utils.rb,
lib/fogged/engine.rb,
lib/fogged/version.rb,
lib/fogged/with_directory.rb,
app/models/fogged/resource.rb,
lib/fogged/has_one_resource.rb,
lib/fogged/has_many_resources.rb,
app/models/fogged/resources/encoder.rb,
lib/fogged/zencoder_additional_outputs.rb,
app/models/fogged/resources/aws_encoder.rb,
app/serializers/fogged/resource_serializer.rb,
app/jobs/fogged/resources/aws_thumbnail_job.rb
Overview
The Resource API. This API has only 3 methods: create, confirm and destroy.
To create a new resource, call the create method with a filename and a content_type, you will get a resource as a result. This resource has an upload_url you can use to put your content. Caution, this url is valid only for 2 minutes.
When uploading a resource, two http headers are mandatory:
-
Content-Type, which must be the same value as the one used to create the resource
-
Set the acl to public read. Eg. on AWS send the x-amz-acl header set to “public-read”. This ensures that the resource is publicly readable.
The upload can fail if these two flags/settings are missing.
Once you finished uploading the resource, you can confirm it with the method confirm. You MUST confirm a resource in order to use it elsewhere (eg. in the Event api). Once confirmed, a resource can’t be updated. For example, if you want to update the resource content, create a new one. A resource has these fields:
id - the resource’s id name - the resource’s name upload_url - the secured url where you can upload your content. This link has
already all the correct parameters for S3. Do not change them.
url - the public url where you can read the content h264_url - the url of the h264 file. Only for video resources mpeg_url - the url of the mpeg file. Only for video resources webm_url - the url of the webm file. Only for video resources thumbnail_urls - the urls of the thumbnails. Only for video resources encoding_progress - the progress of the encoding in %. Only for video
resources
Examples
{
"resource": {
"id": 1,
"upload_url": "https:...",
"url": "https:..."
}
}
{
"resource": {
"id": 42145,
"name": "Resource 6",
"url": "https://...",
"h264_url": "https://...",
"mpeg_url": "https://...",
"webm_url": "https://...",
"thumbnail_urls": [
"https://...",
"https://...",
"https://...",
"https://...",
"https://..."
],
"encoding_progress": 0
}
}
Defined Under Namespace
Modules: HasManyResources, HasOneResource, Resources Classes: Engine, Resource, ResourceSerializer, ResourcesController
Constant Summary collapse
- VERSION =
"0.0.13"
Class Method Summary collapse
- .configure {|_self| ... } ⇒ Object
- .directory_public_url(directory_name) ⇒ Object
- .file_exists?(key) ⇒ Boolean
- .file_public_url(key, directory = Fogged.resources.key) ⇒ Object
- .resources ⇒ Object
- .resources_public_url ⇒ Object
- .test_mode! ⇒ Object
- .with_directory(directory_name) ⇒ Object
- .zencoder_additional_outputs(&block) ⇒ Object
Class Method Details
.configure {|_self| ... } ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/fogged.rb', line 42 def self.configure yield self if block_given? check_config self.zencoder_enabled = defined?(Zencoder) self.minimagick_enabled = defined?(MiniMagick) self.active_job_enabled = (Rails.application.config.active_job.queue_adapter != :inline) end |
.directory_public_url(directory_name) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/fogged/utils.rb', line 2 def self.directory_public_url(directory_name) case Fogged.provider when :aws Fogged.storage.request_url(:bucket_name => directory_name) else fail(ArgumentError, "Provider #{Fogged.provider} is not available!") end end |
.file_exists?(key) ⇒ Boolean
23 24 25 |
# File 'lib/fogged/utils.rb', line 23 def self.file_exists?(key) Fogged.resources.files.head(key) end |
.file_public_url(key, directory = Fogged.resources.key) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/fogged/utils.rb', line 15 def self.file_public_url(key, directory = Fogged.resources.key) Fogged.storage.try( :request_url, :bucket_name => directory, :object_name => key ) end |
.resources ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fogged.rb', line 50 def self.resources return Fogged._resources if Fogged._resources case Fogged.provider when :aws Fogged._resources = aws_resources else fail(ArgumentError, "Provider #{Fogged.provider} is not available!") end end |
.resources_public_url ⇒ Object
11 12 13 |
# File 'lib/fogged/utils.rb', line 11 def self.resources_public_url directory_public_url(Fogged.resources.key) end |
.test_mode! ⇒ Object
61 62 63 64 |
# File 'lib/fogged.rb', line 61 def self.test_mode! Fogged.test_enabled = true Fogged._resources = test_resources end |
.with_directory(directory_name) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/fogged/with_directory.rb', line 2 def self.with_directory(directory_name) old_resources = Fogged._resources Fogged._resources = Fogged.storage.directories.get(directory_name) yield ensure Fogged._resources = old_resources end |
.zencoder_additional_outputs(&block) ⇒ Object
4 5 6 |
# File 'lib/fogged/zencoder_additional_outputs.rb', line 4 def self.zencoder_additional_outputs(&block) Fogged.zencoder_additional_outputs_block = block end |