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 FieldsResource
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
28 29 30 31 32 |
# File 'lib/contentful/asset.rb', line 28 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/contentful/asset.rb', line 47 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 |