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

#default_locale, #raw, #sys

Instance Method Summary collapse

Methods included from ResourceReferences

#incoming_references

Methods inherited from FieldsResource

#fields, #fields_with_locales, #locales

Methods inherited from BaseResource

#==, #reload

Constructor Details

#initializeAsset

Returns a new instance of Asset



31
32
33
34
35
# File 'lib/contentful/asset.rb', line 31

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


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

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

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