paperclipdropbox 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -14
- data/lib/paperclipdropbox/version.rb +1 -1
- data/lib/paperclipdropbox.rb +12 -13
- data/lib/tasks/paperclipdropbox.rake +27 -20
- metadata +36 -44
data/README.rdoc
CHANGED
@@ -18,26 +18,14 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
gem install paperclipdropbox
|
20
20
|
|
21
|
-
Then run the authotization rake task
|
21
|
+
Then create the paperclipdropbox.yml file and run the authotization rake task
|
22
22
|
|
23
23
|
rake paperclipdropbox:authorize
|
24
24
|
|
25
25
|
you'll then be given a url to login to dropbox to authorize this plugin access to your dropbox account.
|
26
|
-
Then once logged in run the rake task again.
|
27
26
|
|
28
|
-
== Usage
|
29
|
-
|
30
|
-
Create the file config/paperclipdropbox.yml:
|
31
27
|
|
32
|
-
|
33
|
-
dropbox_user: user_email
|
34
|
-
dropbox_password: user_password
|
35
|
-
|
36
|
-
test:
|
37
|
-
...
|
38
|
-
|
39
|
-
production:
|
40
|
-
...
|
28
|
+
== Usage
|
41
29
|
|
42
30
|
In your model:
|
43
31
|
|
@@ -49,4 +37,19 @@ In your model:
|
|
49
37
|
end
|
50
38
|
|
51
39
|
|
40
|
+
== Optional
|
41
|
+
|
42
|
+
Create the file config/paperclipdropbox.yml:
|
43
|
+
|
44
|
+
development:
|
45
|
+
dropbox_key: user_email
|
46
|
+
dropbox_secret: user_password
|
47
|
+
path: "/:attachment/:attachment/:id/:style/:filename"
|
48
|
+
|
49
|
+
test:
|
50
|
+
...
|
51
|
+
|
52
|
+
production:
|
53
|
+
...
|
54
|
+
|
52
55
|
You can add the path option to the config/paperclipdropbox.yml file for ease of use.
|
data/lib/paperclipdropbox.rb
CHANGED
@@ -5,6 +5,8 @@ end
|
|
5
5
|
module Paperclip
|
6
6
|
module Storage
|
7
7
|
module Dropboxstorage
|
8
|
+
extend self
|
9
|
+
|
8
10
|
def self.extended(base)
|
9
11
|
require "dropbox"
|
10
12
|
base.instance_eval do
|
@@ -13,8 +15,6 @@ module Paperclip
|
|
13
15
|
@options.merge!(YAML.load_file("#{Rails.root}/config/paperclipdropbox.yml")[Rails.env].symbolize_keys)
|
14
16
|
end
|
15
17
|
|
16
|
-
@dropbox_user = @options[:dropbox_user]
|
17
|
-
@dropbox_password = @options[:dropbox_password]
|
18
18
|
@dropbox_key = '8ti7qntpcysl91j'
|
19
19
|
@dropbox_secret = 'i0tshr4cpd1pa4e'
|
20
20
|
@dropbox_public_url = @options[:dropbox_public_url] || "http://dl.dropbox.com/u/"
|
@@ -26,26 +26,26 @@ module Paperclip
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def exists?(style = default_style)
|
29
|
-
log("exists? #{style}")
|
29
|
+
log("exists? #{style}") if respond_to?(:log)
|
30
30
|
begin
|
31
31
|
dropbox_session.metadata("/Public#{File.dirname(path(style))}")
|
32
|
-
log("true")
|
32
|
+
log("true") if respond_to?(:log)
|
33
33
|
true
|
34
34
|
rescue
|
35
|
-
log("false")
|
35
|
+
log("false") if respond_to?(:log)
|
36
36
|
false
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def to_file(style=default_style)
|
41
|
-
log("to_file #{style}")
|
41
|
+
log("to_file #{style}") if respond_to?(:log)
|
42
42
|
return @queued_for_write[style] || "#{@dropbox_public_url}#{user_id}/#{path(style)}"
|
43
43
|
end
|
44
44
|
|
45
45
|
def flush_writes #:nodoc:
|
46
46
|
log("[paperclip] Writing files #{@queued_for_write.count}")
|
47
47
|
@queued_for_write.each do |style, file|
|
48
|
-
log("[paperclip] Writing files for ")
|
48
|
+
log("[paperclip] Writing files for ") if respond_to?(:log)
|
49
49
|
file.close
|
50
50
|
dropbox_session.upload(file.path, "/Public#{File.dirname(path(style))}", :as=> File.basename(path(style)))
|
51
51
|
end
|
@@ -54,7 +54,7 @@ module Paperclip
|
|
54
54
|
|
55
55
|
def flush_deletes #:nodoc:
|
56
56
|
@queued_for_delete.each do |path|
|
57
|
-
log("[paperclip] Deleting files for #{path}")
|
57
|
+
log("[paperclip] Deleting files for #{path}") if respond_to?(:log)
|
58
58
|
begin
|
59
59
|
dropbox_session.rm("/Public/#{path}")
|
60
60
|
rescue
|
@@ -69,24 +69,23 @@ module Paperclip
|
|
69
69
|
Rails.cache.write('DropboxSession:uid', dropbox_session.account.uid)
|
70
70
|
dropbox_session.account.uid
|
71
71
|
else
|
72
|
-
log("read Dropbox User_id")
|
72
|
+
log("read Dropbox User_id") if respond_to?(:log)
|
73
73
|
Rails.cache.read('DropboxSession:uid')
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
private
|
78
77
|
def dropbox_session
|
79
78
|
unless Rails.cache.exist?('DropboxSession')
|
80
79
|
if @dropboxsession.blank?
|
81
|
-
log("loading session from yaml")
|
80
|
+
log("loading session from yaml") if respond_to?(:log)
|
82
81
|
if File.exists?("#{Rails.root}/config/dropboxsession.yml")
|
83
82
|
@dropboxsession = Dropbox::Session.deserialize(File.read("#{Rails.root}/config/dropboxsession.yml"))
|
84
83
|
end
|
85
84
|
end
|
86
|
-
@dropboxsession.mode = :dropbox
|
85
|
+
@dropboxsession.mode = :dropbox unless @dropboxsession.blank?
|
87
86
|
@dropboxsession
|
88
87
|
else
|
89
|
-
log("reading Dropbox Session")
|
88
|
+
log("reading Dropbox Session") if respond_to?(:log)
|
90
89
|
Rails.cache.read('DropboxSession')
|
91
90
|
end
|
92
91
|
end
|
@@ -2,46 +2,53 @@ require "yaml"
|
|
2
2
|
require "dropbox"
|
3
3
|
|
4
4
|
namespace :paperclipdropbox do
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
desc "Create DropBox Authorized Session Yaml"
|
8
8
|
task :authorize => :environment do
|
9
|
-
|
9
|
+
|
10
10
|
SESSION_FILE = "#{Rails.root}/config/dropboxsession.yml"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
|
12
|
+
puts ""
|
13
|
+
puts ""
|
14
|
+
puts ""
|
15
|
+
|
16
|
+
unless @dropboxsession = Paperclip::Storage::Dropboxstorage.dropbox_session
|
17
|
+
if File.exists?("#{Rails.root}/config/paperclipdropbox.yml")
|
18
|
+
@options = (YAML.load_file("#{Rails.root}/config/paperclipdropbox.yml")[Rails.env].symbolize_keys)
|
19
|
+
end
|
20
|
+
|
21
|
+
@dropbox_key = @options.blank? ? '8ti7qntpcysl91j' : @options[:dropbox_key]
|
22
|
+
@dropbox_secret = @options.blank? ? 'i0tshr4cpd1pa4e' : @options[:dropbox_secret]
|
23
|
+
|
22
24
|
@dropboxsession = Dropbox::Session.new(@dropbox_key, @dropbox_secret)
|
23
25
|
@dropboxsession.mode = :dropbox
|
24
|
-
|
25
|
-
|
26
|
+
|
27
|
+
puts "Visit #{@dropboxsession.authorize_url} to log in to Dropbox. Hit enter when you have done this."
|
28
|
+
|
29
|
+
$stdin.flush
|
30
|
+
|
31
|
+
STDIN.gets
|
32
|
+
|
26
33
|
end
|
27
|
-
|
28
|
-
puts ""
|
29
|
-
puts ""
|
34
|
+
|
30
35
|
begin
|
31
36
|
@dropboxsession.authorize
|
32
|
-
|
37
|
+
puts ""
|
33
38
|
puts "Authorized - #{@dropboxsession.authorized?}"
|
34
39
|
rescue
|
35
40
|
begin
|
41
|
+
puts ""
|
36
42
|
puts "Please login to dropbox using this link : #{@dropboxsession.authorize_url}"
|
37
43
|
puts "then run this rake task again."
|
38
44
|
rescue
|
45
|
+
puts ""
|
39
46
|
puts "Already Authorized - #{@dropboxsession.authorized?}"
|
40
47
|
end
|
41
48
|
end
|
42
49
|
|
43
50
|
puts ""
|
44
|
-
puts ""
|
51
|
+
puts ""
|
45
52
|
File.open(SESSION_FILE, "w") do |f|
|
46
53
|
f.puts @dropboxsession.serialize
|
47
54
|
end
|
metadata
CHANGED
@@ -1,49 +1,45 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclipdropbox
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Paul Ketelle
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: paperclip
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &10442076 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: dropbox
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *10442076
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: dropbox
|
27
|
+
requirement: &10441824 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
35
33
|
type: :runtime
|
36
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *10441824
|
37
36
|
description: Adds Dropbox storage support for the Paperclip gem. Dropbox account required.
|
38
|
-
email:
|
37
|
+
email:
|
39
38
|
- paul@ketelle.com
|
40
39
|
executables: []
|
41
|
-
|
42
40
|
extensions: []
|
43
|
-
|
44
41
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
42
|
+
files:
|
47
43
|
- .gitignore
|
48
44
|
- Gemfile
|
49
45
|
- README.rdoc
|
@@ -55,30 +51,26 @@ files:
|
|
55
51
|
- paperclipdropbox.gemspec
|
56
52
|
homepage: https://github.com/dripster82/paperclipdropbox
|
57
53
|
licenses: []
|
58
|
-
|
59
54
|
post_install_message:
|
60
55
|
rdoc_options: []
|
61
|
-
|
62
|
-
require_paths:
|
56
|
+
require_paths:
|
63
57
|
- lib
|
64
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
59
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version:
|
70
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
65
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version:
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
76
70
|
requirements: []
|
77
|
-
|
78
71
|
rubyforge_project: paperclipdropbox
|
79
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.10
|
80
73
|
signing_key:
|
81
74
|
specification_version: 3
|
82
75
|
summary: Dropbox storage support for paperclip file attachment
|
83
76
|
test_files: []
|
84
|
-
|