Module: Cloudinary

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

Overview

Copyright Cloudinary

Defined Under Namespace

Modules: AuthToken, CarrierWave, FormBuilder Classes: Api, Blob, Downloader, Engine, Migrator, PreloadedFile, Railtie, Search, 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 =
"CloudinaryRuby/" + VERSION
FORMAT_ALIASES =
{
  "jpeg" => "jpg",
  "jpe"  => "jpg",
  "tif"  => "tiff",
  "ps"   => "eps",
  "ept"  => "eps"
}
VERSION =
"1.8.1"
@@user_platform =
""
@@config =
nil

Class Method Summary collapse

Class Method Details

.app_rootObject



128
129
130
131
132
133
134
135
# File 'lib/cloudinary.rb', line 128

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:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cloudinary.rb', line 63

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cloudinary.rb', line 87

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("=")
    if isNestedKey? key
      putNestedKey key, value
    else
      set_config(key => URI.decode(value))
    end
  end
end

.isNestedKey?(key) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/cloudinary.rb', line 124

def self.isNestedKey?(key)
  /\w+\[\w+\]/ =~ key
end

.putNestedKey(key, value) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cloudinary.rb', line 108

def self.putNestedKey(key, value)
  chain   = key.split(/[\[\]]+/).reject { |i| i.empty? }
  outer   = @@config
  lastKey = chain.pop()
  chain.each do |innerKey|
    inner = outer[innerKey]
    if inner.nil?
      inner           = OpenStruct.new
      outer[innerKey] = inner
    end
    outer = inner
  end
  outer[lastKey] = value
end

.USER_AGENTObject



45
46
47
48
49
50
51
# File 'lib/cloudinary.rb', line 45

def self.USER_AGENT
  if @@user_platform.empty?
    "#{USER_AGENT}"
  else
    "#{@@user_platform} #{USER_AGENT}"
  end
end

.user_platformObject



41
42
43
# File 'lib/cloudinary.rb', line 41

def self.user_platform
  @@user_platform
end

.user_platform=(value) ⇒ Object

Add platform information to the USER_AGENT header This is intended for platform information and not individual applications!



37
38
39
# File 'lib/cloudinary.rb', line 37

def self.user_platform=(value)
  @@user_platform= value
end