cloudinary 1.0.26 → 1.0.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -114,7 +114,7 @@ module CloudinaryHelper
114
114
  end
115
115
 
116
116
  def cloudinary_url(source, options = {})
117
- options[:secure] = request.ssl? if !options.include?(:secure) && defined?(request) && request && request.respond_to?(:ssl?)
117
+ options[:ssl_detected] = request.ssl? if defined?(request) && request && request.respond_to?(:ssl?)
118
118
  Cloudinary::Utils.cloudinary_url(source, options)
119
119
  end
120
120
 
@@ -143,6 +143,15 @@ module CloudinaryHelper
143
143
  content_tag("input", nil, tag_options)
144
144
  end
145
145
 
146
+ def cl_private_download_url(public_id, format, options = {})
147
+ api_key = options[:api_key] || Cloudinary.config.api_key || raise("Must supply api_key")
148
+ api_secret = options[:api_secret] || Cloudinary.config.api_secret || raise("Must supply api_secret")
149
+ cloudinary_params = {:timestamp=>Time.now.to_i, :public_id=>public_id, :format=>format}.reject{|k, v| v.blank?}
150
+ cloudinary_params[:signature] = Cloudinary::Utils.api_sign_request(cloudinary_params, api_secret)
151
+ cloudinary_params[:api_key] = api_key
152
+ return Cloudinary::Utils.cloudinary_api_url("download", options) + "?" + cloudinary_params.to_query
153
+ end
154
+
146
155
  def self.included(base)
147
156
  ActionView::Helpers::FormBuilder.send(:include, Cloudinary::FormBuilder)
148
157
  end
@@ -11,6 +11,7 @@ class Cloudinary::Uploader
11
11
  :callback=> options[:callback],
12
12
  :format=>options[:format],
13
13
  :type=>options[:type],
14
+ :backup=>options[:backup],
14
15
  :tags=>options[:tags] && Cloudinary::Utils.build_array(options[:tags]).join(",")}
15
16
  if options[:eager]
16
17
  params[:eager] = Cloudinary::Utils.build_array(options[:eager]).map do
@@ -116,9 +117,9 @@ class Cloudinary::Uploader
116
117
 
117
118
  result = nil
118
119
 
119
- api_url = Cloudinary::Utils.cloudinary_api_url(action, {:resource_type => options.delete(:resource_type), :upload_prefix => options.delete(:upload_prefix)})
120
+ api_url = Cloudinary::Utils.cloudinary_api_url(action, options)
120
121
 
121
- RestClient::Request.execute(:method => :post, :url => api_url, :payload => params.reject{|k, v| v.blank?}, :timeout=>60) do
122
+ RestClient::Request.execute(:method => :post, :url => api_url, :payload => params.reject{|k, v| v.nil? || v==""}, :timeout=>60) do
122
123
  |response, request, tmpresult|
123
124
  raise "Server returned unexpected status code - #{response.code} - #{response.body}" if ![200,400,500].include?(response.code)
124
125
  begin
@@ -11,13 +11,13 @@ class Cloudinary::Utils
11
11
  options[:width], options[:height] = size.split("x") if size
12
12
  width = options[:width]
13
13
  height = options[:height]
14
- has_overlay = !options[:overlay].blank?
14
+ has_layer = !options[:overlay].blank? || !options[:underlay].blank?
15
15
 
16
- options.delete(:width) if width && (width.to_f < 1 || has_overlay)
17
- options.delete(:height) if height && (height.to_f < 1 || has_overlay)
16
+ options.delete(:width) if width && (width.to_f < 1 || has_layer)
17
+ options.delete(:height) if height && (height.to_f < 1 || has_layer)
18
18
 
19
19
  crop = options.delete(:crop)
20
- width=height=nil if crop.nil? && !has_overlay
20
+ width=height=nil if crop.nil? && !has_layer
21
21
 
22
22
  background = options.delete(:background)
23
23
  background = background.sub(/^#/, 'rgb:') if background
@@ -37,7 +37,7 @@ class Cloudinary::Utils
37
37
  effect = Array(effect).flatten.join(":") if effect.is_a?(Array) || effect.is_a?(Hash)
38
38
 
39
39
  params = {:w=>width, :h=>height, :t=>named_transformation, :c=>crop, :b=>background, :e=>effect}
40
- { :x=>:x, :y=>:y, :r=>:radius, :d=>:default_image, :g=>:gravity, :q=>:quality, :p=>:prefix, :a=>:angle, :l=>:overlay, :f=>:fetch_format }.each do
40
+ { :x=>:x, :y=>:y, :r=>:radius, :d=>:default_image, :g=>:gravity, :q=>:quality, :p=>:prefix, :a=>:angle, :l=>:overlay, :u=>:underlay, :f=>:fetch_format }.each do
41
41
  |param, option|
42
42
  params[param] = options.delete(option)
43
43
  end
@@ -48,8 +48,12 @@ class Cloudinary::Utils
48
48
  (base_transformations << transformation).reject(&:blank?).join("/")
49
49
  end
50
50
 
51
+ def self.api_string_to_sign(params_to_sign)
52
+ params_to_sign.map{|k,v| [k.to_s, v.is_a?(Array) ? v.join(",") : v]}.reject{|k,v| v.nil? || v == ""}.sort_by(&:first).map{|k,v| "#{k}=#{v}"}.join("&")
53
+ end
54
+
51
55
  def self.api_sign_request(params_to_sign, api_secret)
52
- to_sign = params_to_sign.reject{|k,v| v.blank?}.map{|k,v| [k.to_s, v.is_a?(Array) ? v.join(",") : v]}.sort_by(&:first).map{|k,v| "#{k}=#{v}"}.join("&")
56
+ to_sign = api_string_to_sign(params_to_sign)
53
57
  Digest::SHA1.hexdigest("#{to_sign}#{api_secret}")
54
58
  end
55
59
 
@@ -64,8 +68,10 @@ class Cloudinary::Utils
64
68
  version = options.delete(:version)
65
69
  format = options.delete(:format)
66
70
 
67
- cloud_name = options.delete(:cloud_name) || Cloudinary.config.cloud_name || raise("Must supply cloud_name in tag or in configuration")
68
- secure = options.delete(:secure) || Cloudinary.config.secure
71
+ cloud_name = options.delete(:cloud_name) || Cloudinary.config.cloud_name || raise("Must supply cloud_name in tag or in configuration")
72
+ secure = options.delete(:secure)
73
+ ssl_detected = options.delete(:ssl_detected)
74
+ secure = ssl_detected || Cloudinary.config.secure if secure.nil?
69
75
  private_cdn = options.delete(:private_cdn) || Cloudinary.config.private_cdn
70
76
  secure_distribution = options.delete(:secure_distribution) || Cloudinary.config.secure_distribution
71
77
  force_remote = options.delete(:force_remote)
@@ -123,7 +129,7 @@ class Cloudinary::Utils
123
129
 
124
130
  def self.cloudinary_api_url(action = 'upload', options = {})
125
131
  cloudinary = options[:upload_prefix] || Cloudinary.config.upload_prefix || "https://api.cloudinary.com"
126
- cloud_name = Cloudinary.config.cloud_name || raise("Must supply cloud_name")
132
+ cloud_name = options[:cloud_name] || Cloudinary.config.cloud_name || raise("Must supply cloud_name")
127
133
  resource_type = options[:resource_type] || "image"
128
134
  return [cloudinary, "v1_1", cloud_name, resource_type, action].join("/")
129
135
  end
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.0.26"
3
+ VERSION = "1.0.27"
4
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,5 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
- # loaded once.
5
- #
6
1
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
2
  RSpec.configure do |config|
8
3
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
4
  config.run_all_when_everything_filtered = true
10
- config.filter_run :focus
11
5
  end
data/spec/utils_spec.rb CHANGED
@@ -8,6 +8,7 @@ describe Cloudinary::Utils do
8
8
  config.cloud_name = "test123"
9
9
  config.secure_distribution = nil
10
10
  config.private_cdn = false
11
+ config.secure = false
11
12
  end
12
13
  end
13
14
 
@@ -192,13 +193,6 @@ describe Cloudinary::Utils do
192
193
  result.should == "http://res.cloudinary.com/test123/image/upload/a_55/test"
193
194
  end
194
195
 
195
- it "should support overlay" do
196
- options = {:overlay=>"text:hello"}
197
- result = Cloudinary::Utils.cloudinary_url("test", options)
198
- options.should == {}
199
- result.should == "http://res.cloudinary.com/test123/image/upload/l_text:hello/test"
200
- end
201
-
202
196
  it "should support format for fetch urls" do
203
197
  options = {:format=>"jpg", :type=>:fetch}
204
198
  result = Cloudinary::Utils.cloudinary_url("http://cloudinary.com/images/logo.png", options)
@@ -227,11 +221,42 @@ describe Cloudinary::Utils do
227
221
  result.should == "http://res.cloudinary.com/test123/image/upload/e_sepia:10/test"
228
222
  end
229
223
 
230
- it "should not pass width/height to html for overlay" do
231
- options = {:overlay=>"text:hello", :height=>100, :width=>100}
224
+ {:overlay=>:l, :underlay=>:u}.each do |param, letter|
225
+ it "should support #{param}" do
226
+ options = {param=>"text:hello"}
227
+ result = Cloudinary::Utils.cloudinary_url("test", options)
228
+ options.should == {}
229
+ result.should == "http://res.cloudinary.com/test123/image/upload/#{letter}_text:hello/test"
230
+ end
231
+
232
+ it "should not pass width/height to html for #{param}" do
233
+ options = {param=>"text:hello", :height=>100, :width=>100}
234
+ result = Cloudinary::Utils.cloudinary_url("test", options)
235
+ options.should == {}
236
+ result.should == "http://res.cloudinary.com/test123/image/upload/h_100,#{letter}_text:hello,w_100/test"
237
+ end
238
+ end
239
+
240
+ it "should use ssl_detected if secure is not given as parameter and not set to true in configuration" do
241
+ options = {:ssl_detected=>true}
232
242
  result = Cloudinary::Utils.cloudinary_url("test", options)
233
243
  options.should == {}
234
- result.should == "http://res.cloudinary.com/test123/image/upload/h_100,l_text:hello,w_100/test"
235
- end
236
-
244
+ result.should == "https://d3jpl91pxevbkh.cloudfront.net/test123/image/upload/test"
245
+ end
246
+
247
+ it "should use secure if given over ssl_detected and configuration" do
248
+ options = {:ssl_detected=>true, :secure=>false}
249
+ Cloudinary.config.secure = true
250
+ result = Cloudinary::Utils.cloudinary_url("test", options)
251
+ options.should == {}
252
+ result.should == "http://res.cloudinary.com/test123/image/upload/test"
253
+ end
254
+
255
+ it "should use secure: true from configuration over ssl_detected" do
256
+ options = {:ssl_detected=>false}
257
+ Cloudinary.config.secure = true
258
+ result = Cloudinary::Utils.cloudinary_url("test", options)
259
+ options.should == {}
260
+ result.should == "https://d3jpl91pxevbkh.cloudfront.net/test123/image/upload/test"
261
+ end
237
262
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.26
5
+ version: 1.0.27
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nadav Soferman
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-06-08 00:00:00 +03:00
15
+ date: 2012-06-26 00:00:00 +03:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency