Module: Cloudinary

Defined in:
lib/cloudinary/version.rb,
lib/cloudinary.rb

Overview

Copyright Cloudinary

Defined Under Namespace

Modules: CarrierWave, FormBuilder Classes: Api, Blob, Downloader, Engine, Migrator, PreloadedFile, Railtie, Static, Uploader, Utils

Constant Summary collapse

CF_SHARED_CDN =
"d3jpl91pxevbkh.cloudfront.net"
AKAMAI_SHARED_CDN =
"res.cloudinary.com"
OLD_AKAMAI_SHARED_CDN =
"cloudinary-a.akamaihd.net"
SHARED_CDN =
AKAMAI_SHARED_CDN
USER_AGENT =
"cld-ruby-" + VERSION
FORMAT_ALIASES =
{
  "jpeg" => "jpg",
  "jpe" => "jpg",
  "tif" => "tiff",
  "ps" => "eps",
  "ept" => "eps"
}
VERSION =
"1.1.0"
@@config =
nil

Class Method Summary collapse

Class Method Details

.app_rootObject


79
80
81
82
83
84
85
86
# File 'lib/cloudinary.rb', line 79

def self.app_root
  if defined? Rails::root
    # Rails 2.2 return String for Rails.root
    Rails.root.is_a?(Pathname) ? Rails.root : Pathname.new(Rails.root)
  else
    Pathname.new(".")
  end
end

.config(new_config = nil) {|@@config| ... } ⇒ Object

Yields:


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cloudinary.rb', line 38

def self.config(new_config=nil)
  first_time = @@config.nil?
  @@config ||= OpenStruct.new((YAML.load(ERB.new(IO.read(config_dir.join("cloudinary.yml"))).result)[config_env] rescue {}))
      
  # Heroku support
  if first_time && ENV["CLOUDINARY_CLOUD_NAME"]
    set_config(
      "cloud_name" => ENV["CLOUDINARY_CLOUD_NAME"],
      "api_key" => ENV["CLOUDINARY_API_KEY"],
      "api_secret" => ENV["CLOUDINARY_API_SECRET"],
      "secure_distribution" => ENV["CLOUDINARY_SECURE_DISTRIBUTION"],
      "private_cdn" => ENV["CLOUDINARY_PRIVATE_CDN"].to_s == 'true',
      "secure" => ENV["CLOUDINARY_SECURE"].to_s == 'true'
    )
  elsif first_time && ENV["CLOUDINARY_URL"]
    config_from_url(ENV["CLOUDINARY_URL"])
  end

  set_config(new_config) if new_config
  yield(@@config) if block_given?

  @@config    
end

.config_from_url(url) ⇒ Object


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cloudinary.rb', line 62

def self.config_from_url(url)
  @@config ||= OpenStruct.new
  uri = URI.parse(url)
  set_config(
    "cloud_name" => uri.host,
    "api_key" => uri.user,
    "api_secret" => uri.password,
    "private_cdn" => !uri.path.blank?,
    "secure_distribution" => uri.path[1..-1]
  )
  uri.query.to_s.split("&").each do
    |param|
    key, value = param.split("=")
    set_config(key=>URI.decode(value))
  end    
end