paperclipdropbox 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/paperclipdropbox/version.rb +3 -0
- data/lib/paperclipdropbox.rb +79 -0
- data/paperclipdropbox.gemspec +24 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Storage
|
3
|
+
module Dropboxstorage
|
4
|
+
def self.extended(base)
|
5
|
+
require "dropbox"
|
6
|
+
base.instance_eval do
|
7
|
+
@options.merge!(YAML.load_file("#{Rails.root.to_s}/config/paperclipdropbox.yml")[Rails.env].symbolize_keys)
|
8
|
+
@dropbox_user = @options[:dropbox_user]
|
9
|
+
@dropbox_password = @options[:dropbox_password]
|
10
|
+
@dropbox_key = @options[:dropbox_key]
|
11
|
+
@dropbox_secret = @options[:dropbox_secret]
|
12
|
+
@dropbox_public_url = @options[:dropbox_public_url] || "http://dl.dropbox.com/u/"
|
13
|
+
@options.merge!( :url => "#{@dropbox_public_url}#{user_id}#{@options[:path]}" )
|
14
|
+
@url = @options[:url]
|
15
|
+
@path = @options[:path]
|
16
|
+
log("Starting up DropBox Storage")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def exists?(style = default_style)
|
21
|
+
log("exists? #{style}")
|
22
|
+
begin
|
23
|
+
dropbox_session.metadata(style)
|
24
|
+
log("true")
|
25
|
+
true
|
26
|
+
rescue
|
27
|
+
log("false")
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_file(style=default_style)
|
33
|
+
log("to_file #{style}")
|
34
|
+
return @queued_for_write[style] || "#{@dropbox_public_url}#{user_id}/#{path(style)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def flush_writes #:nodoc:
|
38
|
+
@queued_for_write.each do |style, file|
|
39
|
+
log("[paperclip] Writing files for /Public#{path(style)}")
|
40
|
+
file.close
|
41
|
+
dropbox_session.upload(file.path, "/Public#{File.dirname(path(style))}", :as=> File.basename(path(style)))
|
42
|
+
end
|
43
|
+
@queued_for_write = {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def flush_deletes #:nodoc:
|
47
|
+
@queued_for_delete.each do |path|
|
48
|
+
log("[paperclip] Deleting files for #{path(style)}")
|
49
|
+
dropbox_session.rm("/Public/#{path}")
|
50
|
+
end
|
51
|
+
@queued_for_delete = []
|
52
|
+
end
|
53
|
+
|
54
|
+
def user_id
|
55
|
+
unless Rails.cache.exist?('DropboxSession:uid')
|
56
|
+
log("get Dropbox Session User_id")
|
57
|
+
Rails.cache.write('DropboxSession:uid', dropbox_session.account.uid)
|
58
|
+
end
|
59
|
+
log("read Dropbox User_id")
|
60
|
+
Rails.cache.read('DropboxSession:uid')
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def dropbox_session
|
65
|
+
unless Rails.cache.exist?('DropboxSession')
|
66
|
+
log("create new Dropbox Session")
|
67
|
+
dropboxsession = Dropbox::Session.new(@dropbox_key, @dropbox_secret)
|
68
|
+
dropboxsession.mode = :dropbox
|
69
|
+
dropboxsession.authorizing_user = @dropbox_user
|
70
|
+
dropboxsession.authorizing_password = @dropbox_password
|
71
|
+
dropboxsession.authorize!
|
72
|
+
Rails.cache.write('DropboxSession', dropboxsession)
|
73
|
+
end
|
74
|
+
log("reading Dropbox Session")
|
75
|
+
Rails.cache.read('DropboxSession')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "paperclipdropbox/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "paperclipdropbox"
|
7
|
+
s.version = Paperclipdropbox::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Paul Ketelle"]
|
10
|
+
s.email = ["paul@ketelle.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Dropbox storage support for paperclip file attachment}
|
13
|
+
s.description = %q{Dropbox storage support for paperclip file attachment}
|
14
|
+
|
15
|
+
s.rubyforge_project = "paperclipdropbox"
|
16
|
+
|
17
|
+
s.add_dependency 'paperclip'
|
18
|
+
s.add_dependency 'dropbox'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclipdropbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul Ketelle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-04-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: paperclip
|
16
|
+
requirement: &11286864 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *11286864
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dropbox
|
27
|
+
requirement: &11286612 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *11286612
|
36
|
+
description: Dropbox storage support for paperclip file attachment
|
37
|
+
email:
|
38
|
+
- paul@ketelle.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Rakefile
|
46
|
+
- lib/paperclipdropbox.rb
|
47
|
+
- lib/paperclipdropbox/version.rb
|
48
|
+
- paperclipdropbox.gemspec
|
49
|
+
homepage: ''
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project: paperclipdropbox
|
69
|
+
rubygems_version: 1.7.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Dropbox storage support for paperclip file attachment
|
73
|
+
test_files: []
|