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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/contentstack/asset.rb', line 41 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.
10 11 12 |
# File 'lib/contentstack/asset.rb', line 10 def content_type @content_type end |
#file_size ⇒ Object (readonly)
Size of the asset.
16 17 18 |
# File 'lib/contentstack/asset.rb', line 16 def file_size @file_size end |
#filename ⇒ Object (readonly)
Name of the asset.
13 14 15 |
# File 'lib/contentstack/asset.rb', line 13 def filename @filename end |
#tags ⇒ Object (readonly)
Array of tags assigned to the asset.
19 20 21 |
# File 'lib/contentstack/asset.rb', line 19 def @tags end |
#uid ⇒ Object (readonly)
Contentstack Asset UID for this asset
7 8 9 |
# File 'lib/contentstack/asset.rb', line 7 def uid @uid end |
#url ⇒ Object (readonly)
URL to fetch/render the asset
22 23 24 |
# File 'lib/contentstack/asset.rb', line 22 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
61 62 63 64 65 |
# File 'lib/contentstack/asset.rb', line 61 def fetch json = API.get_assets(@uid) # puts "json -- #{json}" self.class.new(json["asset"]) end |