activestorage-cloudinary-service 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +8 -0
- data/activestorage-cloudinary-service.gemspec +27 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/active_storage/service/cloudinary_service.rb +156 -0
- data/lib/active_storage/service/version.rb +5 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2eb62018264e48d4b9f1dc376cfd401f8d215645
|
4
|
+
data.tar.gz: bc69c0c0b7367845416aeb0aa67e1bd5087175ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3332fda9e60d98e76fa3c84bd7d148118811537bcf0bf5c806ec6ffb366f72a4450ab6b9696362085eeaa16324b798e8c48a3d81d365e47b5ca2a2bd55ea396b
|
7
|
+
data.tar.gz: 4c92345d5ca888864a208ea6d51a38547f846ac90e67df9b4d8d3d78149c5a3c14f0ed73a85eeb83099924df86f790c6cb42e3a04c242ff4867c76f13c5d439b
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
activestorage-cloudinary-service (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
aws_cf_signer (0.1.3)
|
10
|
+
cloudinary (1.8.2)
|
11
|
+
aws_cf_signer
|
12
|
+
rest-client
|
13
|
+
diff-lcs (1.3)
|
14
|
+
domain_name (0.5.20170404)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
http-cookie (1.0.3)
|
17
|
+
domain_name (~> 0.5)
|
18
|
+
mime-types (3.1)
|
19
|
+
mime-types-data (~> 3.2015)
|
20
|
+
mime-types-data (3.2016.0521)
|
21
|
+
netrc (0.11.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rest-client (2.0.2)
|
24
|
+
http-cookie (>= 1.0.2, < 2.0)
|
25
|
+
mime-types (>= 1.16, < 4.0)
|
26
|
+
netrc (~> 0.8)
|
27
|
+
rspec (3.7.0)
|
28
|
+
rspec-core (~> 3.7.0)
|
29
|
+
rspec-expectations (~> 3.7.0)
|
30
|
+
rspec-mocks (~> 3.7.0)
|
31
|
+
rspec-core (3.7.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-expectations (3.7.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.7.0)
|
36
|
+
rspec-mocks (3.7.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.7.0)
|
39
|
+
rspec-support (3.7.0)
|
40
|
+
unf (0.1.4)
|
41
|
+
unf_ext
|
42
|
+
unf_ext (0.0.7.4)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
activestorage-cloudinary-service!
|
49
|
+
bundler (~> 1.16)
|
50
|
+
cloudinary
|
51
|
+
rake (~> 10.0)
|
52
|
+
rspec
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# ActiveStorage::Service::CloudinaryService
|
2
|
+
|
3
|
+
With **v5.2**, Rails introduces [ActiveStorage](https://github.com/rails/rails/blob/master/activestorage/README.md), to facilitate uploading files to cloud services and attaching those files to ActiveRecord objects. Out of the box, it comes with implementations for cloud storage services; Amazon S3, Google Cloud Storage, and Microsoft Azure Storage; with an extendible adapter for adding support for other storage services.
|
4
|
+
|
5
|
+
This gem extends the ActiveStorage::Service api with an implementation for [Cloudinary](https://cloudinary.com/) cloud service. The implementation is a thin wrapper around the official [cloudinary gem](https://github.com/cloudinary/cloudinary_gem) to provide necessary interfaces required to hook up cloudinary to the active_storage api. Serving as a middleman, it interprets active_storage requests and delegate to their cloudinary gem contemporary and parses the response as necessary. So you can work with Cloudinary much like you would any of the other active_storage services that comes out of the box.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cloudinary', require: false
|
13
|
+
gem 'activestorage-cloudinary-service'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
In your Rails 5.2+ app, run:
|
23
|
+
```shell
|
24
|
+
rails active_storage:install
|
25
|
+
```
|
26
|
+
This copy's over the active_storage migration for creating the needed tables and then run:
|
27
|
+
```shell
|
28
|
+
rails db:migrate
|
29
|
+
```
|
30
|
+
|
31
|
+
_Note: you can skip the above two steps if you already have active_storage setup or if working a new Rails 5.2 (the setup is automatically added)_
|
32
|
+
|
33
|
+
Declare a Cloudinary service in `config/storage.yml`. Each active_storage service requires a `name` and the relevant configurations options. Basic configuration options for cloudinary are `cloud_name`, `api_key` and `api_secret`. These are available from your [cloudinary account dashboard](https://cloudinary.com/console/cloudinary.yml).
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
cloudinary:
|
37
|
+
service: Cloudinary
|
38
|
+
cloud_name: <%= ENV['CLOUDINARY_CLOUD_NAME'] %>
|
39
|
+
api_key: <%= ENV['CLOUDINARY_API_KEY'] %>
|
40
|
+
api_secret: <%= ENV['CLOUDINARY_API_SECRET'] %>
|
41
|
+
```
|
42
|
+
|
43
|
+
The env vars should correspond to their appropriate values as defined in your app. Or using `rails credentials:edit` to set the cloudinary secrets `(as cloudinary:cloud_name|api_key|api_secret)`
|
44
|
+
```yaml
|
45
|
+
cloudinary:
|
46
|
+
service: Cloudinary
|
47
|
+
cloud_name: <%= Rails.application.credentials.dig(:cloudinary, :cloud_name) %>
|
48
|
+
api_key: <%= Rails.application.credentials.dig(:cloudinary, :api_key) %>
|
49
|
+
api_secret: <%= Rails.application.credentials.dig(:cloudinary, :api_secret) %>
|
50
|
+
```
|
51
|
+
|
52
|
+
*See [here](https://cloudinary.com/documentation/api_and_access_identifiers) for other supported configurations options that can be provided.*
|
53
|
+
|
54
|
+
Tell Active Storage to use the Cloudinary service by setting `Rails.application.config.active_storage.service`. It is recommended to do this on a per-environment basis to enjoy the flexibility of using different services for different environment.
|
55
|
+
|
56
|
+
For example, to use the cloudinary service in the production environment, you would add the following to `config/environments/production.rb`
|
57
|
+
|
58
|
+
```rb
|
59
|
+
config.active_storage.service = :cloudinary
|
60
|
+
```
|
61
|
+
|
62
|
+
## Known issues
|
63
|
+
Currently, active_storage client-side upload doesn't work with Cloudinary. This because the cloudinary api doesn't, as at now, support the `PUT` request method used by [activestorage.js](https://github.com/rails/rails/blob/master/activestorage/app/javascript/activestorage/blob_upload.js#L9) library and as such client side uploads will error out with the message `Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.`
|
64
|
+
|
65
|
+
Nevertheless, the necessary ground work for this is set and once either active_storage is updated to support more request type or Cloudinary enables support for `PUT` request method, it should work fine.
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/0sc/activestorage-cloudinary-service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
80
|
+
|
81
|
+
## Code of Conduct
|
82
|
+
|
83
|
+
Everyone interacting in the ActiveStorage::Service::CloudinaryService project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/0sc/activestorage-cloudinary-service/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_storage/service/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'activestorage-cloudinary-service'
|
8
|
+
spec.version = ActiveStorage::CloudinaryService::VERSION
|
9
|
+
spec.authors = ['Osmond Oscar']
|
10
|
+
spec.email = ['oskarromero3@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Rails ActiveStorage adapter for cloudinary'
|
13
|
+
spec.homepage = 'https://github.com/0sc/activestorage-cloudinary-service'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'cloudinary'
|
27
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'active_storage/service/cloudinary_service'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'cloudinary'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module ActiveStorage
|
5
|
+
class Service::CloudinaryService < Service
|
6
|
+
# FIXME: implement setup for private resource type
|
7
|
+
# FIXME: allow configuration via cloudinary url
|
8
|
+
def initialize(cloud_name:, api_key:, api_secret:, options: {})
|
9
|
+
options.merge!(
|
10
|
+
cloud_name: cloud_name,
|
11
|
+
api_key: api_key,
|
12
|
+
api_secret: api_secret
|
13
|
+
)
|
14
|
+
Cloudinary.config(options)
|
15
|
+
# Cloudinary.config_from_url(url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def upload(key, io, checksum: nil)
|
19
|
+
instrument :upload, key: key, checksum: checksum do
|
20
|
+
Cloudinary::Uploader.upload(io, public_id: key)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return the content of the file at the +key+.
|
25
|
+
def download(key)
|
26
|
+
tmp_file = open(url_for_public_id(key))
|
27
|
+
if block_given?
|
28
|
+
instrument :streaming_download, key: key do
|
29
|
+
File.open(tmp_file, 'rb') do |file|
|
30
|
+
while (data = file.read(64.kilobytes))
|
31
|
+
yield data
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
instrument :download, key: key do
|
37
|
+
File.binread tmp_file
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Delete the file at the +key+.
|
43
|
+
def delete(key)
|
44
|
+
instrument :delete, key: key do
|
45
|
+
delete_resource_with_public_id(key)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Delete files at keys starting with the +prefix+.
|
50
|
+
def delete_prefixed(prefix)
|
51
|
+
instrument :delete_prefixed, prefix: prefix do
|
52
|
+
find_resources_with_public_id_prefix(prefix).each do |resource|
|
53
|
+
delete_resource_with_public_id(resource['public_id'])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return +true+ if a file exists at the +key+.
|
59
|
+
def exist?(key)
|
60
|
+
instrument :exist?, key: key do
|
61
|
+
resource_exists_with_public_id?(key)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns a signed, temporary URL for the file at the +key+. The URL will be valid for the amount
|
66
|
+
# of seconds specified in +expires_in+. You must also provide the +disposition+ (+:inline+ or +:attachment+),
|
67
|
+
# +filename+, and +content_type+ that you wish the file to be served with on request.
|
68
|
+
def url(key, expires_in:, disposition:, filename:, content_type:)
|
69
|
+
instrument :url, key: key do
|
70
|
+
options = {
|
71
|
+
expires_in: expires_in,
|
72
|
+
content_type: content_type,
|
73
|
+
disposition: disposition,
|
74
|
+
filename: filename
|
75
|
+
}
|
76
|
+
signed_download_url_for_public_id(key, options)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns a signed, temporary URL that a direct upload file can be PUT to on the +key+.
|
81
|
+
# The URL will be valid for the amount of seconds specified in +expires_in+.
|
82
|
+
# You must also provide the +content_type+, +content_length+, and +checksum+ of the file
|
83
|
+
# that will be uploaded. All these attributes will be validated by the service upon upload.
|
84
|
+
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
85
|
+
instrument :url_for_direct_upload, key: key do
|
86
|
+
options = {
|
87
|
+
expires_in: expires_in,
|
88
|
+
content_type: content_type,
|
89
|
+
content_length: content_length,
|
90
|
+
checksum: checksum
|
91
|
+
}
|
92
|
+
direct_upload_url_for_public_id(key, options)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns a Hash of headers for +url_for_direct_upload+ requests.
|
97
|
+
def headers_for_direct_upload(key, filename:, content_type:, content_length:, checksum:)
|
98
|
+
{ 'Content-Type' => content_type, 'X-Unique-Upload-Id' => key }
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def resource_exists_with_public_id?(public_id)
|
104
|
+
!find_resource_with_public_id(public_id).empty?
|
105
|
+
end
|
106
|
+
|
107
|
+
def find_resource_with_public_id(public_id)
|
108
|
+
Cloudinary::Api.resources_by_ids(public_id).fetch('resources')
|
109
|
+
end
|
110
|
+
|
111
|
+
def find_resources_with_public_id_prefix(prefix)
|
112
|
+
Cloudinary::Api.resources(type: :upload, prefix: prefix).fetch('resources')
|
113
|
+
end
|
114
|
+
|
115
|
+
def delete_resource_with_public_id(public_id)
|
116
|
+
Cloudinary::Uploader.destroy(public_id)
|
117
|
+
end
|
118
|
+
|
119
|
+
def url_for_public_id(public_id)
|
120
|
+
Cloudinary::Api.resource(public_id)['secure_url']
|
121
|
+
end
|
122
|
+
|
123
|
+
# FIXME: Cloudinary Ruby SDK does't expose an api for signed upload url
|
124
|
+
# The expected url is similar to the private_download_url
|
125
|
+
# with download replaced with upload
|
126
|
+
def direct_upload_url_for_public_id(public_id, options)
|
127
|
+
# allow the server to auto detect the resource_type
|
128
|
+
options[:resource_type] ||= 'auto'
|
129
|
+
signed_download_url_for_public_id(public_id, options).sub(/download/, 'upload')
|
130
|
+
end
|
131
|
+
|
132
|
+
def signed_download_url_for_public_id(public_id, options)
|
133
|
+
options[:resource_type] ||= resource_type(options[:content_type])
|
134
|
+
Cloudinary::Utils.private_download_url(
|
135
|
+
public_id,
|
136
|
+
resource_format(options),
|
137
|
+
signed_url_options(options)
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
def signed_url_options(options)
|
142
|
+
{
|
143
|
+
resource_type: (options[:resource_type] || 'auto'),
|
144
|
+
type: (options[:type] || 'upload'),
|
145
|
+
attachment: (options[:attachment] == :attachment),
|
146
|
+
expires_at: (Time.now + options[:expires_in])
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
def resource_format(_options); end
|
151
|
+
|
152
|
+
def resource_type(content_type)
|
153
|
+
content_type.sub(%r{/.*$}, '')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activestorage-cloudinary-service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Osmond Oscar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cloudinary
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- oskarromero3@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- CODE_OF_CONDUCT.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- activestorage-cloudinary-service.gemspec
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/active_storage/service/cloudinary_service.rb
|
88
|
+
- lib/active_storage/service/version.rb
|
89
|
+
homepage: https://github.com/0sc/activestorage-cloudinary-service
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.6.13
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Rails ActiveStorage adapter for cloudinary
|
113
|
+
test_files: []
|