Class: Contentful::Asset

Inherits:
FieldsResource show all
Includes:
ResourceReferences
Defined in:
lib/contentful/asset.rb

Overview

Instance Attribute Summary

Attributes inherited from FieldsResource

#localized

Attributes inherited from BaseResource

#_metadata, #default_locale, #raw, #sys

Instance Method Summary collapse

Methods included from ResourceReferences

#incoming_references

Methods inherited from FieldsResource

#fields, #fields_with_locales, #locales, #raw_with_links

Methods inherited from BaseResource

#==, #reload

Constructor Details

#initializeAsset

Returns a new instance of Asset.



33
34
35
36
37
# File 'lib/contentful/asset.rb', line 33

def initialize(*)
  super
  create_files!
  define_asset_methods!
end

Instance Method Details

#image_url(options = {}) ⇒ String Also known as: url

Generates a URL for the Contentful Image API

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :width (Integer)
  • :height (Integer)
  • :format (String)
  • :quality (String)
  • :focus (String)
  • :fit (String)
  • :fl (String)

    File Layering - ‘progressive’

  • :background (String)

Returns:

  • (String)

    Image API URL

See Also:

  • https://www.contentful.com/developers/documentation/content-delivery-api/#image-asset-resizing


53
54
55
56
57
58
59
60
61
# File 'lib/contentful/asset.rb', line 53

def image_url(options = {})
  query = build_query(options)

  if query.empty?
    file.url
  else
    "#{file.url}?#{URI.encode_www_form(query)}"
  end
end

#inspectObject



29
30
31
# File 'lib/contentful/asset.rb', line 29

def inspect
  "<#{repr_name} id='#{sys[:id]}' url='#{url}'>"
end

#known_link?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/contentful/asset.rb', line 24

def known_link?(*)
  false
end

#marshal_dumpObject



12
13
14
# File 'lib/contentful/asset.rb', line 12

def marshal_dump
  super.merge(raw: raw)
end

#marshal_load(raw_object) ⇒ Object



17
18
19
20
21
# File 'lib/contentful/asset.rb', line 17

def marshal_load(raw_object)
  super(raw_object)
  create_files!
  define_asset_methods!
end