cloudinary 1.9.1 → 1.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  4. data/.github/pull_request_template.md +24 -0
  5. data/.gitignore +7 -1
  6. data/.travis.yml +15 -8
  7. data/CHANGELOG.md +261 -0
  8. data/README.md +3 -0
  9. data/Rakefile +3 -45
  10. data/cloudinary.gemspec +27 -20
  11. data/lib/active_storage/blob_key.rb +20 -0
  12. data/lib/active_storage/service/cloudinary_service.rb +249 -0
  13. data/lib/cloudinary.rb +53 -63
  14. data/lib/cloudinary/account_api.rb +231 -0
  15. data/lib/cloudinary/account_config.rb +30 -0
  16. data/lib/cloudinary/api.rb +228 -71
  17. data/lib/cloudinary/auth_token.rb +10 -4
  18. data/lib/cloudinary/base_api.rb +79 -0
  19. data/lib/cloudinary/base_config.rb +70 -0
  20. data/lib/cloudinary/cache.rb +38 -0
  21. data/lib/cloudinary/cache/breakpoints_cache.rb +31 -0
  22. data/lib/cloudinary/cache/key_value_cache_adapter.rb +25 -0
  23. data/lib/cloudinary/cache/rails_cache_adapter.rb +34 -0
  24. data/lib/cloudinary/cache/storage/rails_cache_storage.rb +5 -0
  25. data/lib/cloudinary/carrier_wave.rb +4 -2
  26. data/lib/cloudinary/carrier_wave/remote.rb +3 -2
  27. data/lib/cloudinary/carrier_wave/storage.rb +2 -1
  28. data/lib/cloudinary/{controller.rb → cloudinary_controller.rb} +3 -5
  29. data/lib/cloudinary/config.rb +43 -0
  30. data/lib/cloudinary/helper.rb +77 -7
  31. data/lib/cloudinary/migrator.rb +3 -1
  32. data/lib/cloudinary/railtie.rb +7 -3
  33. data/lib/cloudinary/responsive.rb +111 -0
  34. data/lib/cloudinary/uploader.rb +67 -15
  35. data/lib/cloudinary/utils.rb +324 -54
  36. data/lib/cloudinary/version.rb +1 -1
  37. data/lib/cloudinary/video_helper.rb +96 -22
  38. data/lib/tasks/cloudinary/fetch_assets.rake +48 -0
  39. data/lib/tasks/{cloudinary.rake → cloudinary/sync_static.rake} +0 -0
  40. data/tools/allocate_test_cloud.sh +9 -0
  41. data/tools/get_test_cloud.sh +9 -0
  42. data/tools/update_version +220 -0
  43. data/vendor/assets/javascripts/cloudinary/jquery.cloudinary.js +51 -13
  44. data/vendor/assets/javascripts/cloudinary/jquery.fileupload.js +24 -4
  45. data/vendor/assets/javascripts/cloudinary/jquery.ui.widget.js +741 -561
  46. data/vendor/assets/javascripts/cloudinary/load-image.all.min.js +1 -1
  47. metadata +92 -67
  48. data/spec/access_control_spec.rb +0 -99
  49. data/spec/api_spec.rb +0 -545
  50. data/spec/archive_spec.rb +0 -129
  51. data/spec/auth_token_spec.rb +0 -79
  52. data/spec/cloudinary_helper_spec.rb +0 -190
  53. data/spec/cloudinary_spec.rb +0 -32
  54. data/spec/data/sync_static/app/assets/javascripts/1.coffee +0 -1
  55. data/spec/data/sync_static/app/assets/javascripts/1.js +0 -1
  56. data/spec/data/sync_static/app/assets/stylesheets/1.css +0 -3
  57. data/spec/docx.docx +0 -0
  58. data/spec/favicon.ico +0 -0
  59. data/spec/logo.png +0 -0
  60. data/spec/rake_spec.rb +0 -160
  61. data/spec/sample_asset_file.tsv +0 -4
  62. data/spec/search_spec.rb +0 -109
  63. data/spec/spec_helper.rb +0 -245
  64. data/spec/storage_spec.rb +0 -44
  65. data/spec/streaminig_profiles_api_spec.rb +0 -74
  66. data/spec/support/helpers/temp_file_helpers.rb +0 -22
  67. data/spec/support/shared_contexts/rake.rb +0 -19
  68. data/spec/uploader_spec.rb +0 -363
  69. data/spec/utils_methods_spec.rb +0 -54
  70. data/spec/utils_spec.rb +0 -906
  71. data/spec/video_tag_spec.rb +0 -251
  72. data/spec/video_url_spec.rb +0 -164
@@ -1,251 +0,0 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require 'cloudinary'
4
- require 'action_view'
5
- require 'cloudinary/helper'
6
- require 'rails/version'
7
-
8
- if ::Rails::VERSION::MAJOR < 4
9
- def config
10
- @config ||= {}
11
- end
12
- def controller
13
- @controller ||={}
14
- end
15
- end
16
- describe CloudinaryHelper do
17
- before :all do
18
- # Test the helper in the context it runs in in production
19
- ActionView::Base.send :include, CloudinaryHelper
20
-
21
- end
22
- before(:each) do
23
- Cloudinary.config do |config|
24
- config.cloud_name = "test123"
25
- config.secure_distribution = nil
26
- config.private_cdn = false
27
- config.secure = false
28
- config.cname = nil
29
- config.cdn_subdomain = false
30
- config.api_key = "1234"
31
- config.api_secret = "b"
32
- end
33
- end
34
-
35
- let(:helper) {
36
- ActionView::Base.new
37
- }
38
- let(:root_path) { "http://res.cloudinary.com/test123" }
39
- let(:upload_path) { "#{root_path}/video/upload" }
40
-
41
- describe 'cl_video_tag' do
42
- let(:basic_options) { { :cloud_name => "test123"} }
43
- let(:options) { basic_options }
44
- let(:test_tag) { TestTag.new helper.cl_video_tag("movie", options) }
45
- context "when options include video tag attributes" do
46
- let(:options) { basic_options.merge({ :autoplay => true,
47
- :controls => true,
48
- :loop => true,
49
- :muted => true,
50
- :preload => true }) }
51
- it "should support video tag parameters" do
52
- expect(test_tag.attributes.keys).to include("autoplay", "controls", "loop", "muted", "preload")
53
- end
54
- end
55
-
56
- context 'when given transformations' do
57
- let(:options) {
58
- basic_options.merge(
59
- :source_types => "mp4",
60
- :html_height => "100",
61
- :html_width => "200",
62
- :crop => :scale,
63
- :height => "200",
64
- :width => "400",
65
- :video_codec => { :codec => 'h264' },
66
- :audio_codec => 'acc',
67
- :start_offset => 3) }
68
-
69
- it 'should create a tag with "src" attribute that includes the transformations' do
70
- expect(test_tag["src"]).to be_truthy
71
- expect(test_tag["src"]).to include("ac_acc")
72
- expect(test_tag["src"]).to include("vc_h264")
73
- expect(test_tag["src"]).to include("so_3")
74
- expect(test_tag["src"]).to include("w_400")
75
- expect(test_tag["src"]).to include("h_200")
76
- end
77
- it 'should have the correct tag height' do
78
- expect(test_tag["src"]).to include("ac_acc")
79
- expect(test_tag["height"]).to eq("100")
80
- end
81
- end
82
-
83
- describe ":source_types" do
84
- context "when a single source type is provided" do
85
- let(:options) { basic_options.merge(:source_types => "mp4") }
86
- it "should create a video tag" do
87
- expect(test_tag.name).to eq("video")
88
- expect(test_tag['src']).to eq( "#{upload_path}/movie.mp4")
89
- end
90
- it "should not have a `type` attribute" do
91
- expect(test_tag.attributes).not_to include("type")
92
- end
93
- it "should not have inner `source` tags" do
94
- expect(test_tag.children.map(&:name)).not_to include("source")
95
- end
96
- end
97
-
98
- context 'when provided with multiple source types' do
99
- let(:options) { basic_options.merge(:source_types => %w(mp4 webm ogv)) }
100
- it "should create a tag with multiple source tags" do
101
- expect(test_tag.children.length).to eq(3)
102
- expect(test_tag.children[0].name).to eq("source")
103
- expect(test_tag.children[1].name).to eq("source")
104
- expect(test_tag.children.map{|c| c['src']}).to all( include("video/upload"))
105
- end
106
- it "should order the source tags according to the order of the source_types" do
107
- expect(test_tag.children[0][:type]).to eq("video/mp4")
108
- expect(test_tag.children[1][:type]).to eq("video/webm")
109
- expect(test_tag.children[2][:type]).to eq("video/ogg")
110
- end
111
- end
112
- end
113
-
114
- describe ":poster" do
115
- context "when poster is not provided" do
116
- it "should default to jpg with the video transformation" do
117
- expect(test_tag[:poster]).to eq(helper.cl_video_thumbnail_path("movie", { :format => 'jpg' }))
118
- end
119
- end
120
-
121
- context "when given a string" do
122
- let(:options) { basic_options.merge(:poster => TEST_IMAGE_URL) }
123
- it "should include a poster attribute with the given string as url" do
124
- expect(test_tag.attributes).to include('poster')
125
- expect(test_tag[:poster]).to eq(TEST_IMAGE_URL)
126
- end
127
- end
128
-
129
- context "when poster is a hash" do
130
- let(:options) { basic_options.merge(:poster => { :gravity => "north" }) }
131
- it "should include a poster attribute with the given options" do
132
- expect(test_tag[:poster]).to eq("#{upload_path}/g_north/movie.jpg")
133
- end
134
- context "when a public id is provided" do
135
- let(:options) { basic_options.merge(:poster => { :public_id => 'myposter.jpg', :gravity => "north" }) }
136
- it "should include a poster attribute with an image path and the given options" do
137
- expect(test_tag[:poster]).to eq("#{root_path}/image/upload/g_north/myposter.jpg")
138
- end
139
-
140
-
141
- end
142
- end
143
-
144
- context "when poster parameter is nil or false" do
145
- let(:options) { basic_options.merge(:poster => nil) }
146
- it "should not include a poster attribute in the tag for nil" do
147
- expect(test_tag.attributes).not_to include('poster')
148
- end
149
- let(:options) { basic_options.merge(:poster => false) }
150
- it "should not include a poster attribute in the tag for false" do
151
- expect(test_tag.attributes).not_to include('poster')
152
- end
153
- end
154
- end
155
-
156
- context ":source_transformation" do
157
- let(:options) { basic_options.merge(:source_types => %w(mp4 webm),
158
- :source_transformation => { 'mp4' => { 'quality' => 70 },
159
- 'webm' => { 'quality' => 30 } }
160
- ) }
161
- it "should produce the specific transformation for each type" do
162
- expect(test_tag.children_by_type("video/mp4")[0][:src]).to include("q_70")
163
- expect(test_tag.children_by_type("video/webm")[0][:src]).to include("q_30")
164
- end
165
-
166
- end
167
-
168
- describe ':fallback_content' do
169
- context 'when given fallback_content parameter' do
170
- let(:fallback) { "<span id=\"spanid\">Cannot display video</span>" }
171
- let(:options) { basic_options.merge(:fallback_content => fallback) }
172
- it "should include fallback content in the tag" do
173
- expect(test_tag.children).to include(TestTag.new(fallback))
174
- end
175
- end
176
-
177
- context "when given a block" do
178
- let(:test_tag) do
179
- # Actual code being tested ----------------
180
- html = helper.cl_video_tag("movie", options) do
181
- "Cannot display video!"
182
- end
183
- # -----------------------------------
184
- TestTag.new(html)
185
- end
186
- it 'should treat the block return value as fallback content' do
187
- expect(test_tag.children).to include("Cannot display video!")
188
- end
189
- end
190
- describe "dimensions" do
191
- context "when `:crop => 'fit'`" do
192
- let(:options) { basic_options.merge(:crop => 'fit') }
193
- it "should not include a width and height attributes" do
194
- expect(test_tag.attributes.keys).not_to include("width", "height")
195
- end
196
- end
197
- context "when `:crop => 'limit'`" do
198
- let(:options) { basic_options.merge(:crop => 'limit') }
199
- it "should not include a width and height attributes" do
200
- expect(test_tag.attributes.keys).not_to include("width", "height")
201
- end
202
- end
203
- end
204
- end
205
- end
206
- describe 'cl_video_thumbnail_path' do
207
- let(:source) { "movie_id" }
208
- let(:options) { {} }
209
- let(:path) { helper.cl_video_thumbnail_path(source, options) }
210
- it "should generate a cloudinary URI to the video thumbnail" do
211
- expect(path).to eq("#{upload_path}/movie_id.jpg")
212
- end
213
- end
214
- describe 'cl_video_thumbnail_tag' do
215
- let(:source) { "movie_id" }
216
- let(:options) { {} }
217
- let(:result_tag) { TestTag.new(helper.cl_video_thumbnail_tag(source, options)) }
218
- describe ":resource_type" do
219
- context "'video' (default)" do
220
- let(:options) { { :resource_type => 'video' } }
221
- it "should have a 'video/upload' path" do
222
- expect(result_tag.name).to eq('img')
223
- expect(result_tag[:src]).to include("video/upload")
224
- end
225
- it "should generate an img tag with file extension `jpg`" do
226
- expect(result_tag[:src]).to end_with("movie_id.jpg")
227
- end
228
- end
229
- context "'image'" do
230
- let(:options) { { :resource_type => 'image' } }
231
- it "should have a 'image/upload' path" do
232
- expect(result_tag.name).to eq('img')
233
- expect(result_tag[:src]).to include("image/upload")
234
- end
235
- it "should generate an img tag with file extension `jpg`" do
236
- expect(result_tag[:src]).to end_with("movie_id.jpg")
237
- end
238
- end
239
- context "'raw'" do
240
- let(:options) { { :resource_type => 'raw' } }
241
- it "should have a 'raw/upload' path" do
242
- expect(result_tag.name).to eq('img')
243
- expect(result_tag[:src]).to include("raw/upload")
244
- end
245
- it "should generate an img tag with file extension `jpg`" do
246
- expect(result_tag[:src]).to end_with("movie_id.jpg")
247
- end
248
- end
249
- end
250
- end
251
- end
@@ -1,164 +0,0 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require 'cloudinary'
4
- require 'action_view'
5
- require 'cloudinary/helper'
6
- require 'action_view/test_case'
7
-
8
- describe Cloudinary::Utils do
9
- before(:each) do
10
- Cloudinary.config do |config|
11
- config.cloud_name = "test123"
12
- config.secure_distribution = nil
13
- config.private_cdn = false
14
- config.secure = false
15
- config.cname = nil
16
- config.cdn_subdomain = false
17
- config.api_key = "1234"
18
- config.api_secret = "b"
19
- end
20
- end
21
- let(:root_path) { "http://res.cloudinary.com/test123" }
22
- let(:upload_path) { "#{root_path}/video/upload" }
23
-
24
- describe "cloudinary_url" do
25
- context ":video_codec" do
26
- it 'should support a string value' do
27
- expect(["video_id", { :resource_type => 'video', :video_codec => 'auto' }])
28
- .to produce_url("#{upload_path}/vc_auto/video_id")
29
- .and empty_options
30
- end
31
- it 'should support a hash value' do
32
- expect(["video_id", {
33
- :resource_type => 'video',
34
- :video_codec => {
35
- :codec => 'h264',
36
- :profile => 'basic',
37
- :level => '3.1'
38
- }
39
- }])
40
- .to produce_url("#{upload_path}/vc_h264:basic:3.1/video_id")
41
- .and empty_options
42
- end
43
- end
44
- context ":audio_codec" do
45
- it 'should support a string value' do
46
- expect(["video_id", { :resource_type => 'video', :audio_codec => 'acc' }])
47
- .to produce_url("#{upload_path}/ac_acc/video_id")
48
- .and empty_options
49
- end
50
- end
51
- context ":bit_rate" do
52
- it 'should support an integer value' do
53
- expect(["video_id", { :resource_type => 'video', :bit_rate => 2048 }])
54
- .to produce_url("#{upload_path}/br_2048/video_id")
55
- .and empty_options
56
- end
57
- it 'should support "<integer>k" ' do
58
- expect(["video_id", { :resource_type => 'video', :bit_rate => '44k' }])
59
- .to produce_url("#{upload_path}/br_44k/video_id")
60
- .and empty_options
61
- end
62
- it 'should support "<integer>m"' do
63
- expect(["video_id", { :resource_type => 'video', :bit_rate => '1m' }])
64
- .to produce_url("#{upload_path}/br_1m/video_id")
65
- .and empty_options
66
- end
67
- end
68
- context ":audio_frequency" do
69
- it 'should support an integer value' do
70
- expect(["video_id", { :resource_type => 'video', :audio_frequency => 44100 }])
71
- .to produce_url("#{upload_path}/af_44100/video_id")
72
- .and empty_options
73
- end
74
- end
75
- context ":video_sampling" do
76
- it "should support an integer value" do
77
- expect(["video_id", { :resource_type => 'video', :video_sampling => 20 }])
78
- .to produce_url("#{upload_path}/vs_20/video_id")
79
- .and empty_options
80
- end
81
- it "should support an string value in the a form of \"<float>s\"" do
82
- expect(["video_id", { :resource_type => 'video', :video_sampling => "2.3s" }])
83
- .to produce_url("#{upload_path}/vs_2.3s/video_id")
84
- .and empty_options
85
- end
86
- end
87
- { :so => :start_offset, :eo => :end_offset, :du => :duration }.each do |short, long|
88
- context ":#{long}" do
89
- it "should support decimal seconds " do
90
- expect(["video_id", { :resource_type => 'video', long => 2.63 }])
91
- .to produce_url("#{upload_path}/#{short}_2.63/video_id")
92
- .and empty_options
93
- expect(["video_id", { :resource_type => 'video', long => '2.63' }])
94
- .to produce_url("#{upload_path}/#{short}_2.63/video_id")
95
- .and empty_options
96
- end
97
- it 'should support percents of the video length as "<number>p"' do
98
- expect(["video_id", { :resource_type => 'video', long => '35p' }])
99
- .to produce_url("#{upload_path}/#{short}_35p/video_id")
100
- .and empty_options
101
- end
102
- it 'should support percents of the video length as "<number>%"' do
103
- expect(["video_id", { :resource_type => 'video', long => '35%' }])
104
- .to produce_url("#{upload_path}/#{short}_35p/video_id")
105
- .and empty_options
106
- end
107
- end
108
- end
109
-
110
- describe ":offset" do
111
- let(:test_url) { Cloudinary::Utils.cloudinary_url("video_id", options) }
112
- [
113
- ['string range', 'so_2.66,eo_3.21', '2.66..3.21'],
114
- ['array', 'so_2.66,eo_3.21', [2.66, 3.21]],
115
- ['range of floats', 'so_2.66,eo_3.21', 2.66..3.21],
116
- ['array of % strings', 'so_35p,eo_70p', %w(35% 70%)],
117
- ['array of p strings', 'so_35p,eo_70p', %w(35p 70p)],
118
- ['array of float percent', 'so_35.5p,eo_70.5p', %w(35.5p 70.5p)]
119
- ].each do |test|
120
- name, url_param, range = test
121
- context "when provided with #{name} #{range}" do
122
- let(:options) { { :resource_type => 'video', :offset => range } }
123
- it "should produce a range transformation in the format of #{url_param}" do
124
- expect { test_url }.to change { options }.to({})
125
- transformation = /([^\/]*)\/video_id$/.match(test_url)[1]
126
- # we can't rely on the order of the parameters so we sort them before comparing
127
- expect(transformation.split(',').sort.reverse.join(',')).to eq(url_param)
128
- end
129
- end
130
- end
131
- end
132
- context "when given existing relevant parameters: :quality, :background, :crop, :width, :height, :gravity, :overlay" do
133
-
134
- { :overlay => :l, :underlay => :u }.each do |param, letter|
135
- it "should support #{param}" do
136
- expect(["test", { :resource_type => 'video', param => "text:hello" }])
137
- .to produce_url("#{upload_path}/#{letter}_text:hello/test")
138
- .and empty_options
139
- end
140
-
141
- it "should not pass width/height to html for #{param}" do
142
- expect(["test", { :resource_type => 'video', param => "text:hello", :height => 100, :width => 100 }])
143
- .to produce_url("#{upload_path}/h_100,#{letter}_text:hello,w_100/test")
144
- .and empty_options
145
- end
146
- end
147
- it "should produce the transformation string" do
148
- expect(["test", { :resource_type => 'video', :background => "#112233" }])
149
- .to produce_url("#{upload_path}/b_rgb:112233/test")
150
- .and empty_options
151
- expect(["test", {
152
- :resource_type => 'video',
153
- :x => 1, :y => 2, :radius => 3,
154
- :gravity => :center,
155
- :quality => 0.4,
156
- :prefix => "a" }])
157
- .to produce_url("#{upload_path}/g_center,p_a,q_0.4,r_3,x_1,y_2/test")
158
- .and empty_options
159
-
160
- end
161
- end
162
- end
163
-
164
- end