cloudinary 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/cloudinary/api.rb +20 -4
- data/lib/cloudinary/uploader.rb +1 -0
- data/lib/cloudinary/utils.rb +13 -5
- data/lib/cloudinary/version.rb +1 -1
- data/spec/api_spec.rb +22 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/uploader_spec.rb +12 -1
- data/spec/utils_spec.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 334dc407a90f5a0d121718d87976528ec216786c
|
4
|
+
data.tar.gz: e326b4b46e3a18c3bbe3367ad460d208f169972e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e163279980d8a009331cf45d5f946e8ac7579c4c2086ff15311ccd872eef6e9a19e43e66996de42b5a6a6a719b52e0b1e3f59d5d8a9fa54c18141f931b6608c0
|
7
|
+
data.tar.gz: 5a0cabe2f96432e09427c89e8b790bb3d68f345f34658867d991f8784cbda8a0bd76b04c9e92f4501a46ead871bfd53b54a7206a597ae5b424d59f054c0b8034
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
|
2
|
+
1.2.3 / 2016-08-21
|
3
|
+
==================
|
4
|
+
|
5
|
+
* Allow a string to be passed as eager transformation
|
6
|
+
* Add `delete_derived_by_transformation` to the Api methods.
|
7
|
+
* Support videos mode for url suffixes.
|
8
|
+
* Support url suffixes without private cdn
|
9
|
+
* Fix `values_match?`
|
10
|
+
|
2
11
|
1.2.2 / 2016-07-16
|
3
12
|
==================
|
4
13
|
|
data/lib/cloudinary/api.rb
CHANGED
@@ -126,6 +126,22 @@ class Cloudinary::Api
|
|
126
126
|
call_api(:delete, uri, { :derived_resource_ids => derived_resource_ids }, options)
|
127
127
|
end
|
128
128
|
|
129
|
+
# Delete derived resources identified by transformation for the provided public_ids
|
130
|
+
# @param [String|Array] public_ids The resources the derived resources belong to
|
131
|
+
# @param [String|Hash|Array] transformations the transformation(s) associated with the derived resources
|
132
|
+
# @param [Hash] options
|
133
|
+
# @option options [String] :resource_type ("image")
|
134
|
+
# @option options [String] :type ("upload")
|
135
|
+
def self.delete_derived_by_transformation(public_ids, transformations, options={})
|
136
|
+
resource_type = options[:resource_type] || "image"
|
137
|
+
type = options[:type] || "upload"
|
138
|
+
uri = "resources/#{resource_type}/#{type}"
|
139
|
+
params = {:public_ids => public_ids}.merge(only(options, :invalidate))
|
140
|
+
params[:keep_original] = true
|
141
|
+
params[:transformations] = Cloudinary::Utils.build_eager(transformations)
|
142
|
+
call_api(:delete, uri, params, options)
|
143
|
+
end
|
144
|
+
|
129
145
|
def self.tags(options={})
|
130
146
|
resource_type = options[:resource_type] || "image"
|
131
147
|
uri = "tags/#{resource_type}"
|
@@ -144,9 +160,9 @@ class Cloudinary::Api
|
|
144
160
|
call_api(:delete, "transformations/#{transformation_string(transformation)}", {}, options)
|
145
161
|
end
|
146
162
|
|
147
|
-
|
148
|
-
|
149
|
-
|
163
|
+
# updates - supports:
|
164
|
+
# "allowed_for_strict" boolean
|
165
|
+
# "unsafe_update" transformation params - updates a named transformation parameters without regenerating existing images
|
150
166
|
def self.update_transformation(transformation, updates, options={})
|
151
167
|
params = only(updates, :allowed_for_strict)
|
152
168
|
params[:unsafe_update] = transformation_string(updates[:unsafe_update]) if updates[:unsafe_update]
|
@@ -157,7 +173,7 @@ class Cloudinary::Api
|
|
157
173
|
call_api(:post, "transformations/#{name}", { :transformation => transformation_string(definition) }, options)
|
158
174
|
end
|
159
175
|
|
160
|
-
|
176
|
+
# upload presets
|
161
177
|
def self.upload_presets(options={})
|
162
178
|
call_api(:get, "upload_presets", only(options, :next_cursor, :max_results), options)
|
163
179
|
end
|
data/lib/cloudinary/uploader.rb
CHANGED
@@ -286,6 +286,7 @@ class Cloudinary::Uploader
|
|
286
286
|
api_url = Cloudinary::Utils.cloudinary_api_url(action, options)
|
287
287
|
headers = { "User-Agent" => Cloudinary::USER_AGENT }
|
288
288
|
headers['Content-Range'] = options[:content_range] if options[:content_range]
|
289
|
+
headers.merge!(options[:extra_headers]) if options[:extra_headers]
|
289
290
|
RestClient::Request.execute(:method => :post, :url => api_url, :payload => params.reject { |k, v| v.nil? || v=="" }, :timeout => timeout, :headers => headers) do
|
290
291
|
|response, request, tmpresult|
|
291
292
|
raise CloudinaryException, "Server returned unexpected status code - #{response.code} - #{response.body}" unless [200, 400, 401, 403, 404, 500].include?(response.code)
|
data/lib/cloudinary/utils.rb
CHANGED
@@ -316,8 +316,6 @@ class Cloudinary::Utils
|
|
316
316
|
url_suffix = options.delete(:url_suffix)
|
317
317
|
use_root_path = config_option_consume(options, :use_root_path)
|
318
318
|
|
319
|
-
raise(CloudinaryException, "URL Suffix only supported in private CDN") if url_suffix.present? and not private_cdn
|
320
|
-
|
321
319
|
original_source = source
|
322
320
|
return original_source if source.blank?
|
323
321
|
if defined?(CarrierWave::Uploader::Base) && source.is_a?(CarrierWave::Uploader::Base)
|
@@ -401,6 +399,9 @@ class Cloudinary::Utils
|
|
401
399
|
when resource_type.to_s == "raw" && type.to_s == "upload"
|
402
400
|
resource_type = "files"
|
403
401
|
type = nil
|
402
|
+
when resource_type.to_s == "video" && type.to_s == "upload"
|
403
|
+
resource_type = "videos"
|
404
|
+
type = nil
|
404
405
|
else
|
405
406
|
raise(CloudinaryException, "URL Suffix only supported for image/upload, image/private and raw/upload")
|
406
407
|
end
|
@@ -748,14 +749,21 @@ class Cloudinary::Utils
|
|
748
749
|
}
|
749
750
|
end
|
750
751
|
|
752
|
+
#
|
751
753
|
# @private
|
754
|
+
# @param [String|Hash|Array] an eager transformation can be a string or hash, with or without a format. The parameter also accepts an array of eager transformations.
|
752
755
|
def self.build_eager(eager)
|
753
756
|
return nil if eager.nil?
|
754
757
|
Cloudinary::Utils.build_array(eager).map do
|
755
758
|
|transformation, format|
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
+
unless transformation.is_a? String
|
760
|
+
transformation = transformation.clone
|
761
|
+
if transformation.respond_to?(:delete)
|
762
|
+
format = transformation.delete(:format) || format
|
763
|
+
end
|
764
|
+
transformation = Cloudinary::Utils.generate_transformation_string(transformation, true)
|
765
|
+
end
|
766
|
+
[transformation, format].compact.join("/")
|
759
767
|
end.join("|")
|
760
768
|
end
|
761
769
|
|
data/lib/cloudinary/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -125,6 +125,28 @@ describe Cloudinary::Api do
|
|
125
125
|
@api.delete_derived_resources(derived_resource_id)
|
126
126
|
end
|
127
127
|
|
128
|
+
it "should allow deleting derived resources by transformations" do
|
129
|
+
public_id = "public_id"
|
130
|
+
transformations = "c_crop,w_100"
|
131
|
+
expect(RestClient::Request).to receive(:execute).with(
|
132
|
+
deep_hash_value( {[:payload, :public_ids] => public_id,
|
133
|
+
[:payload, :transformations] => "c_crop,w_100"}))
|
134
|
+
@api.delete_derived_by_transformation(public_id, "c_crop,w_100")
|
135
|
+
|
136
|
+
transformations = {:crop => "crop", :width => 100}
|
137
|
+
expect(RestClient::Request).to receive(:execute).with(
|
138
|
+
deep_hash_value( {[:payload, :public_ids] => public_id,
|
139
|
+
[:payload, :transformations] => "c_crop,w_100"}))
|
140
|
+
@api.delete_derived_by_transformation(public_id, transformations)
|
141
|
+
|
142
|
+
transformations = [{:crop => "crop", :width => 100}, {:crop => "scale", :width => 300}]
|
143
|
+
expect(RestClient::Request).to receive(:execute).with(
|
144
|
+
deep_hash_value( {[:payload, :public_ids] => public_id,
|
145
|
+
[:payload, :transformations] => "c_crop,w_100|c_scale,w_300"}))
|
146
|
+
@api.delete_derived_by_transformation(public_id, transformations)
|
147
|
+
|
148
|
+
end
|
149
|
+
|
128
150
|
it "should allow deleting resources" do
|
129
151
|
expect(RestClient::Request).to receive(:execute).with(deep_hash_value( {[:payload, :public_ids] => ["apit_test", "test_id_2", "api_test3"]}))
|
130
152
|
@api.delete_resources(["apit_test", "test_id_2", "api_test3"])
|
data/spec/spec_helper.rb
CHANGED
@@ -166,7 +166,7 @@ end
|
|
166
166
|
RSpec::Matchers.define :deep_hash_value do |expected|
|
167
167
|
match do |actual|
|
168
168
|
expected.all? do |path, value|
|
169
|
-
Cloudinary.values_match? deep_fetch(actual, path)
|
169
|
+
Cloudinary.values_match? value, deep_fetch(actual, path)
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
@@ -175,7 +175,7 @@ RSpec::Matchers.alias_matcher :have_deep_hash_values_of, :deep_hash_value
|
|
175
175
|
|
176
176
|
module Cloudinary
|
177
177
|
# @api private
|
178
|
-
def self.values_match?( actual
|
178
|
+
def self.values_match?(expected, actual)
|
179
179
|
if Hash === actual
|
180
180
|
return hashes_match?(expected, actual) if Hash === expected
|
181
181
|
elsif Array === expected && Enumerable === actual && !(Struct === actual)
|
data/spec/uploader_spec.rb
CHANGED
@@ -83,7 +83,18 @@ describe Cloudinary::Uploader do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should support eager" do
|
86
|
-
Cloudinary::Uploader.upload(TEST_IMG, :eager =>[{ :crop =>"scale", :width =>"2.0"}], :tags => [TEST_TAG, TIMESTAMP_TAG])
|
86
|
+
result = Cloudinary::Uploader.upload(TEST_IMG, :eager =>[{ :crop =>"scale", :width =>"2.0"}], :tags => [TEST_TAG, TIMESTAMP_TAG])
|
87
|
+
expect(result["eager"].length).to be(1)
|
88
|
+
expect(result).to have_deep_hash_values_of(["eager", 0, "transformation"] => "c_scale,w_2.0")
|
89
|
+
result = Cloudinary::Uploader.upload(TEST_IMG, :eager =>"c_scale,w_2.0", :tags => [TEST_TAG, TIMESTAMP_TAG])
|
90
|
+
expect(result["eager"].length).to be(1)
|
91
|
+
expect(result).to have_deep_hash_values_of(["eager", 0, "transformation"] => "c_scale,w_2.0")
|
92
|
+
result = Cloudinary::Uploader.upload(TEST_IMG, :eager =>["c_scale,w_2.0", { :crop =>"crop", :width =>"0.5", :format => "tiff"}], :tags => [TEST_TAG, TIMESTAMP_TAG])
|
93
|
+
expect(result["eager"].length).to be(2)
|
94
|
+
expect(result).to have_deep_hash_values_of(
|
95
|
+
["eager", 0, "transformation"] => "c_scale,w_2.0",
|
96
|
+
["eager", 1, "transformation"] => "c_crop,w_0.5/tiff"
|
97
|
+
)
|
87
98
|
end
|
88
99
|
|
89
100
|
it "should support headers" do
|
data/spec/utils_spec.rb
CHANGED
@@ -87,8 +87,13 @@ describe Cloudinary::Utils do
|
|
87
87
|
.and empty_options
|
88
88
|
end
|
89
89
|
|
90
|
-
it "should
|
91
|
-
expect
|
90
|
+
it "should support url_suffix in shared distribution" do
|
91
|
+
expect(["test", { :url_suffix => "hello" }])
|
92
|
+
.to produce_url("http://res.cloudinary.com/#{cloud_name}/images/test/hello")
|
93
|
+
.and empty_options
|
94
|
+
expect(["test", { :url_suffix => "hello", :angle => 0 }])
|
95
|
+
.to produce_url("http://res.cloudinary.com/#{cloud_name}/images/a_0/test/hello")
|
96
|
+
.and empty_options
|
92
97
|
end
|
93
98
|
|
94
99
|
it "should disallow url_suffix in non upload types" do
|
@@ -133,6 +138,12 @@ describe Cloudinary::Utils do
|
|
133
138
|
.and empty_options
|
134
139
|
end
|
135
140
|
|
141
|
+
it "should support url_suffix for videos" do
|
142
|
+
expect(["test", { :url_suffix => "hello", :private_cdn => true, :resource_type => :video }])
|
143
|
+
.to produce_url("http://#{cloud_name}-res.cloudinary.com/videos/test/hello")
|
144
|
+
.and empty_options
|
145
|
+
end
|
146
|
+
|
136
147
|
it "should support url_suffix for private uploads" do
|
137
148
|
expect(["test", { :url_suffix => "hello", :private_cdn => true, :resource_type => :image, :type => :private }])
|
138
149
|
.to produce_url("http://#{cloud_name}-res.cloudinary.com/private_images/test/hello")
|
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.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nadav Soferman
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws_cf_signer
|