class Middleman::ImageUploaderTag::CloudinaryCDN

Constants

OBLIGATORY_OPTIONS

Public Class Methods

new(config) click to toggle source
# File lib/middleman/image-uploader-tag/cdns/cloudinary.rb, line 9
def initialize(config)
  raise AuthorizationRequired if OBLIGATORY_OPTIONS.any? { |k| config[k].nil? }

  Cloudinary.config do |c|
    config.each { |key, value| c.public_send(:"#{key}=", value) unless value.nil? }
  end
end

Public Instance Methods

upload_to_cloud(file, options = {}) click to toggle source
# File lib/middleman/image-uploader-tag/cdns/cloudinary.rb, line 24
def upload_to_cloud(file, options = {})
  # rescue Cloudinary exceptions? (timeouts, limits and so on..)
  raise NotFound if !file || !File.exist?(file.to_s)

  options.merge!({ use_filename: true, unique_filename: false })

  Cloudinary::Uploader.upload(file, options).inject({}) do |memo, (k,v)|
    memo[k.to_sym] = v
    memo
  end
end