paperclip-cloudinary 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +38 -0
- data/LICENSE +21 -0
- data/README.md +77 -0
- data/Rakefile +2 -0
- data/lib/paperclip/cloudinary.rb +2 -0
- data/lib/paperclip/cloudinary/version.rb +5 -0
- data/lib/paperclip/storage/cloudinary.rb +112 -0
- data/paperclip-cloudinary.gemspec +26 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c8792c1595abc2f240fbe22966f157101d7d5bf
|
4
|
+
data.tar.gz: 733ce9504493f5839e79bc3f72d7fc59a066f63b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea993ac4ab0e85e6c7ae6eacf6cff001618ceed0fb58f4a42ab2ea6d9d1eeeb09b9a612728c469693014379bfe569a5f2cd8e05b20b21dfbc014992f01d97475
|
7
|
+
data.tar.gz: ccdcdb29d4948f411d47746321b97704004454bb7d30c02e831e297f0daa1d518d33ab93fa0328ff2f94cc64d1d2359f5f34b0a9f11e56705b85aec924543a8b
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
paperclip-cloudinary
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
paperclip-cloudinary (1.0.0)
|
5
|
+
cloudinary (~> 1.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
aws_cf_signer (0.1.3)
|
11
|
+
cloudinary (1.1.4)
|
12
|
+
aws_cf_signer
|
13
|
+
rest-client
|
14
|
+
domain_name (0.5.20160310)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
http-cookie (1.0.2)
|
17
|
+
domain_name (~> 0.5)
|
18
|
+
mime-types (2.99.1)
|
19
|
+
netrc (0.11.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rest-client (1.8.0)
|
22
|
+
http-cookie (>= 1.0.2, < 2.0)
|
23
|
+
mime-types (>= 1.16, < 3.0)
|
24
|
+
netrc (~> 0.7)
|
25
|
+
unf (0.1.4)
|
26
|
+
unf_ext
|
27
|
+
unf_ext (0.0.7.2)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.11)
|
34
|
+
paperclip-cloudinary!
|
35
|
+
rake (~> 10.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.11.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Carl Scott
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# paperclip-cloudinary
|
2
|
+
|
3
|
+
paperclip-cloudinary allows simple storage of image assets to a
|
4
|
+
Cloudinary instance.
|
5
|
+
|
6
|
+
[Cloudinary](http://cloudinary.com) is an image, file and video hosting service that allows for
|
7
|
+
dynamic, on-the-fly transformations of images with fast results. There
|
8
|
+
is a free tier to allow you to get started immediately, with paid tiers
|
9
|
+
available once you start gaining traction.
|
10
|
+
|
11
|
+
This library just provides the basics -- provided with your Cloudinary
|
12
|
+
credentials, use paperclip-cloudinary to manage your attachments.
|
13
|
+
|
14
|
+
At this stage, not all of the API has been exposed for Cloudinary, so if
|
15
|
+
it seems you can't quite leverage all of Cloudinary's functionality yet,
|
16
|
+
that's why.
|
17
|
+
|
18
|
+
Note: Cloudinary also supports CarrierWave, and will probably be more
|
19
|
+
consistently maintained going forward. But if you are distinctively
|
20
|
+
looking for a paperclip-based solution, this gem is for you.
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'paperclip-cloudinary'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install paperclip-cloudinary
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Download your configuration YAML file and place it in your `config`
|
41
|
+
directory. You can grab it here:
|
42
|
+
|
43
|
+
[https://cloudinary.com/console/cloudinary.yml](https://cloudinary.com/console/cloudinary.yml)
|
44
|
+
|
45
|
+
This will enable the
|
46
|
+
[Cloudinary gem](https://github.com/cloudinary/cloudinary_gem) to pick
|
47
|
+
up your configuration automatically.
|
48
|
+
|
49
|
+
To use in your model, add the following options for `storage` to `has_attached_file`
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
has_attached_file :image,
|
53
|
+
:storage => :cloudinary
|
54
|
+
```
|
55
|
+
|
56
|
+
If you have put your cloudinary config file at a location other than
|
57
|
+
config/cloudinary.yml (which is ill-advised), you can specify where the
|
58
|
+
credentials are located by specifying the `cloudinary_credentials`
|
59
|
+
option:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
has_attached_file :image,
|
63
|
+
:storage => :cloudinary,
|
64
|
+
:cloudinary_credentials => Rails.root.join("config/cloudinary.yml")
|
65
|
+
```
|
66
|
+
|
67
|
+
The `cloudinary_credentials` can be a file location, a file, or a Hash
|
68
|
+
of options.
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/GoGoCarl/paperclip-cloudinary.
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Storage
|
3
|
+
module Cloudinary
|
4
|
+
# You can download your configuration directly from Cloudinary to
|
5
|
+
# start using this gem immediately:
|
6
|
+
#
|
7
|
+
# https://cloudinary.com/console/cloudinary.yml
|
8
|
+
|
9
|
+
def self.extended base
|
10
|
+
begin
|
11
|
+
require 'cloudinary'
|
12
|
+
rescue LoadError => e
|
13
|
+
e.message << ' (You may need to install the cloudinary gem)'
|
14
|
+
raise e
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def flush_writes
|
19
|
+
@queued_for_write.each do |style_name, file|
|
20
|
+
defaults = {
|
21
|
+
public_id: public_id(style_name),
|
22
|
+
use_filename: true,
|
23
|
+
unique_filename: false,
|
24
|
+
overwrite: true
|
25
|
+
}
|
26
|
+
options = @options[:cloudinary_upload_options] || {}
|
27
|
+
options.merge! defaults
|
28
|
+
::Cloudinary::Uploader.upload file, options
|
29
|
+
end
|
30
|
+
|
31
|
+
after_flush_writes
|
32
|
+
|
33
|
+
@queued_for_write.clear
|
34
|
+
end
|
35
|
+
|
36
|
+
def flush_deletes
|
37
|
+
@queued_for_delete.each do |path|
|
38
|
+
::Cloudinary::Uploader.destroy path
|
39
|
+
end
|
40
|
+
|
41
|
+
@queued_for_delete.clear
|
42
|
+
end
|
43
|
+
|
44
|
+
def copy_to_local_file style, local_dest_path
|
45
|
+
File.open(local_dest_path, 'wb') do |file|
|
46
|
+
file.write ::Cloudinary::Downloader.download(path(style))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def exists? style = default_style
|
51
|
+
::Cloudinary::Uploader.exists? path(style)
|
52
|
+
end
|
53
|
+
|
54
|
+
def url style_or_options = default_style, options = {}
|
55
|
+
if style_or_options.is_a?(Hash)
|
56
|
+
options.merge! style_or_options
|
57
|
+
style = default_style
|
58
|
+
else
|
59
|
+
style = style_or_options
|
60
|
+
end
|
61
|
+
::Cloudinary::Utils.cloudinary_url path(style)
|
62
|
+
end
|
63
|
+
|
64
|
+
def public_id style
|
65
|
+
s = path style
|
66
|
+
s[0..-(File.extname(s).length + 1)]
|
67
|
+
end
|
68
|
+
|
69
|
+
def cloud_name
|
70
|
+
cloudinary_credentials[:cloud_name]
|
71
|
+
end
|
72
|
+
|
73
|
+
def api_key
|
74
|
+
cloudinary_credentials[:api_key]
|
75
|
+
end
|
76
|
+
|
77
|
+
def api_secret
|
78
|
+
cloudinary_credentials[:api_secret]
|
79
|
+
end
|
80
|
+
|
81
|
+
def cloudinary_credentials
|
82
|
+
@cloudinary_credentials ||= parse_credentials(@options[:cloudinary_credentials] || Rails.root.join("config/cloudinary.yml"))
|
83
|
+
@cloudinary_credentials
|
84
|
+
end
|
85
|
+
|
86
|
+
def parse_credentials creds
|
87
|
+
creds = creds.respond_to?('call') ? creds.call(self) : creds
|
88
|
+
creds = find_credentials(creds).stringify_keys
|
89
|
+
env = Object.const_defined?(:Rails) ? Rails.env : nil
|
90
|
+
(creds[env] || creds).symbolize_keys
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def find_credentials creds
|
96
|
+
case creds
|
97
|
+
when File
|
98
|
+
YAML::load(ERB.new(File.read(creds.path)).result)
|
99
|
+
when String, Pathname
|
100
|
+
YAML::load(ERB.new(File.read(creds)).result)
|
101
|
+
when Hash
|
102
|
+
creds
|
103
|
+
when NilClass
|
104
|
+
{}
|
105
|
+
else
|
106
|
+
raise ArgumentError, "Credentials given are not a path, file, proc, or hash."
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paperclip/cloudinary/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paperclip-cloudinary"
|
8
|
+
spec.version = Paperclip::Cloudinary::VERSION
|
9
|
+
spec.authors = ["Carl Scott"]
|
10
|
+
spec.email = ["carl.scott@solertium.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Store Paperclip-managed assets with Cloudinary.}
|
13
|
+
spec.description = %q{Store Paperclip-managed assets with Cloudinary. Requires a free Cloudinary account to get started.}
|
14
|
+
spec.homepage = "http://github.com/GoGoCarl/paperclip-cloudinary"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "cloudinary", "~> 1.1"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-cloudinary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carl Scott
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cloudinary
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Store Paperclip-managed assets with Cloudinary. Requires a free Cloudinary
|
56
|
+
account to get started.
|
57
|
+
email:
|
58
|
+
- carl.scott@solertium.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/paperclip/cloudinary.rb
|
72
|
+
- lib/paperclip/cloudinary/version.rb
|
73
|
+
- lib/paperclip/storage/cloudinary.rb
|
74
|
+
- paperclip-cloudinary.gemspec
|
75
|
+
homepage: http://github.com/GoGoCarl/paperclip-cloudinary
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.8
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Store Paperclip-managed assets with Cloudinary.
|
99
|
+
test_files: []
|