cloudinary 1.0.37 → 1.0.38

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,5 @@ pkg
4
4
  assets/
5
5
  vendor/assets/
6
6
  Gemfile.lock
7
+ .DS_Store
8
+ *.tmproj
@@ -40,7 +40,7 @@ class Cloudinary::Api
40
40
  resource_type = options[:resource_type] || "image"
41
41
  type = options[:type] || "upload"
42
42
  uri = "resources/#{resource_type}/#{type}/#{public_id}"
43
- call_api(:get, uri, {}, options)
43
+ call_api(:get, uri, only(options, :colors, :exif, :faces), options)
44
44
  end
45
45
 
46
46
  def self.delete_resources(public_ids, options={})
@@ -46,12 +46,8 @@ module Cloudinary::CarrierWave
46
46
  options = args.extract_options!
47
47
  options = self.transformation.merge(options) if self.version_name.present?
48
48
 
49
- resource_type = Cloudinary::Utils.resource_type_for_format(self.format)
50
- if self.class.storage_type == :authenticated
51
- Cloudinary::Utils.signed_download_url(public_id, {:format=>self.format, :resource_type=>resource_type}.merge(options))
52
- else
53
- Cloudinary::Utils.cloudinary_url(public_id, {:format=>self.format, :resource_type=>resource_type, :type=>self.class.storage_type}.merge(options))
54
- end
49
+ resource_type = Cloudinary::Utils.resource_type_for_format(self.filename || self.format)
50
+ Cloudinary::Utils.cloudinary_url(public_id, {:format=>self.format, :resource_type=>resource_type, :type=>self.storage_type}.merge(options))
55
51
  end
56
52
  end
57
53
 
@@ -109,10 +105,11 @@ module Cloudinary::CarrierWave
109
105
  end
110
106
 
111
107
  class CloudinaryFile
112
- attr_reader :identifier, :public_id, :filename, :format, :version, :storage_type
108
+ attr_reader :identifier, :public_id, :filename, :format, :version, :storage_type, :resource_type
113
109
  def initialize(identifier, uploader)
114
110
  @uploader = uploader
115
111
  @identifier = identifier
112
+
116
113
  if @identifier.include?("/")
117
114
  version, @filename = @identifier.split("/")
118
115
  @version = version[1..-1] # remove 'v' prefix
@@ -120,17 +117,25 @@ module Cloudinary::CarrierWave
120
117
  @filename = @identifier
121
118
  @version = nil
122
119
  end
120
+
123
121
  @storage_type = uploader.class.storage_type
122
+ @resource_type = Cloudinary::Utils.resource_type_for_format(@filename)
124
123
  @public_id, @format = Cloudinary::CarrierWave.split_format(@filename)
125
124
  end
126
125
 
127
126
  def delete
128
- Cloudinary::Uploader.destroy(self.public_id) if @uploader.delete_remote?
127
+ Cloudinary::Uploader.destroy(self.public_id, :type=>self.storage_type, :resource_type=>self.resource_type) if @uploader.delete_remote?
129
128
  end
130
129
 
131
130
  def exists?
132
- Cloudinary::Uploader.exists?(self.identifier, :type=>self.storage_type)
131
+ Cloudinary::Uploader.exists?(self.identifier, :type=>self.storage_type, :resource_type=>self.resource_type)
133
132
  end
133
+
134
+ def read(options={})
135
+ parameters={:type=>self.storage_type, :resource_type=>self.resource_type}.merge(options)
136
+ Cloudinary::Downloader.download(self.identifier, parameters)
137
+ end
138
+
134
139
  end
135
140
 
136
141
  def self.split_format(identifier)
@@ -25,6 +25,7 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
25
25
  eager_versions = uploader.versions.values.select(&:eager)
26
26
  params[:eager] = eager_versions.map{|version| [version.transformation, version.format]} if eager_versions.length > 0
27
27
  params[:type]=uploader.class.storage_type
28
+
28
29
  params[:resource_type] ||= :auto
29
30
 
30
31
  uploader.metadata = Cloudinary::Uploader.upload(data, params)
@@ -58,5 +59,5 @@ class Cloudinary::CarrierWave::Storage < ::CarrierWave::Storage::Abstract
58
59
  else
59
60
  raise "Only ActiveRecord and Mongoid are supported at the moment!"
60
61
  end
61
- end
62
+ end
62
63
  end
@@ -3,19 +3,26 @@ class Cloudinary::Downloader
3
3
 
4
4
  def self.download(source, options={})
5
5
  options = options.clone
6
+
6
7
  if !source.match(/^https?:\/\//i)
7
- source = Cloudinary::Utils.cloudinary_url(source, options)
8
+ source = Cloudinary::Utils.cloudinary_url(source, options)
8
9
  end
9
-
10
- url = URI.parse(source)
10
+
11
+
12
+ url = URI.parse(source)
11
13
  http = Net::HTTP.new(url.host, url.port)
12
- req = Net::HTTP::Get.new(url.path)
14
+ req = Net::HTTP::Get.new(url.request_uri)
15
+
13
16
  if url.port == 443
14
17
  http.use_ssl=true
15
18
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
19
  end
17
- res = http.start{|agent| agent.request(req)}
18
- return res.body
20
+
21
+ res = http.start{|agent|
22
+ agent.request(req)
23
+ }
24
+
25
+ return res.body
19
26
  end
20
27
 
21
28
  end
@@ -72,6 +72,7 @@ class Cloudinary::Migrator
72
72
  public_id
73
73
  )
74
74
  "
75
+
75
76
  if options[:reset_queue]
76
77
  @db.execute("delete from queue")
77
78
  end
@@ -262,7 +263,7 @@ class Cloudinary::Migrator
262
263
  # Skip
263
264
  elsif data.match(/^https?:/)
264
265
  url = data
265
- else
266
+ else
266
267
  file = main.temporary_file(data, row["public_id"] || "cloudinaryfile")
267
268
  end
268
269
  end
@@ -53,12 +53,13 @@ class Cloudinary::Uploader
53
53
  end
54
54
 
55
55
  def self.exists?(public_id, options={})
56
- if options[:type] == :authenticated
57
- cloudinary_url = Cloudinary::Utils.signed_download_url(public_id, options)
58
- else
59
- cloudinary_url = Cloudinary::Utils.cloudinary_url(public_id, options)
56
+ cloudinary_url = Cloudinary::Utils.cloudinary_url(public_id, options)
57
+ begin
58
+ RestClient::Request.execute(:method => :head, :url => cloudinary_url, :timeout=>5).code.to_s =~ /2\d{2}/
59
+ rescue RestClient::ResourceNotFound => e
60
+ return false
60
61
  end
61
- RestClient::Request.execute(:method => :head, :url => cloudinary_url, :timeout=>5).code.to_s =~ /2\d{2}/
62
+
62
63
  end
63
64
 
64
65
  def self.explicit(public_id, options={})
@@ -48,9 +48,14 @@ class Cloudinary::Utils
48
48
  effect = options.delete(:effect)
49
49
  effect = Array(effect).flatten.join(":") if effect.is_a?(Array) || effect.is_a?(Hash)
50
50
 
51
- params = {:w=>width, :h=>height, :t=>named_transformation, :c=>crop, :b=>background, :e=>effect, :a=>angle}
52
- { :x=>:x, :y=>:y, :r=>:radius, :d=>:default_image, :g=>:gravity, :q=>:quality,
53
- :p=>:prefix, :l=>:overlay, :u=>:underlay, :f=>:fetch_format, :dn=>:density, :pg=>:page
51
+ border = options.delete(:border)
52
+ if border.is_a?(Hash)
53
+ border = "#{border[:width] || 2}px_solid_#{(border[:color] || "black").sub(/^#/, 'rgb:')}"
54
+ end
55
+
56
+ params = {:w=>width, :h=>height, :t=>named_transformation, :c=>crop, :b=>background, :e=>effect, :a=>angle, :bo=>border}
57
+ { :x=>:x, :y=>:y, :r=>:radius, :d=>:default_image, :g=>:gravity, :q=>:quality, :cs=>:color_space,
58
+ :p=>:prefix, :l=>:overlay, :u=>:underlay, :f=>:fetch_format, :dn=>:density, :pg=>:page, :dl=>:delay
54
59
  }.each do
55
60
  |param, option|
56
61
  params[param] = options.delete(option)
@@ -72,7 +77,8 @@ class Cloudinary::Utils
72
77
  end
73
78
 
74
79
  # Warning: options are being destructively updated!
75
- def self.cloudinary_url(source, options = {})
80
+ def self.unsigned_download_url(source, options = {})
81
+
76
82
  type = options.delete(:type)
77
83
 
78
84
  options[:fetch_format] ||= options.delete(:format) if type == :fetch
@@ -81,7 +87,6 @@ class Cloudinary::Utils
81
87
  resource_type = options.delete(:resource_type) || "image"
82
88
  version = options.delete(:version)
83
89
  format = options.delete(:format)
84
-
85
90
  cloud_name = options.delete(:cloud_name) || Cloudinary.config.cloud_name || raise("Must supply cloud_name in tag or in configuration")
86
91
  secure = options.delete(:secure)
87
92
  ssl_detected = options.delete(:ssl_detected)
@@ -94,6 +99,7 @@ class Cloudinary::Utils
94
99
 
95
100
  original_source = source
96
101
  return original_source if source.blank?
102
+ source = source.to_s
97
103
  if !force_remote
98
104
  return original_source if (type.nil? || type == :asset) && source.match(%r(^https?:/)i)
99
105
  if source.start_with?("/")
@@ -120,7 +126,7 @@ class Cloudinary::Utils
120
126
  elsif !format.blank?
121
127
  source = "#{source}.#{format}"
122
128
  end
123
-
129
+
124
130
  if cloud_name.start_with?("/")
125
131
  prefix = "/res" + cloud_name
126
132
  else
@@ -178,11 +184,20 @@ class Cloudinary::Utils
178
184
  authenticated_distribution = options[:authenticated_distribution] || Cloudinary.config.authenticated_distribution || raise("Must supply authenticated_distribution")
179
185
  @signers ||= Hash.new{|h,k| path, id = k; h[k] = AwsCfSigner.new(path, id)}
180
186
  signer = @signers[[aws_private_key_path, aws_key_pair_id]]
181
- url = Cloudinary::Utils.cloudinary_url(public_id, {:type=>:authenticated}.merge(options).merge(:secure=>true, :secure_distribution=>authenticated_distribution, :private_cdn=>true))
187
+ url = Cloudinary::Utils.unsigned_download_url(public_id, {:type=>:authenticated}.merge(options).merge(:secure=>true, :secure_distribution=>authenticated_distribution, :private_cdn=>true))
182
188
  expires_at = options[:expires_at] || (Time.now+3600)
183
189
  signer.sign(url, :ending => expires_at)
184
190
  end
185
191
 
192
+ def self.cloudinary_url(public_id, options = {})
193
+ if options[:type].to_s == 'authenticated'
194
+ result = signed_download_url(public_id, options)
195
+ else
196
+ result = unsigned_download_url(public_id, options)
197
+ end
198
+ return result
199
+ end
200
+
186
201
  def self.asset_file_name(path)
187
202
  data = Rails.root.join(path).read(:mode=>"rb")
188
203
  ext = path.extname
@@ -232,10 +247,12 @@ class Cloudinary::Utils
232
247
  end
233
248
  end
234
249
 
235
- IMAGE_FORMATS = %w(bmp png tif tiff jpg jpeg gif pdf ico)
250
+ IMAGE_FORMATS = %w(bmp png tif tiff jpg jpeg gif pdf ico eps)
236
251
 
237
252
  def self.supported_image_format?(format)
238
- IMAGE_FORMATS.include?(format.to_s.downcase)
253
+ format = format.to_s.downcase
254
+ extension = format =~ /\./ ? format.split('.').last : format
255
+ IMAGE_FORMATS.include?(extension)
239
256
  end
240
257
 
241
258
  def self.resource_type_for_format(format)
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.0.37"
3
+ VERSION = "1.0.38"
4
4
  end
data/spec/utils_spec.rb CHANGED
@@ -310,4 +310,18 @@ describe Cloudinary::Utils do
310
310
  result.should == "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test"
311
311
  end
312
312
 
313
+ it "should support border" do
314
+ options = {"border"=>{:width=>5}}
315
+ result = Cloudinary::Utils.cloudinary_url("test", options)
316
+ options.should == {}
317
+ result.should == "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_black/test"
318
+ options = {"border"=>{:width=>5, :color=>"#ffaabbdd"}}
319
+ result = Cloudinary::Utils.cloudinary_url("test", options)
320
+ options.should == {}
321
+ result.should == "http://res.cloudinary.com/test123/image/upload/bo_5px_solid_rgb:ffaabbdd/test"
322
+ options = {"border"=>"1px_solid_blue"}
323
+ result = Cloudinary::Utils.cloudinary_url("test", options)
324
+ options.should == {}
325
+ result.should == "http://res.cloudinary.com/test123/image/upload/bo_1px_solid_blue/test"
326
+ end
313
327
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.37
4
+ version: 1.0.38
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-09-12 00:00:00.000000000 Z
14
+ date: 2012-10-02 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client