dragonfly-cloudinary-datastore 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/dragonfly-cloudinary-datastore.gemspec +23 -0
- data/lib/dragonfly-cloudinary-datastore.rb +5 -0
- data/lib/dragonfly/cloudinary_datastore.rb +35 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af4a7c3395634a471e62830e79864386e0f7346c
|
4
|
+
data.tar.gz: f7a1f91a970f49f301d3b659229de8ac2c0c5dae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85dc639e913237d3af4d949d5afe07683857f85ae71a8e6a66cfb92bfccb6623670334cbf6a6fd5bc3f00a77b7512ac086ae7c0fcbd5caceb9678cdbe5efb63b
|
7
|
+
data.tar.gz: 7482245abe19c76fb20f975c41cd97246d6445718d82d55b2a05e30b5276294b6c153b72e13a7c0d57741bb329edf1d680e007aab6498ca8d12b41fa9f3f017d
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2017 Prabhakar Kumar
|
2
|
+
|
3
|
+
MIT License
|
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,44 @@
|
|
1
|
+
# Introduction
|
2
|
+
[Dragonfly](http://markevans.github.io/dragonfly/) is great for on the fly image processing in your Ruby or Rails
|
3
|
+
application.
|
4
|
+
Being an awesomely extensible software, dragonfly has a very clean and simple API for implemeting
|
5
|
+
[custom data stores](http://markevans.github.io/dragonfly/data-stores#building-a-custom-data-store).
|
6
|
+
There are data stores for Dragonfly that write to S3, MongoDB and CouchDB. There is an old project that provides
|
7
|
+
a [cloudinary based datastore](https://github.com/adie/dragonfly-cloudinary) for dragonfly. But that project is
|
8
|
+
not actively maintained and it doesn't work with the latest dragonfly interface for read, write and destory.
|
9
|
+
|
10
|
+
So I created this gem which supports the latest dragonfly interface.
|
11
|
+
|
12
|
+
# Usage
|
13
|
+
|
14
|
+
If using Cloudinary on Heroku, the config is read automatically from CLOUDINARY\_URL environment variable. Else, just download your cloudinary.yml file
|
15
|
+
and place it in your config directory.
|
16
|
+
|
17
|
+
Then in your dragonfly initializer, declare cloudinary as the data store with the following line.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
app.datastore = Dragonfly::CloudinaryDatastore.new
|
21
|
+
```
|
22
|
+
|
23
|
+
## With PushType CMS
|
24
|
+
[PushType](http://www.pushtype.org/) is a cool CMS for rails. If you want to use cloudinary for storing media in your PushType based application,
|
25
|
+
read ahead. You will specially need it if you want to run your PushType application on Heroku.
|
26
|
+
|
27
|
+
In the `config/initializers/push_type.rb` file, comment the line that configures `:file` datastore and add
|
28
|
+
the line `config.dragonfly_datastore = Dragonfly::CloudinaryDatastore.new`
|
29
|
+
|
30
|
+
|
31
|
+
# TODO
|
32
|
+
|
33
|
+
1. Add some tests
|
34
|
+
|
35
|
+
# Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
42
|
+
|
43
|
+
|
44
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "dragonfly-cloudinary-datastore"
|
7
|
+
gem.version = '0.1'
|
8
|
+
gem.authors = ["Prabhakar Kumar"]
|
9
|
+
gem.email = ["prabhakar97@gmail.com"]
|
10
|
+
gem.description = %q{Cloudinary based data store for Dragonfly. Works with the latest read write destory interface.}
|
11
|
+
gem.summary = %q{Cloudinary based data store for Dragonfly}
|
12
|
+
gem.homepage = "https://github.com/prabhakar97/dragonfly-cloudinary-datastore"
|
13
|
+
gem.license = "MIT"
|
14
|
+
gem.extra_rdoc_files = ["LICENSE.txt", "README.md"]
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_runtime_dependency 'dragonfly', '~> 1.0', '>= 1.0'
|
22
|
+
gem.add_runtime_dependency 'cloudinary', '~> 1.3', '>= 1.3.0'
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'cloudinary'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Dragonfly
|
5
|
+
class CloudinaryDatastore
|
6
|
+
|
7
|
+
def write(content, opts={})
|
8
|
+
result = Cloudinary::Uploader.upload(content.path, { tags: serialize_hash(content.meta) })
|
9
|
+
"#{result['public_id']}.#{result['format']}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(uid)
|
13
|
+
resource = Cloudinary::Api.resource(File.basename(uid, File.extname(uid)))
|
14
|
+
[Cloudinary::Downloader.download(uid), deserialize_to_hash(resource['tags'])]
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy(uid)
|
18
|
+
Cloudinary::Uploader.destroy(uid)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def serialize_hash(hash)
|
23
|
+
return hash if hash.nil?
|
24
|
+
hash.map { |k, v| "#{k}=>#{v}"}
|
25
|
+
end
|
26
|
+
|
27
|
+
def deserialize_to_hash(str_arr)
|
28
|
+
return str_arr if str_arr.nil?
|
29
|
+
res = str_arr.map { |x| x.split("=>") }.flatten
|
30
|
+
hash = Hash[*res.flatten]
|
31
|
+
hash
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dragonfly-cloudinary-datastore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prabhakar Kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dragonfly
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: cloudinary
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.3.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.0
|
53
|
+
description: Cloudinary based data store for Dragonfly. Works with the latest read
|
54
|
+
write destory interface.
|
55
|
+
email:
|
56
|
+
- prabhakar97@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- dragonfly-cloudinary-datastore.gemspec
|
69
|
+
- lib/dragonfly-cloudinary-datastore.rb
|
70
|
+
- lib/dragonfly/cloudinary_datastore.rb
|
71
|
+
homepage: https://github.com/prabhakar97/dragonfly-cloudinary-datastore
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.5.1
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Cloudinary based data store for Dragonfly
|
95
|
+
test_files: []
|