Class: Contentful::Management::Asset
- Inherits:
-
Object
- Object
- Contentful::Management::Asset
- Extended by:
- Resource::AssetFields
- Includes:
- Resource, Resource::Archiver, Resource::EnvironmentAware, Resource::Fields, Resource::Metadata, Resource::Publisher, Resource::Refresher, Resource::SystemProperties
- Defined in:
- lib/contentful/management/asset.rb
Overview
Resource class for Asset.
Instance Attribute Summary
Attributes included from Resource::SystemProperties
Attributes included from Resource::Metadata
Attributes included from Resource
#client, #properties, #raw_object, #request
Instance Method Summary collapse
-
#fields_for_query ⇒ Object
Parser for assets attributes, creates appropriate form of request.
-
#image_url(options = {}) ⇒ String
Generates a URL for the Contentful Image API.
-
#locale ⇒ String
Returns currently supported locale or default locale.
-
#process_file ⇒ Contentful::Management::Asset
Processing an Asset file.
Methods included from Resource::AssetFields
Methods included from Resource::EnvironmentAware
Methods included from Resource::Publisher
#publish, #published?, #unpublish, #updated?
Methods included from Resource::Refresher
Methods included from Resource::Archiver
#archive, #archived?, #unarchive
Methods included from Resource::Fields
Methods included from Resource
#array?, #default_locale, #destroy, #environment_id, #fields, #nested_locale_fields?, #resource?, #save, #sys, #update
Instance Method Details
#fields_for_query ⇒ Object
Parser for assets attributes, creates appropriate form of request.
78 79 80 81 82 83 84 |
# 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 |
#image_url(options = {}) ⇒ String
Generates a URL for the Contentful Image API
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/contentful/management/asset.rb', line 105 def image_url( = {}) query = { w: [:w] || [:width], h: [:h] || [:height], fm: [:fm] || [:format], q: [:q] || [:quality] }.select { |_k, value| value } query.empty? ? file.url : "#{file.url}?#{URI.encode_www_form(query)}" end |
#locale ⇒ String
Returns currently supported locale or default locale.
73 74 75 |
# File 'lib/contentful/management/asset.rb', line 73 def locale sys && sys[:locale] ? sys[:locale] : default_locale end |
#process_file ⇒ Contentful::Management::Asset
Processing an Asset file
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |