Module: Paperclip::Storage::Dropbox
- Defined in:
- lib/paperclip/storage/dropbox.rb,
lib/paperclip/storage/dropbox/credentials.rb,
lib/paperclip/storage/dropbox/url_generator.rb,
lib/paperclip/storage/dropbox/path_generator.rb,
lib/paperclip/storage/dropbox/generator_factory.rb,
lib/paperclip/storage/dropbox/public_url_generator.rb,
lib/paperclip/storage/dropbox/private_url_generator.rb
Defined Under Namespace
Modules: GeneratorFactory
Classes: Credentials, FileExists, PathGenerator, PrivateUrlGenerator, PublicUrlGenerator, UrlGenerator
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.extended(base) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/paperclip/storage/dropbox.rb', line 11
def self.extended(base)
base.instance_eval do
@options[:dropbox_options] ||= {}
@options[:path] = nil if @options[:path] == self.class.default_options[:path]
@options[:dropbox_visibility] ||= "public"
@path_generator = PathGenerator.new(self, @options)
end
end
|
Instance Method Details
#copy_to_local_file(style = default_style, destination_path) ⇒ Object
50
51
52
53
54
|
# File 'lib/paperclip/storage/dropbox.rb', line 50
def copy_to_local_file(style = default_style, destination_path)
File.open(destination_path, "wb") do |file|
file.write(dropbox_client.get_file(path(style)))
end
end
|
#dropbox_client ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/paperclip/storage/dropbox.rb', line 64
def dropbox_client
@dropbox_client ||= begin
credentials = dropbox_credentials
session = DropboxSession.new(credentials[:app_key], credentials[:app_secret])
session.set_access_token(credentials[:access_token], credentials[:access_token_secret])
DropboxClient.new(session, credentials[:access_type])
end
end
|
#dropbox_credentials ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/paperclip/storage/dropbox.rb', line 73
def dropbox_credentials
@dropbox_credentials ||= begin
creds = fetch_credentials
creds[:access_type] ||= 'dropbox'
creds
end
end
|
#exists?(style = default_style) ⇒ Boolean
56
57
58
59
60
61
62
|
# File 'lib/paperclip/storage/dropbox.rb', line 56
def exists?(style = default_style)
return false if not present?
metadata = dropbox_client.metadata(path(style))
not metadata.nil? and not metadata["is_deleted"]
rescue DropboxError
false
end
|
#flush_deletes ⇒ Object
31
32
33
34
35
36
|
# File 'lib/paperclip/storage/dropbox.rb', line 31
def flush_deletes
@queued_for_delete.each do |path|
dropbox_client.file_delete(path)
end
@queued_for_delete.clear
end
|
#flush_writes ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/paperclip/storage/dropbox.rb', line 23
def flush_writes
@queued_for_write.each do |style, file|
dropbox_client.put_file(path(style), file.read)
end
after_flush_writes
@queued_for_write.clear
end
|
#path(style = default_style) ⇒ Object
44
45
46
47
48
|
# File 'lib/paperclip/storage/dropbox.rb', line 44
def path(style = default_style)
path = @path_generator.generate(style)
path = File.join("Public", path) if public_dropbox?
path
end
|
#public_dropbox? ⇒ Boolean
85
86
87
88
|
# File 'lib/paperclip/storage/dropbox.rb', line 85
def public_dropbox?
dropbox_credentials[:access_type] == "dropbox" &&
@options[:dropbox_visibility] == "public"
end
|
#url(style_or_options = default_style, options = {}) ⇒ Object
38
39
40
41
42
|
# File 'lib/paperclip/storage/dropbox.rb', line 38
def url(style_or_options = default_style, options = {})
options.merge!(style_or_options) if style_or_options.is_a?(Hash)
style = style_or_options.is_a?(Hash) ? default_style : style_or_options
url_generator.generate(style, options)
end
|