Sha256: a96083740434ceef7f2555541083284b5a57edfb6f70ece4d72e0ec15f9b1632

Contents?: true

Size: 1.96 KB

Versions: 18

Compression:

Stored size: 1.96 KB

Contents

module Scrivito

# @api public
# The Binary class represents the data stored in a binary attribute of an Obj
# or Widget
class Binary
  def initialize(id, public_content)
    @id = id
    @public_content = public_content
  end

  # @api public
  # Some Scrivito data is considered private, i.e. it is not currently intended
  # for the general public, for example content in a workspace that has not 
  # been published yet.
  # @return [Boolean]
  def private?
    !public_content?
  end

  # @api public
  # The URL where this binary data is accessible and can be downloaded using an
  # HTTP GET request. Note that urls for private content will have an
  # expiration time in order to protect them.
  # Therefore the url returned here should be accessed immediately after it has been returned (i.e. within a couple of minutes).
  # When accessed after they have expired, an error will occur.
  # The urls should not be used for long-term-storage (i.e. they are no longer accessible hours or days after they have been generated).
  # @return [String] the URL under which this content is available
  def url
    find_url('get')
  end

  # @api public
  # the filename of this binary data, for example "my_image.jpg"
  # @return [String] the filename of binary
  def filename
    File.basename(URI(url).path)
  end

  # @api public
  # the content type of this binary data, for example "image/jpeg"
  # @return [String] content type
  def content_type
    headers[:content_type]
  end

  # @api public
  # the length of this binary data, in bytes.
  # @return [Integer] number of bytes
  def content_length
    headers[:content_length].to_i
  end

  private

  attr_reader :id

  def public_content?
    !!@public_content
  end

  def headers
    CmsBackend.instance.find_blob_metadata(id, find_url('head'))
  end

  def find_url(verb)
    CmsBackend.instance.find_blob_data(@id, access_type, verb)['url']
  end

  def access_type
    public_content? ? 'public_access' : 'private_access'
  end
end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
scrivito_sdk-0.50.1 lib/scrivito/binary.rb
scrivito_sdk-0.50.0 lib/scrivito/binary.rb
scrivito_sdk-0.50.0.rc2 lib/scrivito/binary.rb
scrivito_sdk-0.50.0.rc1 lib/scrivito/binary.rb
scrivito_sdk-0.42.1 lib/scrivito/binary.rb
scrivito_sdk-0.42.1.rc3 lib/scrivito/binary.rb
scrivito_sdk-0.42.1.rc2 lib/scrivito/binary.rb
scrivito_sdk-0.42.1.rc1 lib/scrivito/binary.rb
scrivito_sdk-0.42.0 lib/scrivito/binary.rb
scrivito_sdk-0.41.1 lib/scrivito/binary.rb
scrivito_sdk-0.41.0 lib/scrivito/binary.rb
scrivito_sdk-0.41.0.rc2 lib/scrivito/binary.rb
scrivito_sdk-0.41.0.rc1 lib/scrivito/binary.rb
scrivito_sdk-0.40.0 lib/scrivito/binary.rb
scrivito_sdk-0.40.0.rc2 lib/scrivito/binary.rb
scrivito_sdk-0.40.0.rc1 lib/scrivito/binary.rb
scrivito_sdk-0.30.0 lib/scrivito/binary.rb
scrivito_sdk-0.30.0.rc1 lib/scrivito/binary.rb