cloudinary 1.0.67 → 1.0.68
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/cloudinary/api.rb +3 -3
- data/lib/cloudinary/engine.rb +1 -1
- data/lib/cloudinary/helper.rb +21 -21
- data/lib/cloudinary/railtie.rb +3 -0
- data/lib/cloudinary/uploader.rb +38 -0
- data/lib/cloudinary/version.rb +1 -1
- data/spec/api_spec.rb +13 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= Version 1.0.68 - 2014-02-16
|
2
|
+
* Support for uploading large raw files.
|
3
|
+
* Correct support for image_tag and image_path override.
|
4
|
+
* Add direction support to Admin API listings.
|
5
|
+
|
1
6
|
= Version 1.0.67 - 2014-01-09
|
2
7
|
* Support specifying face coordinates in upload API.
|
3
8
|
* Support specifying context (currently alt and caption) in upload API and returning context in API.
|
data/lib/cloudinary/api.rb
CHANGED
@@ -36,20 +36,20 @@ class Cloudinary::Api
|
|
36
36
|
type = options[:type]
|
37
37
|
uri = "resources/#{resource_type}"
|
38
38
|
uri += "/#{type}" if !type.blank?
|
39
|
-
call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context), options)
|
39
|
+
call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context, :direction), options)
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.resources_by_tag(tag, options={})
|
43
43
|
resource_type = options[:resource_type] || "image"
|
44
44
|
uri = "resources/#{resource_type}/tags/#{tag}"
|
45
|
-
call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context), options)
|
45
|
+
call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :direction), options)
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.resources_by_ids(public_ids, options={})
|
49
49
|
resource_type = options[:resource_type] || "image"
|
50
50
|
type = options[:type] || "upload"
|
51
51
|
uri = "resources/#{resource_type}/#{type}"
|
52
|
-
call_api(:get, uri, only(options, :tags, :context).merge(public_ids
|
52
|
+
call_api(:get, uri, only(options, :tags, :context).merge(:public_ids => public_ids), options)
|
53
53
|
end
|
54
54
|
|
55
55
|
def self.resource(public_id, options={})
|
data/lib/cloudinary/engine.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
class Cloudinary::Engine < Rails::Engine
|
1
|
+
class Cloudinary::Engine < Rails::Engine
|
2
2
|
end
|
data/lib/cloudinary/helper.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
module CloudinaryHelper
|
3
|
-
include ActionView::Helpers::AssetTagHelper
|
4
|
-
alias :original_image_tag :image_tag
|
5
|
-
alias :original_image_path :image_path
|
6
|
-
|
7
3
|
# Stand-in for Rails image_tag helper that accepts various options for transformations.
|
8
4
|
#
|
9
5
|
# source:: the public ID, possibly with a file type extension. If there is no extension, the
|
@@ -34,32 +30,24 @@ module CloudinaryHelper
|
|
34
30
|
options[:size] = options.delete(:html_size) if options.include?(:html_size)
|
35
31
|
options[:border] = options.delete(:html_border) if options.include?(:html_border)
|
36
32
|
|
37
|
-
|
33
|
+
image_tag_without_cloudinary(source, options)
|
38
34
|
end
|
39
35
|
|
40
36
|
# Works similarly to cl_image_tag, however just generates the URL of the image
|
41
37
|
def cl_image_path(source, options = {})
|
42
38
|
options = options.clone
|
43
39
|
url = cloudinary_url_internal(source, options)
|
44
|
-
|
40
|
+
image_path_without_cloudinary(url)
|
45
41
|
end
|
46
42
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
cl_image_tag(source, {:type=>:asset}.merge(options || {}))
|
51
|
-
else
|
52
|
-
original_image_tag(*args)
|
53
|
-
end
|
43
|
+
def image_tag_with_cloudinary(*args)
|
44
|
+
source, options = args
|
45
|
+
cl_image_tag(source, {:type=>:asset}.merge(options || {}))
|
54
46
|
end
|
55
47
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
cl_image_path(source, {:type=>:asset}.merge(options || {}))
|
60
|
-
else
|
61
|
-
original_image_path(*args)
|
62
|
-
end
|
48
|
+
def image_path_with_cloudinary(*args)
|
49
|
+
source, options = args
|
50
|
+
cl_image_path(source, {:type=>:asset}.merge(options || {}))
|
63
51
|
end
|
64
52
|
|
65
53
|
def fetch_image_tag(profile, options = {})
|
@@ -206,6 +194,15 @@ module CloudinaryHelper
|
|
206
194
|
|
207
195
|
def self.included(base)
|
208
196
|
ActionView::Helpers::FormBuilder.send(:include, Cloudinary::FormBuilder)
|
197
|
+
base.class_eval do
|
198
|
+
if defined?(Rails) && !Rails.version.start_with?("2") && Cloudinary.config.enhance_image_tag
|
199
|
+
alias_method_chain :image_tag, :cloudinary
|
200
|
+
alias_method_chain :image_path, :cloudinary
|
201
|
+
else
|
202
|
+
alias_method :image_tag_without_cloudinary, :image_tag
|
203
|
+
alias_method :image_path_without_cloudinary, :image_path
|
204
|
+
end
|
205
|
+
end
|
209
206
|
end
|
210
207
|
|
211
208
|
private
|
@@ -259,7 +256,10 @@ if defined? ActionView::Helpers::AssetUrlHelper
|
|
259
256
|
end
|
260
257
|
end
|
261
258
|
|
262
|
-
|
259
|
+
if defined?(Rails) && Rails.version.start_with?("2")
|
260
|
+
ActionView::Base.send :include, ActionView::Helpers::AssetTagHelper
|
261
|
+
ActionView::Base.send :include, CloudinaryHelper
|
262
|
+
end
|
263
263
|
|
264
264
|
begin
|
265
265
|
require 'sass-rails'
|
data/lib/cloudinary/railtie.rb
CHANGED
data/lib/cloudinary/uploader.rb
CHANGED
@@ -59,6 +59,44 @@ class Cloudinary::Uploader
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
# Upload large raw files. Note that public_id should include an extension for best results.
|
63
|
+
def self.upload_large(file, public_id, options={})
|
64
|
+
if file.is_a?(Pathname) || !file.respond_to?(:read)
|
65
|
+
file = File.open(file, "rb")
|
66
|
+
end
|
67
|
+
upload = upload_id = nil
|
68
|
+
index = 1
|
69
|
+
while !file.eof?
|
70
|
+
buffer = file.read(20_000_000)
|
71
|
+
upload = upload_large_part(Cloudinary::Blob.new(buffer), public_id, options.merge(:upload_id=>upload_id, :part_number=>index, :final=>file.eof?))
|
72
|
+
upload_id = upload["upload_id"]
|
73
|
+
index += 1
|
74
|
+
end
|
75
|
+
upload
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Upload large raw files. Note that public_id should include an extension for best results.
|
80
|
+
def self.upload_large_part(file, public_id, options={})
|
81
|
+
call_api("upload_large", options.merge(:resource_type=>:raw)) do
|
82
|
+
params = {
|
83
|
+
:timestamp=>Time.now.to_i,
|
84
|
+
:type=>options[:type],
|
85
|
+
:public_id=> public_id,
|
86
|
+
:backup=>options[:backup],
|
87
|
+
:final=>options[:final],
|
88
|
+
:part_number=>options[:part_number],
|
89
|
+
:upload_id=>options[:upload_id]
|
90
|
+
}
|
91
|
+
if file.is_a?(Pathname) || !file.respond_to?(:read)
|
92
|
+
params[:file] = File.open(file, "rb")
|
93
|
+
else
|
94
|
+
params[:file] = file
|
95
|
+
end
|
96
|
+
[params, [:file]]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
62
100
|
def self.destroy(public_id, options={})
|
63
101
|
call_api("destroy", options) do
|
64
102
|
{
|
data/lib/cloudinary/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -64,6 +64,19 @@ describe Cloudinary::Api do
|
|
64
64
|
resources.map{|resource| resource["tags"]}.should include(["api_test_tag"])
|
65
65
|
resources.map{|resource| resource["context"]}.should include({"custom" => {"key" => "value"}})
|
66
66
|
end
|
67
|
+
|
68
|
+
it "should allow listing resources in both directions" do
|
69
|
+
asc_resources = @api.resources(:type=>"upload", :prefix=>"api_test", :direction => "asc")["resources"]
|
70
|
+
desc_resources = @api.resources(:type=>"upload", :prefix=>"api_test", :direction => "desc")["resources"]
|
71
|
+
# NOTE: this assumes the full list fits in a page which is the case unless resources with 'api_test' prefix were
|
72
|
+
# uploaded to the account against which this test runs
|
73
|
+
asc_resources.reverse.should == desc_resources
|
74
|
+
asc_resources_alt = @api.resources(:type=>"upload", :prefix=>"api_test", :direction => 1)["resources"]
|
75
|
+
desc_resources_alt = @api.resources(:type=>"upload", :prefix=>"api_test", :direction => -1)["resources"]
|
76
|
+
asc_resources_alt.reverse.should == desc_resources_alt
|
77
|
+
asc_resources.should == asc_resources_alt
|
78
|
+
lambda{@api.resources(:type=>"upload", :prefix=>"api_test", :direction => "anythingelse")["resources"]}.should raise_error(Cloudinary::Api::BadRequest)
|
79
|
+
end
|
67
80
|
|
68
81
|
it "should allow get resource metadata" do
|
69
82
|
resource = @api.resource("api_test")
|
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.
|
4
|
+
version: 1.0.68
|
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: 2014-
|
14
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|