fog-dropbox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rubocop.yml +20 -0
  4. data/.ruby-env.example +1 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/CONTRIBUTING.md +18 -0
  8. data/CONTRIBUTORS.md +47 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +73 -0
  12. data/Rakefile +12 -0
  13. data/fog-dropbox.gemspec +33 -0
  14. data/lib/fog/bin/dropbox.rb +70 -0
  15. data/lib/fog/dropbox.rb +17 -0
  16. data/lib/fog/dropbox/models/storage/directories.rb +26 -0
  17. data/lib/fog/dropbox/models/storage/directory.rb +40 -0
  18. data/lib/fog/dropbox/models/storage/file.rb +78 -0
  19. data/lib/fog/dropbox/models/storage/files.rb +41 -0
  20. data/lib/fog/dropbox/storage.rb +44 -0
  21. data/lib/fog/dropbox/version.rb +5 -0
  22. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/directories/all.yml +170 -0
  23. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/directories/get.yml +207 -0
  24. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/directory/destroy.yml +171 -0
  25. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/directory/files.yml +262 -0
  26. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/directory/save.yml +208 -0
  27. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/file/destroy.yml +287 -0
  28. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/file/large_file.yml +278 -0
  29. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/file/small_file.yml +239 -0
  30. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/file/string.yml +519 -0
  31. data/spec/fixtures/vcr_cassettes/fog/storage/dropbox/files.yml +554 -0
  32. data/spec/fog/dropbox/models/storage/directories_spec.rb +49 -0
  33. data/spec/fog/dropbox/models/storage/directory_spec.rb +65 -0
  34. data/spec/fog/dropbox/models/storage/file_spec.rb +106 -0
  35. data/spec/fog/dropbox/models/storage/files_spec.rb +90 -0
  36. data/spec/fog/dropbox/storage_spec.rb +15 -0
  37. data/spec/spec_helper.rb +8 -0
  38. metadata +210 -0
@@ -0,0 +1,41 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/dropbox/models/storage/file'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Dropbox
7
+ class Files < Fog::Collection
8
+
9
+ attribute :directory
10
+
11
+ model Fog::Storage::Dropbox::File
12
+
13
+ def get(key, options = {}, &block)
14
+ requires :directory
15
+
16
+ metadata = service.client.metadata(key)
17
+
18
+ new(metadata)
19
+ rescue DropboxError
20
+ nil
21
+ end
22
+
23
+ def head(key, options = {})
24
+ requires :directory
25
+
26
+ metadata = service.client.metadata(key)
27
+
28
+ new(metadata)
29
+ rescue DropboxError
30
+ nil
31
+ end
32
+
33
+ def new(attributes = {})
34
+ requires :directory
35
+ attributes[:name] = attributes['path'].split('/').last
36
+ super({ :directory => directory }.merge(attributes))
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ require 'dropbox_sdk'
2
+
3
+ module Fog
4
+ module Storage
5
+ class Dropbox < Fog::Service
6
+ requires :dropbox_oauth2_access_token
7
+ recognizes :host, :port, :scheme, :persistent, :path_style
8
+
9
+ model_path 'fog/dropbox/models/storage'
10
+ collection :directories
11
+ model :directory
12
+ collection :files
13
+ model :file
14
+
15
+ class Real
16
+
17
+ # Initialize connection to Dropbox
18
+ #
19
+ # ==== Notes
20
+ # options parameter must include a value for :dropbox_oauth2_access_token
21
+ # in order to create a connection
22
+ #
23
+ # ==== Examples
24
+ # dropbox_storage = Storage.new(
25
+ # :dropbox_oauth2_access_token => ENV['DROPBOX_OAUTH2_ACCESS_TOKEN']
26
+ # )
27
+ #
28
+ # ==== Returns
29
+ # * Storage object with connection to Dropbox.
30
+ def initialize(options={})
31
+
32
+ @dropbox_oauth2_access_token = options[:dropbox_oauth2_access_token]
33
+ @dropbox_client = DropboxClient.new(@dropbox_oauth2_access_token)
34
+
35
+ end
36
+
37
+ def client
38
+ @dropbox_client
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Dropbox
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,170 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.dropbox.com/1/metadata/auto/?file_limit=25000&include_deleted=false&list=true
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - OfficialDropboxRubySDK/1.6.4
16
+ Authorization:
17
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Fri, 03 Apr 2015 22:31:57 GMT
27
+ Content-Type:
28
+ - text/javascript
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-Content-Type-Options:
34
+ - nosniff
35
+ Set-Cookie:
36
+ - gvc=MjE1OTk4ODUwNTU3NDk0MDIwMDIzODI3Mzc3NjIxMzYwODQ3ODgz; expires=Wed, 01
37
+ Apr 2020 22:31:57 GMT; httponly; Path=/; secure
38
+ X-Server-Response-Time:
39
+ - '68'
40
+ X-Dropbox-Request-Id:
41
+ - 0d7ae8e5b97c2a6ae35812f859b2087b
42
+ Pragma:
43
+ - no-cache
44
+ Cache-Control:
45
+ - no-cache
46
+ X-Dropbox-Http-Protocol:
47
+ - None
48
+ X-Frame-Options:
49
+ - SAMEORIGIN
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"hash": "a1d6daac35cad71d033f9dd0f38dcbb3", "thumb_exists": false,
53
+ "bytes": 0, "path": "/", "is_dir": true, "icon": "folder", "root": "app_folder",
54
+ "contents": [{"bytes": 0, "rev": "1e341cc98e", "revision": 30, "icon": "folder",
55
+ "path": "/Mastermind", "is_dir": true, "thumb_exists": false, "root": "app_folder",
56
+ "modified": "Fri, 03 Apr 2015 22:11:29 +0000", "size": "0 bytes"}], "size":
57
+ "0 bytes"}'
58
+ http_version:
59
+ recorded_at: Fri, 03 Apr 2015 22:31:57 GMT
60
+ - request:
61
+ method: get
62
+ uri: https://api.dropbox.com/1/metadata/auto/Mastermind?file_limit=25000&include_deleted=false&list=true
63
+ body:
64
+ encoding: US-ASCII
65
+ string: ''
66
+ headers:
67
+ Accept-Encoding:
68
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
69
+ Accept:
70
+ - "*/*"
71
+ User-Agent:
72
+ - OfficialDropboxRubySDK/1.6.4
73
+ Authorization:
74
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
75
+ response:
76
+ status:
77
+ code: 200
78
+ message: OK
79
+ headers:
80
+ Server:
81
+ - nginx
82
+ Date:
83
+ - Fri, 03 Apr 2015 23:12:42 GMT
84
+ Content-Type:
85
+ - text/javascript
86
+ Transfer-Encoding:
87
+ - chunked
88
+ Connection:
89
+ - keep-alive
90
+ X-Content-Type-Options:
91
+ - nosniff
92
+ Set-Cookie:
93
+ - gvc=MTA4NTk4MDI3MDU3NTE3MTYzNTQ2OTQ3ODQwNDU1MTgyOTQ5NDU3; expires=Wed, 01
94
+ Apr 2020 23:12:42 GMT; httponly; Path=/; secure
95
+ X-Server-Response-Time:
96
+ - '65'
97
+ X-Dropbox-Request-Id:
98
+ - 9c0c7d270b29c8b341cbe01b04eeed36
99
+ Pragma:
100
+ - no-cache
101
+ Cache-Control:
102
+ - no-cache
103
+ X-Dropbox-Http-Protocol:
104
+ - None
105
+ X-Frame-Options:
106
+ - SAMEORIGIN
107
+ body:
108
+ encoding: UTF-8
109
+ string: '{"is_deleted": true, "revision": 78, "bytes": 0, "thumb_exists": false,
110
+ "rev": "4e341cc98e", "modified": "Fri, 03 Apr 2015 23:06:08 +0000", "path":
111
+ "/Mastermind", "is_dir": true, "icon": "folder_gray", "root": "app_folder",
112
+ "hash": "6f116d2035e776f0df02feb3462af618", "contents": [], "size": "0 bytes"}'
113
+ http_version:
114
+ recorded_at: Fri, 03 Apr 2015 23:12:42 GMT
115
+ - request:
116
+ method: get
117
+ uri: https://api.dropbox.com/1/metadata/auto/Mastermind?file_limit=25000&include_deleted=false&list=true
118
+ body:
119
+ encoding: US-ASCII
120
+ string: ''
121
+ headers:
122
+ Accept-Encoding:
123
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
124
+ Accept:
125
+ - "*/*"
126
+ User-Agent:
127
+ - OfficialDropboxRubySDK/1.6.4
128
+ Authorization:
129
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
130
+ response:
131
+ status:
132
+ code: 200
133
+ message: OK
134
+ headers:
135
+ Server:
136
+ - nginx
137
+ Date:
138
+ - Fri, 03 Apr 2015 23:12:42 GMT
139
+ Content-Type:
140
+ - text/javascript
141
+ Transfer-Encoding:
142
+ - chunked
143
+ Connection:
144
+ - keep-alive
145
+ X-Content-Type-Options:
146
+ - nosniff
147
+ Set-Cookie:
148
+ - gvc=MjcxNDc4MjE0NDExNjYyNTQ3ODQ4Njc0OTczMTQxMjQ5OTQ0MDQy; expires=Wed, 01
149
+ Apr 2020 23:12:42 GMT; httponly; Path=/; secure
150
+ X-Server-Response-Time:
151
+ - '85'
152
+ X-Dropbox-Request-Id:
153
+ - c20fd54324c0c10bdb72b1385b4bb04b
154
+ Pragma:
155
+ - no-cache
156
+ Cache-Control:
157
+ - no-cache
158
+ X-Dropbox-Http-Protocol:
159
+ - None
160
+ X-Frame-Options:
161
+ - SAMEORIGIN
162
+ body:
163
+ encoding: UTF-8
164
+ string: '{"is_deleted": true, "revision": 78, "bytes": 0, "thumb_exists": false,
165
+ "rev": "4e341cc98e", "modified": "Fri, 03 Apr 2015 23:06:08 +0000", "path":
166
+ "/Mastermind", "is_dir": true, "icon": "folder_gray", "root": "app_folder",
167
+ "hash": "6f116d2035e776f0df02feb3462af618", "contents": [], "size": "0 bytes"}'
168
+ http_version:
169
+ recorded_at: Fri, 03 Apr 2015 23:12:42 GMT
170
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,207 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.dropbox.com/1/metadata/auto/THIS_SHOULD_MATCH_NO_DIRECTORY_IN_YOUR_DROPBOX?file_limit=25000&include_deleted=false&list=true
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - OfficialDropboxRubySDK/1.6.4
16
+ Authorization:
17
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Fri, 03 Apr 2015 22:31:57 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"error": "Path ''/THIS_SHOULD_MATCH_NO_DIRECTORY_IN_YOUR_DROPBOX''
36
+ not found"}'
37
+ http_version:
38
+ recorded_at: Fri, 03 Apr 2015 22:31:57 GMT
39
+ - request:
40
+ method: post
41
+ uri: https://api.dropbox.com/1/fileops/create_folder
42
+ body:
43
+ encoding: US-ASCII
44
+ string: root=auto&path=%2FTEST_DIRECTORY
45
+ headers:
46
+ Accept-Encoding:
47
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
48
+ Accept:
49
+ - "*/*"
50
+ User-Agent:
51
+ - OfficialDropboxRubySDK/1.6.4
52
+ Content-Type:
53
+ - application/x-www-form-urlencoded
54
+ Authorization:
55
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
56
+ response:
57
+ status:
58
+ code: 200
59
+ message: OK
60
+ headers:
61
+ Server:
62
+ - nginx
63
+ Date:
64
+ - Fri, 03 Apr 2015 22:31:58 GMT
65
+ Content-Type:
66
+ - text/javascript
67
+ Transfer-Encoding:
68
+ - chunked
69
+ Connection:
70
+ - keep-alive
71
+ X-Content-Type-Options:
72
+ - nosniff
73
+ Set-Cookie:
74
+ - gvc=MjgzNTg3MjQyNDc5ODQxNDA3Nzg1NjI1ODk3MDE2ODY0ODQ0MzY4; expires=Wed, 01
75
+ Apr 2020 22:31:58 GMT; httponly; Path=/; secure
76
+ X-Server-Response-Time:
77
+ - '854'
78
+ X-Dropbox-Request-Id:
79
+ - b8509cf57de2b24e29a619282da14191
80
+ Pragma:
81
+ - no-cache
82
+ Cache-Control:
83
+ - no-cache
84
+ X-Dropbox-Http-Protocol:
85
+ - None
86
+ X-Frame-Options:
87
+ - SAMEORIGIN
88
+ body:
89
+ encoding: UTF-8
90
+ string: '{"size": "0 bytes", "rev": "2d341cc98e", "thumb_exists": false, "bytes":
91
+ 0, "modified": "Fri, 03 Apr 2015 22:31:57 +0000", "path": "/TEST_DIRECTORY",
92
+ "is_dir": true, "icon": "folder", "root": "app_folder", "revision": 45}'
93
+ http_version:
94
+ recorded_at: Fri, 03 Apr 2015 22:31:58 GMT
95
+ - request:
96
+ method: get
97
+ uri: https://api.dropbox.com/1/metadata/auto/TEST_DIRECTORY?file_limit=25000&include_deleted=false&list=true
98
+ body:
99
+ encoding: US-ASCII
100
+ string: ''
101
+ headers:
102
+ Accept-Encoding:
103
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
104
+ Accept:
105
+ - "*/*"
106
+ User-Agent:
107
+ - OfficialDropboxRubySDK/1.6.4
108
+ Authorization:
109
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
110
+ response:
111
+ status:
112
+ code: 200
113
+ message: OK
114
+ headers:
115
+ Server:
116
+ - nginx
117
+ Date:
118
+ - Fri, 03 Apr 2015 22:31:58 GMT
119
+ Content-Type:
120
+ - text/javascript
121
+ Transfer-Encoding:
122
+ - chunked
123
+ Connection:
124
+ - keep-alive
125
+ X-Content-Type-Options:
126
+ - nosniff
127
+ Set-Cookie:
128
+ - gvc=MjA4OTM2OTQ3MDQ2NjEyODQwMDk3MjU4NTU3NzcxMTA1NDgyOTY%3D; expires=Wed, 01
129
+ Apr 2020 22:31:58 GMT; httponly; Path=/; secure
130
+ X-Server-Response-Time:
131
+ - '64'
132
+ X-Dropbox-Request-Id:
133
+ - 651cb72d7b4a8e84f553d9eacabe7425
134
+ Pragma:
135
+ - no-cache
136
+ Cache-Control:
137
+ - no-cache
138
+ X-Dropbox-Http-Protocol:
139
+ - None
140
+ X-Frame-Options:
141
+ - SAMEORIGIN
142
+ body:
143
+ encoding: UTF-8
144
+ string: '{"size": "0 bytes", "hash": "64c9f9923bade27a3ba062f89c8106b4", "rev":
145
+ "2d341cc98e", "thumb_exists": false, "bytes": 0, "modified": "Fri, 03 Apr
146
+ 2015 22:31:57 +0000", "path": "/TEST_DIRECTORY", "is_dir": true, "icon": "folder",
147
+ "root": "app_folder", "contents": [], "revision": 45}'
148
+ http_version:
149
+ recorded_at: Fri, 03 Apr 2015 22:31:58 GMT
150
+ - request:
151
+ method: post
152
+ uri: https://api.dropbox.com/1/fileops/delete
153
+ body:
154
+ encoding: US-ASCII
155
+ string: root=auto&path=%2FTEST_DIRECTORY
156
+ headers:
157
+ Accept-Encoding:
158
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
159
+ Accept:
160
+ - "*/*"
161
+ User-Agent:
162
+ - OfficialDropboxRubySDK/1.6.4
163
+ Content-Type:
164
+ - application/x-www-form-urlencoded
165
+ Authorization:
166
+ - Bearer <DROPBOX_OAUTH2_ACCESS_TOKEN>
167
+ response:
168
+ status:
169
+ code: 200
170
+ message: OK
171
+ headers:
172
+ Server:
173
+ - nginx
174
+ Date:
175
+ - Fri, 03 Apr 2015 22:31:58 GMT
176
+ Content-Type:
177
+ - text/javascript
178
+ Transfer-Encoding:
179
+ - chunked
180
+ Connection:
181
+ - keep-alive
182
+ X-Content-Type-Options:
183
+ - nosniff
184
+ Set-Cookie:
185
+ - gvc=MTY0ODYyMTA3ODE4NDc2NTI3MDk5NTQzNzc0OTY5MDE1MzI3MjAy; expires=Wed, 01
186
+ Apr 2020 22:31:58 GMT; httponly; Path=/; secure
187
+ X-Server-Response-Time:
188
+ - '180'
189
+ X-Dropbox-Request-Id:
190
+ - e836a874b7c1fc0baec3de4c91f50cd5
191
+ Pragma:
192
+ - no-cache
193
+ Cache-Control:
194
+ - no-cache
195
+ X-Dropbox-Http-Protocol:
196
+ - None
197
+ X-Frame-Options:
198
+ - SAMEORIGIN
199
+ body:
200
+ encoding: UTF-8
201
+ string: '{"is_deleted": true, "revision": 46, "bytes": 0, "thumb_exists": false,
202
+ "rev": "2e341cc98e", "modified": "Fri, 03 Apr 2015 22:31:58 +0000", "path":
203
+ "/TEST_DIRECTORY", "is_dir": true, "icon": "folder_gray", "root": "app_folder",
204
+ "size": "0 bytes"}'
205
+ http_version:
206
+ recorded_at: Fri, 03 Apr 2015 22:31:58 GMT
207
+ recorded_with: VCR 2.9.3