class Contentful::Asset
Resource class for Asset
. www.contentful.com/developers/documentation/content-delivery-api/#assets
Public Class Methods
Source
# File lib/contentful/asset.rb, line 33 def initialize(*) super create_files! define_asset_methods! end
Calls superclass method
Public Instance Methods
Source
# 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
Generates a URL for the Contentful
Image API
@param [Hash] options @option options [Integer] :width @option options [Integer] :height @option options [String] :format @option options [String] :quality @option options [String] :focus @option options [String] :fit @option options [String] :fl File
Layering - ‘progressive’ @option options [String] :background @see _ www.contentful.com/developers/documentation/content-delivery-api/#image-asset-resizing
@return [String] Image API URL
Also aliased as: url
Source
# File lib/contentful/asset.rb, line 29 def inspect "<#{repr_name} id='#{sys[:id]}' url='#{url}'>" end
@private
Source
# File lib/contentful/asset.rb, line 24 def known_link?(*) false end
@private
Source
# File lib/contentful/asset.rb, line 12 def marshal_dump super.merge(raw: raw) end
@private
Calls superclass method
Source
# File lib/contentful/asset.rb, line 17 def marshal_load(raw_object) super(raw_object) create_files! define_asset_methods! end
@private
Calls superclass method
Private Instance Methods
Source
# File lib/contentful/asset.rb, line 67 def build_query(options) { 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], bg: options[:bg] || options[:background], r: options[:r] || options[:radius], fit: options[:fit], fl: options[:fl] }.reject { |_k, v| v.nil? } end
Source
# File lib/contentful/asset.rb, line 81 def create_files! file_json = raw.fetch('fields', {}).fetch('file', nil) return if file_json.nil? is_localized = file_json.keys.none? { |f| %w[fileName contentType details url].include? f } if is_localized locales.each do |locale| @fields[locale][:file] = ::Contentful::File.new(file_json[locale.to_s] || {}, @configuration) end else @fields[internal_resource_locale][:file] = ::Contentful::File.new(file_json, @configuration) end end
Source
# File lib/contentful/asset.rb, line 95 def define_asset_methods! define_singleton_method :title do fields.fetch(:title, nil) end define_singleton_method :description do fields.fetch(:description, nil) end define_singleton_method :file do |wanted_locale = nil| fields(wanted_locale)[:file] end end