Class: Contentful::Asset

Inherits:
Object
  • Object
show all
Includes:
Resource, Resource::AssetFields, Resource::SystemProperties
Defined in:
lib/contentful/asset.rb

Overview

Constant Summary

Constants included from Resource::AssetFields

Resource::AssetFields::FIELDS_COERCIONS

Constants included from Resource::SystemProperties

Resource::SystemProperties::SYS_COERCIONS

Constants included from Resource

Resource::COERCIONS

Instance Attribute Summary

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource

#client, #default_locale, #properties, #request

Instance Method Summary collapse

Methods included from Resource::AssetFields

#fields, included, #initialize, #inspect

Methods included from Resource::SystemProperties

included, #initialize, #inspect

Methods included from Resource

#array?, #fields, #initialize, #inspect, #nested_locale_fields?, #reload, #sys

Instance Method Details

#image_url(options = {}) ⇒ Object

Returns the image url of an asset Allows you to pass in the following options for image resizing:

:width
:height
:format
:quality

See www.contentful.com/developers/documentation/content-delivery-api/#image-asset-resizing



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/contentful/asset.rb', line 19

def image_url(options = {})
  query = {
    w:   options[:w]  || options[:width],
    h:   options[:h]  || options[:height],
    fm:  options[:fm] || options[:format],
    q:   options[:q]  || options[:quality],
    f:   options[:f]  || options[:focus],
    fit: options[:fit]
  }.reject { |_k, v| v.nil? }

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