shrine-cloudinary 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6de8b3f92d35c28abfc92a7ee58478c31aae9e97
4
- data.tar.gz: a1ff3ab50a88b2342c3ca5d844a6301338986025
3
+ metadata.gz: 40214d8c6cb86f477773409ad1b2bd939c9cb781
4
+ data.tar.gz: e17dc751f371937e136ba2f915a6df65be6ed2e9
5
5
  SHA512:
6
- metadata.gz: 2367680d167b65e6b267423be706fa5377d555d130e7479c4dbef8bc32720d8cce2b1a10c5ba5a90fe22ae6af85421aca80a46c8aa73f2619fd407b01c38d6e7
7
- data.tar.gz: cc68b4752f574e4873b09c896e906da02815aac77844e3eea1023de5688a47914d2187ed723fde038f339eee281a45fea1624545c1ccc5e74a6b105a48a32fbe
6
+ metadata.gz: 9d57b2b9cb32ae0ad2f49084039ec26bc97143b657c06236f7fd452905d440b08cb983f0c2bbd12c99cb667f65abac9cd10900fc4e4a50d5998480bfdbda4b6d
7
+ data.tar.gz: fe772efa20d956fd9c867ba511276d8ec394d774b379aaa203802a756efce23465a6cfe7f41ea106f1b6a3fd1e7c5a3ff658698f75538c709587d9dfd6039ce1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Shrine::Cloudinary
1
+ # Shrine::Storage::Cloudinary
2
2
 
3
3
  Provides [Cloudinary] storage for [Shrine].
4
4
 
@@ -92,27 +92,6 @@ user.avatar_url(width: 0.2, crop: :scale)
92
92
 
93
93
  See [Rails image manipulation] for all URL options you can pass in.
94
94
 
95
- ### Large files
96
-
97
- If you're uploading large files with Cloudinary (like videos), you can take
98
- advantage of Cloudinary's special "chunked" upload API, by passing the filesize
99
- threshold after which the special API will be used:
100
-
101
- ```rb
102
- # Upload files larger than 100 MB using the "chunked" upload API
103
- Shrine::Storage::Cloudinary.new(large: 100*1024*1024)
104
- ```
105
-
106
- The default chunk size is 20 MB, but you can change that by passing
107
- `:chunk_size` to `:upload_options`:
108
-
109
- ```rb
110
- Shrine::Storage::Cloudinary.new(
111
- large: 100*1024*1024 # 100 MB
112
- upload_options: {chunk_size: 5*1024*1204} # 5 MB
113
- )
114
- ```
115
-
116
95
  ### Metadata
117
96
 
118
97
  If you decide to do incoming transformations (processing on upload),
@@ -147,8 +126,42 @@ user.avatar.metadata["cloudinary"] #=>
147
126
  # }
148
127
  ```
149
128
 
150
- If you're using the storage directly, `Shrine::Storage::Cloudinary#upload` will
151
- return this hash.
129
+ This is especially useful for saving [responsive breakpoints]. If you're using
130
+ the storage directly, `Shrine::Storage::Cloudinary#upload` will return this
131
+ hash.
132
+
133
+ ### Large files
134
+
135
+ If you're uploading large files with Cloudinary (like videos), you can take
136
+ advantage of Cloudinary's special "chunked" upload API, by passing the filesize
137
+ threshold after which the special API will be used:
138
+
139
+ ```rb
140
+ # Upload files larger than 100 MB using the "chunked" upload API
141
+ Shrine::Storage::Cloudinary.new(large: 100*1024*1024)
142
+ ```
143
+
144
+ The default chunk size is 20 MB, but you can change that by passing
145
+ `:chunk_size` to `:upload_options`:
146
+
147
+ ```rb
148
+ Shrine::Storage::Cloudinary.new(
149
+ large: 100*1024*1024 # 100 MB
150
+ upload_options: {chunk_size: 5*1024*1204} # 5 MB
151
+ )
152
+ ```
153
+
154
+ ### Updating
155
+
156
+ Sometimes you may want to apply actions to already uploaded files, e.g.
157
+ regenerate tranformations. This storage provides the `#update` method which
158
+ delegates to Cloudinary's [explicit API]:
159
+
160
+ ```rb
161
+ cloudinary = Shrine::Storage::Cloudinary.new
162
+ # ...
163
+ cloudinary.update("image.jpg", eager: {...})
164
+ ```
152
165
 
153
166
  ### Clearing storage
154
167
 
@@ -186,3 +199,5 @@ $ bundle exec rake test
186
199
  [Shrine]: https://github.com/janko-m/shrine
187
200
  [Cloudinary options]: http://cloudinary.com/documentation/upload_images#remote_upload
188
201
  [Rails image manipulation]: http://cloudinary.com/documentation/rails_image_manipulation
202
+ [responsive breakpoints]: http://cloudinary.com/blog/introducing_intelligent_responsive_image_breakpoints_solutions
203
+ [explicit API]: http://cloudinary.com/documentation/image_upload_api_reference#explicit
@@ -15,15 +15,15 @@ class Shrine
15
15
  @store_data = store_data
16
16
  end
17
17
 
18
- def upload(io, id, metadata = {})
18
+ def upload(io, id, shrine_metadata: {}, **upload_options)
19
19
  options = {public_id: public_id(id)}
20
+ options.update(@upload_options)
20
21
  options.update(upload_options)
21
- options.update(metadata.delete("cloudinary") || {})
22
22
 
23
23
  result = store(io, **options)
24
24
 
25
25
  update_id!(result, id)
26
- update_metadata!(result, metadata)
26
+ update_metadata!(result, shrine_metadata)
27
27
 
28
28
  result
29
29
  end
@@ -32,6 +32,10 @@ class Shrine
32
32
  Down.download(url(id))
33
33
  end
34
34
 
35
+ def update(id, **options)
36
+ uploader.explicit(public_id(id), resource_type: resource_type, type: type, **options)
37
+ end
38
+
35
39
  def move(io, id, metadata = {})
36
40
  uploader.rename(io.storage.public_id(io.id), public_id(id), resource_type: resource_type)
37
41
  end
@@ -66,8 +70,7 @@ class Shrine
66
70
  utils.cloudinary_url(path(id), resource_type: resource_type, type: type, **options)
67
71
  end
68
72
 
69
- def clear!(confirm = nil, **options)
70
- raise Shrine::Confirm unless confirm == :confirm
73
+ def clear!(**options)
71
74
  if prefix
72
75
  api.delete_resources_by_prefix(prefix, resource_type: resource_type, **options)
73
76
  else
@@ -93,7 +96,7 @@ class Shrine
93
96
 
94
97
  def store(io, chunk_size: nil, **options)
95
98
  if remote?(io)
96
- uploader.upload(io.storage.url(io.id), **options)
99
+ uploader.upload(io.url, **options)
97
100
  else
98
101
  io = io.download if io.is_a?(UploadedFile)
99
102
  if large?(io)
@@ -109,7 +112,7 @@ class Shrine
109
112
  end
110
113
 
111
114
  def remote?(io)
112
- io.is_a?(UploadedFile) && io.storage.url(io.id) =~ /^ftp:|^https?:/
115
+ io.is_a?(UploadedFile) && io.url.to_s =~ /^ftp:|^https?:/
113
116
  end
114
117
 
115
118
  def large?(io)
@@ -117,7 +120,11 @@ class Shrine
117
120
  end
118
121
 
119
122
  def update_id!(result, id)
120
- id.gsub!(/#{File.extname(id)}$/, ".#{result.fetch("format")}") unless resource_type == "raw"
123
+ uploaded_id = result.fetch("public_id")
124
+ uploaded_id = uploaded_id.match("#{prefix}/").post_match if prefix
125
+ uploaded_id += ".#{result["format"]}" if result["format"]
126
+
127
+ id.replace(uploaded_id)
121
128
  end
122
129
 
123
130
  def update_metadata!(result, metadata)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-cloudinary"
3
- gem.version = "0.2.1"
3
+ gem.version = "0.3.0"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine-cloudinary.gemspec"]
14
14
  gem.require_path = "lib"
15
15
 
16
- gem.add_dependency "shrine", "~> 1.1"
16
+ gem.add_dependency "shrine", "~> 2.0"
17
17
  gem.add_dependency "cloudinary"
18
18
  gem.add_dependency "down", ">= 1.0.5"
19
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-27 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cloudinary
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.4.5
128
+ rubygems_version: 2.5.1
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Provides Cloudinary storage for Shrine.