class Contentful::Management::Asset
Resource
class for Asset
. @see _ www.contentful.com/developers/documentation/content-management-api/#resources-assets
Public Class Methods
Source
# File lib/contentful/management/asset.rb, line 28 def self.client_association_class ClientAssetMethodsFactory end
@private
Source
# File lib/contentful/management/asset.rb, line 38 def self.create_attributes(client, attributes) fields = attributes[:fields] || {} locale = attributes[:locale] || client.default_locale fields[:title] = { locale => attributes[:title] } if attributes[:title] fields[:description] = { locale => attributes[:description] } if attributes[:description] fields[:file] = { locale => attributes[:file].properties } if attributes[:file] { fields: fields, metadata: attributes[:_metadata] } end
@private
Source
# File lib/contentful/management/asset.rb, line 33 def self.pre_process_params(parameters) Support.normalize_select!(parameters) end
@private
Public Instance Methods
Source
# File lib/contentful/management/asset.rb, line 49 def after_create(attributes) self.locale = attributes[:locale] || client.default_locale end
@private
Source
# File lib/contentful/management/asset.rb, line 78 def fields_for_query self.class.fields_coercions.keys.each_with_object({}) do |field_name, results| results[field_name] = @fields.transform_values do |fields| get_value_from(fields, field_name) end end end
Parser for assets attributes, creates appropriate form of request.
Source
# File lib/contentful/management/asset.rb, line 87 def get_value_from(fields, field_name) if field_name == :file fields[field_name].properties if fields[field_name] else fields[field_name] end end
@private
Source
# File lib/contentful/management/asset.rb, line 105 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] }.select { |_k, value| value } query.empty? ? file.url : "#{file.url}?#{URI.encode_www_form(query)}" 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 @see _ www.contentful.com/developers/documentation/content-delivery-api/#image-asset-resizing
@return [String] Image API URL
Source
# File lib/contentful/management/asset.rb, line 73 def locale sys && sys[:locale] ? sys[:locale] : default_locale end
Returns currently supported locale or default locale. @return [String] current_locale
Source
# File lib/contentful/management/asset.rb, line 56 def process_file instance_variable_get(:@fields).each_key do |locale| request = Request.new( client, process_url(locale), {}, nil, version: sys[:version] ) request.put end sys[:version] += 1 self end
Processing an Asset
file
@return [Contentful::Management::Asset]
Protected Instance Methods
Source
# File lib/contentful/management/asset.rb, line 118 def process_url(locale_code) "spaces/#{space.id}/environments/#{environment_id}/assets/#{id}/files/#{locale_code}/process" end
Source
# File lib/contentful/management/asset.rb, line 122 def query_attributes(attributes) self.title = attributes[:title] || title self.description = attributes[:description] || description self.file = attributes[:file] || file { fields: fields_for_query, metadata: attributes[:_metadata] } end