class Contentstack::Asset

Asset class to fetch file details on Conentstack server.

Attributes

content_type[R]
file_size[R]
filename[R]
tags[R]
uid[R]
url[R]

Public Class Methods

new(attrs) click to toggle source

Create instance of an Asset. Accepts either a uid of asset (String) or a complete asset JSON @param [String/Hash] attrs 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
# 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

Public Instance Methods

fetch() click to toggle source

Fetch a particular asset using uid.

@asset = @stack.asset('some_asset_uid')
@asset.fetch
puts @asset.url
# File lib/contentstack/asset.rb, line 61
def fetch
  json = API.get_assets(@uid)
  # puts "json -- #{json}"
  self.class.new(json["asset"])
end