paperclip-dropbox 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/paperclip/storage/dropbox/generator_factory.rb +3 -2
- data/lib/paperclip/storage/dropbox.rb +19 -9
- data/paperclip-dropbox.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dc05c507ab4911452e94f9c9a8fbc95254c9472
|
4
|
+
data.tar.gz: 014650ee8b6e82eef6bdb8a93e659cf409d632e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 101c4d07cd070ee970bebeabd082b9d8c202f57ee06f7b06b2722b0c0f35a9efa4ed65487fd15e42c161338498a97decb60b075c5cb84e6bf48fd9cf487f90c9
|
7
|
+
data.tar.gz: 107be6c531a3534f1e7bdacdb354c2835a76aa5cdd23cac02ed59106ab03edfa49614fa85f8669039396af6c0af976beed86cb9e194a6d7d2fd91ae16fd8ff27
|
data/README.md
CHANGED
@@ -31,6 +31,9 @@ user_id: "..."
|
|
31
31
|
access_type: "dropbox|app_folder"
|
32
32
|
```
|
33
33
|
|
34
|
+
You can also pass a `Proc` to `:dropbox_credentials`, if you want the
|
35
|
+
credentials to be dynamically evaluated.
|
36
|
+
|
34
37
|
In order to fill these in, you must [create a Dropbox app](https://www.dropbox.com/developers/apps)
|
35
38
|
and authorize it. There are two types of Dropbox apps: **App folder** or **Full Dropbox**. You can read
|
36
39
|
about the differences and gotchas in [this wiki](https://github.com/janko-m/paperclip-dropbox/wiki/Access-types).
|
@@ -5,9 +5,10 @@ module Paperclip
|
|
5
5
|
module Dropbox
|
6
6
|
module GeneratorFactory
|
7
7
|
def self.build_url_generator(storage, options)
|
8
|
-
|
8
|
+
credentials = storage.try(:dropbox_credentials) || options[:dropbox_credentials]
|
9
|
+
if credentials[:access_type] == "app_folder" || options[:dropbox_visibility] == "private"
|
9
10
|
PrivateUrlGenerator.new(storage, options)
|
10
|
-
elsif
|
11
|
+
elsif credentials[:access_type]
|
11
12
|
PublicUrlGenerator.new(storage, options)
|
12
13
|
end
|
13
14
|
end
|
@@ -11,14 +11,12 @@ module Paperclip
|
|
11
11
|
def self.extended(base)
|
12
12
|
base.instance_eval do
|
13
13
|
@options[:dropbox_options] ||= {}
|
14
|
-
@options[:dropbox_credentials] = fetch_credentials
|
15
14
|
@options[:path] = nil if @options[:path] == self.class.default_options[:path]
|
16
15
|
@options[:dropbox_visibility] ||= "public"
|
17
16
|
|
18
17
|
@path_generator = PathGenerator.new(self, @options)
|
19
|
-
@url_generator = GeneratorFactory.build_url_generator(self, @options)
|
20
18
|
|
21
|
-
dropbox_client # Force creation of dropbox_client
|
19
|
+
#dropbox_client # Force creation of dropbox_client
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -40,7 +38,7 @@ module Paperclip
|
|
40
38
|
def url(style_or_options = default_style, options = {})
|
41
39
|
options.merge!(style_or_options) if style_or_options.is_a?(Hash)
|
42
40
|
style = style_or_options.is_a?(Hash) ? default_style : style_or_options
|
43
|
-
|
41
|
+
url_generator.generate(style, options)
|
44
42
|
end
|
45
43
|
|
46
44
|
def path(style = default_style)
|
@@ -65,25 +63,37 @@ module Paperclip
|
|
65
63
|
|
66
64
|
def dropbox_client
|
67
65
|
@dropbox_client ||= begin
|
68
|
-
|
69
|
-
credentials = @options[:dropbox_credentials]
|
66
|
+
credentials = dropbox_credentials
|
70
67
|
session = DropboxSession.new(credentials[:app_key], credentials[:app_secret])
|
71
68
|
session.set_access_token(credentials[:access_token], credentials[:access_token_secret])
|
72
69
|
DropboxClient.new(session, credentials[:access_type])
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
73
|
+
def dropbox_credentials
|
74
|
+
@dropbox_credentials ||= begin
|
75
|
+
creds = fetch_credentials
|
76
|
+
creds[:access_type] ||= 'dropbox'
|
77
|
+
creds
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def url_generator
|
82
|
+
@url_generator = GeneratorFactory.build_url_generator(self, @options)
|
83
|
+
end
|
84
|
+
|
76
85
|
def public_dropbox?
|
77
|
-
|
86
|
+
dropbox_credentials[:access_type] == "dropbox" &&
|
78
87
|
@options[:dropbox_visibility] == "public"
|
79
88
|
end
|
80
89
|
|
81
|
-
|
82
90
|
private
|
83
91
|
|
84
92
|
def fetch_credentials
|
93
|
+
credentials = @options[:dropbox_credentials].respond_to?('call') ? @options[:dropbox_credentials].call(self) : @options[:dropbox_credentials]
|
94
|
+
|
85
95
|
environment = defined?(Rails) ? Rails.env : @options[:dropbox_options][:environment]
|
86
|
-
Credentials.new(
|
96
|
+
Credentials.new(credentials).fetch(environment)
|
87
97
|
end
|
88
98
|
|
89
99
|
class FileExists < RuntimeError
|
data/paperclip-dropbox.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-dropbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.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:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paperclip
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.4.5
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: Extends Paperclip with Dropbox storage.
|