paperclip-dropbox 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8cf29eabf601c976450ee9451a7f1507f7438b39
4
- data.tar.gz: 1610e7c1b1c31e084d9a19b1589ebfa9ff1474c3
3
+ metadata.gz: 37ae3b2982b4e495d0ff1d022ced7c34f7fc4d48
4
+ data.tar.gz: 7f1e5a3e82be45d4afd68a7a9f680aab64112cf0
5
5
  SHA512:
6
- metadata.gz: 8e97054c8acd45b12b43f8931e465fa089e6b24e1635655e03fd92a9bcea89a022d4c837a1f81bfb8a67807bec3ffbb79c1615b4ec613fbf1b1eadbf2b60608b
7
- data.tar.gz: 80b71d4f7ea9ee4e348779e26fcd8d12bbe29797a20501da786d7d5a779683ee38b5f2e851dfaf3dcb076344cd30c3dfffee00df9a41a112743cbe5888176847
6
+ metadata.gz: 82c92a76e6e5bd9c5cd2e37d64a16ad2c1812214223acd917b65da8a509a2b3886a712b44eb591bcb815e3d217223a109025a9d7af3a591cc68b09d48eb75dc8
7
+ data.tar.gz: 058cbce37ecc26149108f7d12a8d855d89330d21aa265d06dcc87c3749ced8f1367e42eb888a0676576d91ef872081972a093e1c133a02a8a7e732327ca3b65e
data/README.md CHANGED
@@ -6,7 +6,7 @@ This gem extends [Paperclip](https://github.com/thoughtbot/paperclip) with
6
6
  ## Setup
7
7
 
8
8
  ```ruby
9
- gem "paperclip-dropbox", ">= 1"
9
+ gem "paperclip-dropbox", ">= 1.1.7"
10
10
  ```
11
11
 
12
12
  Example:
@@ -28,12 +28,14 @@ app_secret: "..."
28
28
  access_token: "..."
29
29
  access_token_secret: "..."
30
30
  user_id: "..."
31
- access_type: "..."
31
+ access_type: "dropbox|app_folder"
32
32
  ```
33
33
 
34
34
  In order to fill these in, you must [create a Dropbox app](https://www.dropbox.com/developers/apps)
35
35
  and authorize it. There are two types of Dropbox apps: **App folder** or **Full Dropbox**. You can read
36
36
  about the differences and gotchas in [this wiki](https://github.com/janko-m/paperclip-dropbox/wiki/Access-types).
37
+ When you decide, don't forget to put `"dropbox"` or `"app_folder"` as the `:access_type`
38
+ in your credentials.
37
39
 
38
40
  After you have created an app, you will be given the "App key" and "App secret". Provide
39
41
  these and the access type to the authorization Rake task:
@@ -89,6 +91,7 @@ This is a hash containing any of the following options:
89
91
  - `:environment` – String, the environment name to use for selecting namespaced
90
92
  credentials in a non-Rails app
91
93
 
94
+
92
95
  For example:
93
96
 
94
97
  ```ruby
@@ -102,6 +105,20 @@ end
102
105
 
103
106
  In Rails you don't need to specify it.
104
107
 
108
+ ### The `:dropbox_visilbility` option
109
+ This is a string "public" (default) or "private".
110
+ - "public" - Files will be placed in your "Public" directory in dropbox and will the public urls will be used to access the files (not http request required to get a url for the file)
111
+ - "private" - Files can be placed in any dropbox directory (set your :path attachment option) and private, expiring urls (4 hours) will be generated each time you access this file. Private can only be used with the 'dropbox' access type.
112
+
113
+ ```ruby
114
+ class User < ActiveRecord::Base
115
+ has_attached_file :avatar,
116
+ :storage => :dropbox,
117
+ :dropbox_credentials => Rails.root.join("config/dropbox.yml"),
118
+ :dropbox_visibility: 'public'
119
+ end
120
+ ```
121
+
105
122
  ### The `:path` option
106
123
 
107
124
  To change the path of the file, use Paperclip's `:path` option:
@@ -110,7 +127,7 @@ To change the path of the file, use Paperclip's `:path` option:
110
127
  :path => ":style/:id_:filename" # Defaults to ":filename"
111
128
  ```
112
129
 
113
- In "Full Dropbox" mode it will automatically be searched in the `Public` folder,
130
+ In "Full Dropbox" mode with "public" visibility it will automatically be searched in the `Public` folder,
114
131
  so there is not need to specify it.
115
132
 
116
133
  ### URL options
@@ -1,9 +1,10 @@
1
1
  require "dropbox_sdk"
2
2
  require "active_support/core_ext/hash/keys"
3
3
  require "paperclip/storage/dropbox/path_generator"
4
- require "paperclip/storage/dropbox/url_generator"
4
+ require "paperclip/storage/dropbox/generator_factory"
5
5
  require "paperclip/storage/dropbox/credentials"
6
6
 
7
+
7
8
  module Paperclip
8
9
  module Storage
9
10
  module Dropbox
@@ -12,8 +13,12 @@ module Paperclip
12
13
  @options[:dropbox_options] ||= {}
13
14
  @options[:dropbox_credentials] = fetch_credentials
14
15
  @options[:path] = nil if @options[:path] == self.class.default_options[:path]
16
+ @options[:dropbox_visibility] ||= "public"
17
+
15
18
  @path_generator = PathGenerator.new(self, @options)
16
- @url_generator = UrlGenerator.new(self, @options)
19
+ @url_generator = GeneratorFactory.build_url_generator(self, @options)
20
+
21
+ dropbox_client # Force creation of dropbox_client
17
22
  end
18
23
  end
19
24
 
@@ -39,7 +44,9 @@ module Paperclip
39
44
  end
40
45
 
41
46
  def path(style = default_style)
42
- @path_generator.generate(style)
47
+ path = @path_generator.generate(style)
48
+ path = File.join("Public", path) if public_dropbox?
49
+ path
43
50
  end
44
51
 
45
52
  def copy_to_local_file(style = default_style, destination_path)
@@ -66,8 +73,11 @@ module Paperclip
66
73
  end
67
74
  end
68
75
 
69
- def app_folder?; @options[:dropbox_credentials][:access_type] == "app_folder"; end
70
- def full_dropbox?; @options[:dropbox_credentials][:access_type] == "dropbox"; end
76
+ def public_dropbox?
77
+ @options[:dropbox_credentials][:access_type] == "dropbox" &&
78
+ @options[:dropbox_visibility] == "public"
79
+ end
80
+
71
81
 
72
82
  private
73
83
 
@@ -0,0 +1,18 @@
1
+ require "paperclip/storage/dropbox/private_url_generator"
2
+ require "paperclip/storage/dropbox/public_url_generator"
3
+ module Paperclip
4
+ module Storage
5
+ module Dropbox
6
+ module GeneratorFactory
7
+ def self.build_url_generator(storage, options)
8
+ if options[:dropbox_credentials][:access_type] == "app_folder" || options[:dropbox_visibility] == "private"
9
+ PrivateUrlGenerator.new(storage, options)
10
+ elsif options[:dropbox_credentials][:access_type] == "dropbox"
11
+ PublicUrlGenerator.new(storage, options)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -16,7 +16,6 @@ module Paperclip
16
16
  else
17
17
  generate_from_proc(style)
18
18
  end
19
- path = File.join("Public", path) if @attachment.full_dropbox?
20
19
  path
21
20
  end
22
21
 
@@ -0,0 +1,13 @@
1
+ require "paperclip/storage/dropbox/url_generator"
2
+ module Paperclip
3
+ module Storage
4
+ module Dropbox
5
+ class PrivateUrlGenerator < UrlGenerator
6
+ def file_url(style)
7
+ @attachment.dropbox_client.media(@attachment.path(style))["url"]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,16 @@
1
+ require "paperclip/storage/dropbox/url_generator"
2
+ module Paperclip
3
+ module Storage
4
+ module Dropbox
5
+ class PublicUrlGenerator < UrlGenerator
6
+ def file_url(style)
7
+ url = URI.parse("https://dl.dropboxusercontent.com/u/#{user_id}/")
8
+ path = @attachment.path(style)
9
+ path = path.match(/^Public\//).try(:post_match)
10
+ url.merge!(path)
11
+ url.to_s
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,6 +3,7 @@ require "uri"
3
3
  module Paperclip
4
4
  module Storage
5
5
  module Dropbox
6
+
6
7
  class UrlGenerator
7
8
  def initialize(attachment, attachment_options)
8
9
  @attachment = attachment
@@ -11,7 +12,7 @@ module Paperclip
11
12
 
12
13
  def generate(style, options)
13
14
  if @attachment.present?
14
- url = @attachment.full_dropbox? ? public_url(style) : private_url(style)
15
+ url = file_url(style)
15
16
  url = URI.parse(url)
16
17
  url.query = [url.query, "dl=1"].compact.join("&") if options[:download]
17
18
  url.to_s
@@ -22,22 +23,11 @@ module Paperclip
22
23
 
23
24
  private
24
25
 
25
- def private_url(style)
26
- @attachment.dropbox_client.media(@attachment.path(style))["url"]
27
- end
28
-
29
- def public_url(style)
30
- url = URI.parse("https://dl.dropboxusercontent.com/u/#{user_id}/")
31
- path = @attachment.path(style)
32
- path = path.match(/^Public\//).post_match
33
- url.merge!(path)
34
- url.to_s
35
- end
36
-
37
26
  def user_id
38
27
  @attachment_options[:dropbox_credentials][:user_id]
39
28
  end
40
29
  end
30
+
41
31
  end
42
32
  end
43
33
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "paperclip-dropbox"
5
- gem.version = "1.1.7"
5
+ gem.version = "1.2.0"
6
6
 
7
7
  gem.homepage = "https://github.com/janko-m/paperclip-dropbox"
8
8
  gem.description = %q{Extends Paperclip with Dropbox storage.}
metadata CHANGED
@@ -1,131 +1,131 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-dropbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.2.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: 2013-10-28 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paperclip
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dropbox-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.11'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.11'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.6'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.8'
90
- - - <
90
+ - - "<"
91
91
  - !ruby/object:Gem::Version
92
92
  version: '1.10'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '1.8'
100
- - - <
100
+ - - "<"
101
101
  - !ruby/object:Gem::Version
102
102
  version: '1.10'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: activerecord
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '>='
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
109
  version: '3.2'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '>='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '3.2'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: rest-client
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - '>='
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: '1.6'
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - '>='
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '1.6'
131
131
  description: Extends Paperclip with Dropbox storage.
@@ -135,17 +135,20 @@ executables: []
135
135
  extensions: []
136
136
  extra_rdoc_files: []
137
137
  files:
138
+ - LICENSE
139
+ - README.md
140
+ - lib/paperclip-dropbox.rb
141
+ - lib/paperclip/dropbox.rb
138
142
  - lib/paperclip/dropbox/railtie.rb
139
143
  - lib/paperclip/dropbox/rake.rb
140
144
  - lib/paperclip/dropbox/tasks.rake
141
- - lib/paperclip/dropbox.rb
145
+ - lib/paperclip/storage/dropbox.rb
142
146
  - lib/paperclip/storage/dropbox/credentials.rb
147
+ - lib/paperclip/storage/dropbox/generator_factory.rb
143
148
  - lib/paperclip/storage/dropbox/path_generator.rb
149
+ - lib/paperclip/storage/dropbox/private_url_generator.rb
150
+ - lib/paperclip/storage/dropbox/public_url_generator.rb
144
151
  - lib/paperclip/storage/dropbox/url_generator.rb
145
- - lib/paperclip/storage/dropbox.rb
146
- - lib/paperclip-dropbox.rb
147
- - README.md
148
- - LICENSE
149
152
  - paperclip-dropbox.gemspec
150
153
  homepage: https://github.com/janko-m/paperclip-dropbox
151
154
  licenses:
@@ -157,17 +160,17 @@ require_paths:
157
160
  - lib
158
161
  required_ruby_version: !ruby/object:Gem::Requirement
159
162
  requirements:
160
- - - '>='
163
+ - - ">="
161
164
  - !ruby/object:Gem::Version
162
165
  version: 1.9.2
163
166
  required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  requirements:
165
- - - '>='
168
+ - - ">="
166
169
  - !ruby/object:Gem::Version
167
170
  version: '0'
168
171
  requirements: []
169
172
  rubyforge_project:
170
- rubygems_version: 2.0.3
173
+ rubygems_version: 2.2.0
171
174
  signing_key:
172
175
  specification_version: 4
173
176
  summary: Extends Paperclip with Dropbox storage.