Class: Contentstack::Asset
- Inherits:
-
Object
- Object
- Contentstack::Asset
- Defined in:
- lib/contentstack/asset.rb
Overview
Asset class to fetch file details on Conentstack server.
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Content Type for the asset.
-
#file_size ⇒ Object
readonly
Size of the asset.
-
#filename ⇒ Object
readonly
Name of the asset.
-
#tags ⇒ Object
readonly
Array of tags assigned to the asset.
-
#uid ⇒ Object
readonly
Contentstack Asset UID for this asset.
-
#url ⇒ Object
readonly
URL to fetch/render the asset.
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetch a particular asset using uid.
-
#initialize(attrs) ⇒ Asset
constructor
Create instance of an Asset.
Constructor Details
#initialize(attrs) ⇒ Asset
Create instance of an Asset. Accepts either a uid of asset (String) or a complete asset JSON Usage for String parameter
@asset = @stack.asset("some_asset_uid")
@asset.fetch
Usage for Hash parameter
@asset = @stack.asset({
:uid => "some_asset_uid",
:content_type => "file_type", # image/png, image/jpeg, application/pdf, video/mp4 etc.
:filename => "some_file_name",
:file_size => "some_file_size",
:tags => ["tag1", "tag2", "tag3"],
:url => "file_url"
})
@asset.fetch
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/contentstack/asset.rb', line 43 def initialize(attrs) if attrs.class == String @uid = attrs else attrs = attrs.symbolize_keys @uid = attrs[:uid] @content_type = attrs[:content_type] @filename = attrs[:filename] @file_size = attrs[:file_size] @tags = attrs[:tags] @url = attrs[:url] end self end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Content Type for the asset. image/png, image/jpeg, application/pdf, video/mp4 etc.
12 13 14 |
# File 'lib/contentstack/asset.rb', line 12 def content_type @content_type end |
#file_size ⇒ Object (readonly)
Size of the asset.
18 19 20 |
# File 'lib/contentstack/asset.rb', line 18 def file_size @file_size end |
#filename ⇒ Object (readonly)
Name of the asset.
15 16 17 |
# File 'lib/contentstack/asset.rb', line 15 def filename @filename end |
#tags ⇒ Object (readonly)
Array of tags assigned to the asset.
21 22 23 |
# File 'lib/contentstack/asset.rb', line 21 def @tags end |
#uid ⇒ Object (readonly)
Contentstack Asset UID for this asset
9 10 11 |
# File 'lib/contentstack/asset.rb', line 9 def uid @uid end |
#url ⇒ Object (readonly)
URL to fetch/render the asset
24 25 26 |
# File 'lib/contentstack/asset.rb', line 24 def url @url end |
Instance Method Details
#fetch ⇒ Object
Fetch a particular asset using uid.
@asset = @stack.asset('some_asset_uid')
@asset.fetch
puts @asset.url
63 64 65 66 67 |
# File 'lib/contentstack/asset.rb', line 63 def fetch json = API.get_assets(@uid) # puts "json -- #{json}" self.class.new(json["asset"]) end |