Class: Contentful::Asset
- Inherits:
-
FieldsResource
- Object
- BaseResource
- FieldsResource
- Contentful::Asset
- Defined in:
- lib/contentful/asset.rb
Overview
Resource class for Asset. www.contentful.com/developers/documentation/content-delivery-api/#assets
Instance Attribute Summary
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#image_url(options = {}) ⇒ String
(also: #url)
Generates a URL for the Contentful Image API.
-
#initialize ⇒ Asset
constructor
A new instance of Asset.
Methods inherited from FieldsResource
#fields, #fields_with_locales, #locales
Methods inherited from BaseResource
Constructor Details
#initialize ⇒ Asset
Returns a new instance of Asset
25 26 27 28 29 |
# File 'lib/contentful/asset.rb', line 25 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/contentful/asset.rb', line 44 def image_url( = {}) query = { w: [:w] || [:width], h: [:h] || [:height], fm: [:fm] || [:format], q: [:q] || [:quality], f: [:f] || [:focus], fit: [:fit], fl: [:fl] }.reject { |_k, v| v.nil? } if query.empty? file.url else "#{file.url}?#{URI.encode_www_form(query)}" end end |