dropbox-api-kilgore5 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.markdown +335 -0
- data/Rakefile +4 -0
- data/dropbox-api-kilgore5.gemspec +24 -0
- data/lib/dropbox-api.rb +23 -0
- data/lib/dropbox-api/client.rb +73 -0
- data/lib/dropbox-api/client/files.rb +40 -0
- data/lib/dropbox-api/client/raw.rb +51 -0
- data/lib/dropbox-api/connection.rb +34 -0
- data/lib/dropbox-api/connection/requests.rb +67 -0
- data/lib/dropbox-api/objects/delta.rb +11 -0
- data/lib/dropbox-api/objects/dir.rb +30 -0
- data/lib/dropbox-api/objects/file.rb +44 -0
- data/lib/dropbox-api/objects/fileops.rb +28 -0
- data/lib/dropbox-api/objects/object.rb +39 -0
- data/lib/dropbox-api/tasks.rb +48 -0
- data/lib/dropbox-api/util/config.rb +29 -0
- data/lib/dropbox-api/util/error.rb +17 -0
- data/lib/dropbox-api/util/oauth.rb +29 -0
- data/lib/dropbox-api/util/response.rb +8 -0
- data/lib/dropbox-api/util/util.rb +27 -0
- data/lib/dropbox-api/version.rb +5 -0
- data/spec/connection.sample.yml +5 -0
- data/spec/fixtures/dropbox.jpg +0 -0
- data/spec/lib/dropbox-api/client_spec.rb +201 -0
- data/spec/lib/dropbox-api/connection_spec.rb +82 -0
- data/spec/lib/dropbox-api/dir_spec.rb +44 -0
- data/spec/lib/dropbox-api/file_spec.rb +126 -0
- data/spec/lib/dropbox-api/oauth_spec.rb +17 -0
- data/spec/lib/dropbox-api/thumbnail_spec.rb +29 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/config.rb +15 -0
- data/spec/support/jpeg.rb +39 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTY4Y2RiMTFkMTM0ODBlYzQxOGYwOWM5NTJiNjU5YThmYmYwYWY3ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODYwNTFiMjI0MTVlNWQ1NjVlYWJhZjBhYmUxZjU1NWZkODExMzA2MA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2UwOWI1Y2ViYWQzZDM4NTNhYjUxMWYxYjIxOTMxZTQ5YTU4MzNkODFkMGIy
|
10
|
+
MmViMDhlMWM1Y2NhNTBlY2ZmMzdmODhjNTdlMTFmZTI4NGVkNmFkZGYyMjc5
|
11
|
+
ZGY4NTk2NWI2Mjk0YWQzZmU1NjI0OTFmMWExMzkwNDZkYmE3Nzk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWUyM2VkMDQ1ZDg1ZjQwOGVlNGUxOTcyOTYyN2JjOTljMWUyNDI5YjllNGEw
|
14
|
+
ZTVjYTdjNTZkZjcxMGYwMjgxODU5YWQ4OTRkZTE0MzQ5MmNkYjg2NzgxNTY3
|
15
|
+
YmNiNzUwMjc5OTc4NDVmMzc5YjFmOTYwNDU2ODgzODFkYWQwNDM=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 Marcin Bunsch, Future Simple Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,335 @@
|
|
1
|
+
Dropbox::API - Dropbox Ruby API client
|
2
|
+
=========
|
3
|
+
|
4
|
+
A Ruby client for the DropBox REST API.
|
5
|
+
|
6
|
+
Goal:
|
7
|
+
|
8
|
+
To deliver a more Rubyesque experience when using the DropBox API.
|
9
|
+
|
10
|
+
Current state:
|
11
|
+
|
12
|
+
First release, whole API covered.
|
13
|
+
|
14
|
+
Important!!!
|
15
|
+
------------
|
16
|
+
|
17
|
+
From version 0.2.0, Dropbox::API::File#delete and Dropbox::API::Dir#delete *are gone*!!
|
18
|
+
|
19
|
+
The reason is that it's based on Hashie::Mash and was screwing Hash#delete.
|
20
|
+
|
21
|
+
It is replaced with Dropbox::API::File#destroy and Dropbox::API::Dir#destroy.
|
22
|
+
|
23
|
+
Installation
|
24
|
+
------------
|
25
|
+
|
26
|
+
Dropbox::API is available on RubyGems, so:
|
27
|
+
|
28
|
+
```
|
29
|
+
gem install dropbox-api
|
30
|
+
```
|
31
|
+
|
32
|
+
Or in your Gemfile:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem "dropbox-api"
|
36
|
+
```
|
37
|
+
|
38
|
+
Configuration
|
39
|
+
-------------
|
40
|
+
|
41
|
+
In order to use this client, you need to have an app created on https://www.dropbox.com/developers/apps.
|
42
|
+
|
43
|
+
Once you have it, put this configuration somewhere in your code, before you start working with the client.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Dropbox::API::Config.app_key = YOUR_APP_TOKEN
|
47
|
+
Dropbox::API::Config.app_secret = YOUR_APP_SECRET
|
48
|
+
Dropbox::API::Config.mode = "sandbox" # if you have a single-directory app or "dropbox" if it has access to the whole dropbox
|
49
|
+
```
|
50
|
+
|
51
|
+
Dropbox::API::Client
|
52
|
+
--------------------
|
53
|
+
|
54
|
+
The client is the base for all communication with the API and wraps around almost all calls
|
55
|
+
available in the API.
|
56
|
+
|
57
|
+
In order to create a Dropbox::API::Client object, you need to have the configuration set up for OAuth.
|
58
|
+
Second thing you need is to have the user authorize your app using OAuth. Here's a short intro
|
59
|
+
on how to do this:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
consumer = Dropbox::API::OAuth.consumer(:authorize)
|
63
|
+
request_token = consumer.get_request_token
|
64
|
+
# Store the token and secret so after redirecting we have the same request token
|
65
|
+
session[:token] = request_token.token
|
66
|
+
session[:token_secret] = request_token.secret
|
67
|
+
request_token.authorize_url(:oauth_callback => 'http://yoursite.com/callback')
|
68
|
+
# Here the user goes to Dropbox, authorizes the app and is redirected
|
69
|
+
hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
|
70
|
+
request_token = OAuth::RequestToken.from_hash(consumer, hash)
|
71
|
+
result = request_token.get_access_token(:oauth_verifier => oauth_token)
|
72
|
+
```
|
73
|
+
|
74
|
+
Now that you have the oauth token and secret, you can create a new instance of the Dropbox::API::Client, like this:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
client = Dropbox::API::Client.new :token => result.token, :secret => result.secret
|
78
|
+
```
|
79
|
+
|
80
|
+
Rake-based authorization
|
81
|
+
------------------------
|
82
|
+
|
83
|
+
Dropbox::API supplies you with a helper rake which will authorize a single client. This is useful for development and testing.
|
84
|
+
|
85
|
+
In order to have this rake available, put this on your Rakefile:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
require "dropbox-api/tasks"
|
89
|
+
Dropbox::API::Tasks.install
|
90
|
+
```
|
91
|
+
|
92
|
+
You will notice that you have a new rake task - dropbox:authorize
|
93
|
+
|
94
|
+
When you call this Rake task, it will ask you to provide the consumer key and secret. Afterwards it will present you with an authorize url on Dropbox.
|
95
|
+
|
96
|
+
Simply go to that url, authorize the app, then press enter in the console.
|
97
|
+
|
98
|
+
The rake task will output valid ruby code which you can use to create a client.
|
99
|
+
|
100
|
+
What differs this from the DropBox Ruby SDK?
|
101
|
+
--------------------------------------------
|
102
|
+
|
103
|
+
A few things:
|
104
|
+
|
105
|
+
* It's using the ruby oauth gem, instead of reinventing the wheel and implementing OAuth communication
|
106
|
+
* It treats files and directories as Ruby objects with appropriate classes, on which you can perform operations
|
107
|
+
|
108
|
+
Consider the following example which takes all files with names like 'test.txt' and copies them with a suffix '.old'
|
109
|
+
|
110
|
+
This is how it would look using the SDK:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# Because you need the session with the right access token, you need to create one instance per user
|
114
|
+
@session = DropboxSession.new(APP_TOKEN, APP_SECRET)
|
115
|
+
@session.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
|
116
|
+
@client = DropboxClient.new(@session, :app_folder)
|
117
|
+
# The result is a hash, so we need to call a method on the client, supplying the right key from the hash
|
118
|
+
@client.search('/', 'test.txt').each do |hash|
|
119
|
+
@client.file_copy(hash['path'], hash['path'] + ".old")
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
With Dropbox::API, you can clean it up, first you put the app token and secret in a config or initializer file:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
Dropbox::API::Config.app_key = APP_TOKEN
|
127
|
+
Dropbox::API::Config.app_secret = APP_SECRET
|
128
|
+
```
|
129
|
+
|
130
|
+
And when you want to use it, just create a new client object with a specific access token and secret:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
# The app token and secret are read from config, that's all you need to have a client ready for one user
|
134
|
+
@client = Dropbox::API::Client.new(:token => ACCESS_TOKEN, :secret => ACCESS_SECRET)
|
135
|
+
# The file is a Dropbox::API::File object, so you can call methods on it!
|
136
|
+
@client.search('test.txt').each do |file|
|
137
|
+
file.copy(file.path + ".old2")
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
What differs this from the dropbox gem?
|
142
|
+
--------------------------------------
|
143
|
+
|
144
|
+
Dropbox::API does not extend the Ruby primitives, like the dropbox gem:
|
145
|
+
|
146
|
+
https://github.com/RISCfuture/dropbox/tree/master/lib/dropbox/extensions
|
147
|
+
|
148
|
+
Dropbox::API::Client methods
|
149
|
+
----------------------------
|
150
|
+
|
151
|
+
### Dropbox::API::Client#account
|
152
|
+
|
153
|
+
Returns a simple object with information about the account:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
client.account # => #<Dropbox::API::Object>
|
157
|
+
```
|
158
|
+
|
159
|
+
For more info, see [https://www.dropbox.com/developers/reference/api#account-info](https://www.dropbox.com/developers/reference/api#account-info)
|
160
|
+
|
161
|
+
### Dropbox::API::Client#find
|
162
|
+
|
163
|
+
When provided a path, returns a single file or directory
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
client.find 'file.txt' # => #<Dropbox::API::File>
|
167
|
+
```
|
168
|
+
|
169
|
+
### Dropbox::API::Client#ls
|
170
|
+
|
171
|
+
When provided a path, returns a list of files or directories within that path
|
172
|
+
|
173
|
+
By default it's the root path:
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
client.ls # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
177
|
+
```
|
178
|
+
|
179
|
+
But you can provide your own path:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
client.ls 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
183
|
+
```
|
184
|
+
|
185
|
+
### Dropbox::API::Client#mkdir
|
186
|
+
|
187
|
+
Creates a new directory and returns a Dropbox::API::Dir object
|
188
|
+
|
189
|
+
```ruby
|
190
|
+
client.mkdir 'new_dir' # => #<Dropbox::API::Dir>
|
191
|
+
```
|
192
|
+
|
193
|
+
### Dropbox::API::Client#upload
|
194
|
+
|
195
|
+
Stores a file with a provided body under a provided name and returns a Dropbox::API::File object
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
client.upload 'file.txt', 'file body' # => #<Dropbox::API::File>
|
199
|
+
```
|
200
|
+
|
201
|
+
### Dropbox::API::Client#download
|
202
|
+
|
203
|
+
Downloads a file with a provided name and returns it's content
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
client.download 'file.txt' # => 'file body'
|
207
|
+
```
|
208
|
+
|
209
|
+
### Dropbox::API::Client#search
|
210
|
+
|
211
|
+
When provided a pattern, returns a list of files or directories within that path
|
212
|
+
|
213
|
+
By default it searches the root path:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
client.search 'pattern' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
217
|
+
```
|
218
|
+
|
219
|
+
However, you can specify your own path:
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
client.search 'pattern', :path => 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
223
|
+
```
|
224
|
+
|
225
|
+
### Dropbox::API::Client#delta
|
226
|
+
|
227
|
+
Returns a cursor and a list of files that have changed since the cursor was generated.
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
delta = client.delta 'abc123'
|
231
|
+
delta.cursor # => 'def456'
|
232
|
+
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
233
|
+
```
|
234
|
+
|
235
|
+
When called without a cursor, it returns all the files.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
delta = client.delta 'abc123'
|
239
|
+
delta.cursor # => 'abc123'
|
240
|
+
delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
241
|
+
```
|
242
|
+
|
243
|
+
Dropbox::API::File and Dropbox::API::Dir methods
|
244
|
+
----------------------------
|
245
|
+
|
246
|
+
These methods are shared by Dropbox::API::File and Dropbox::API::Dir
|
247
|
+
|
248
|
+
### Dropbox::API::File#copy | Dropbox::API::Dir#copy
|
249
|
+
|
250
|
+
Copies a file/directory to a new specified filename
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
file.copy 'newfilename.txt' # => #<Dropbox::API::File>
|
254
|
+
```
|
255
|
+
|
256
|
+
### Dropbox::API::File#move | Dropbox::API::Dir#move
|
257
|
+
|
258
|
+
Moves a file/directory to a new specified filename
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
file.move 'newfilename.txt' # => #<Dropbox::API::File>
|
262
|
+
```
|
263
|
+
|
264
|
+
### Dropbox::API::File#destroy | Dropbox::API::Dir#destroy
|
265
|
+
|
266
|
+
Deletes a file/directory
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
file.destroy 'newfilename.txt' # => #<Dropbox::API::File>
|
270
|
+
```
|
271
|
+
|
272
|
+
|
273
|
+
Dropbox::API::File methods
|
274
|
+
----------------------------
|
275
|
+
|
276
|
+
### Dropbox::API::File#revisions
|
277
|
+
|
278
|
+
Returns an Array of Dropbox::API::File objects with appropriate rev attribute
|
279
|
+
|
280
|
+
For more info, see [https://www.dropbox.com/developers/reference/api#revisions](https://www.dropbox.com/developers/reference/api#revisions)
|
281
|
+
|
282
|
+
### Dropbox::API::File#restore
|
283
|
+
|
284
|
+
Restores a file to a specific revision
|
285
|
+
|
286
|
+
For more info, see [https://www.dropbox.com/developers/reference/api#restore](https://www.dropbox.com/developers/reference/api#restore)
|
287
|
+
|
288
|
+
### Dropbox::API::File#share_url
|
289
|
+
|
290
|
+
Returns the link to a file page in Dropbox
|
291
|
+
|
292
|
+
For more info, see [https://www.dropbox.com/developers/reference/api#shares](https://www.dropbox.com/developers/reference/api#shares)
|
293
|
+
|
294
|
+
### Dropbox::API::File#direct_url
|
295
|
+
|
296
|
+
Returns the link to a file in Dropbox
|
297
|
+
|
298
|
+
For more info, see [https://www.dropbox.com/developers/reference/api#media](https://www.dropbox.com/developers/reference/api#media)
|
299
|
+
|
300
|
+
### Dropbox::API::File#thumbnail
|
301
|
+
|
302
|
+
Returns the thumbnail for an image
|
303
|
+
|
304
|
+
For more info, see [https://www.dropbox.com/developers/reference/api#thumbnail](https://www.dropbox.com/developers/reference/api#thumbnail)
|
305
|
+
|
306
|
+
### Dropbox::API::File#download
|
307
|
+
|
308
|
+
Downloads a file and returns it's content
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
file.download # => 'file body'
|
312
|
+
```
|
313
|
+
|
314
|
+
Dropbox::API::Dir methods
|
315
|
+
----------------------------
|
316
|
+
|
317
|
+
### Dropbox::API::Dir#ls
|
318
|
+
|
319
|
+
Returns a list of files or directorys within that directory
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
dir.ls # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
|
323
|
+
```
|
324
|
+
|
325
|
+
Testing
|
326
|
+
---------
|
327
|
+
|
328
|
+
In order to run tests, you need to have an application created and authorized. Put all tokens in spec/connection.yml and you're good to go.
|
329
|
+
|
330
|
+
Check out spec/connection.sample.yml for an example.
|
331
|
+
|
332
|
+
Copyright
|
333
|
+
---------
|
334
|
+
|
335
|
+
Copyright (c) 2011 Marcin Bunsch, Future Simple Inc. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dropbox-api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dropbox-api-kilgore5"
|
7
|
+
s.version = Dropbox::API::VERSION
|
8
|
+
s.authors = ["Marcin Bunsch, John Royall"]
|
9
|
+
s.email = ["marcin@futuresimple.com, johnroyall7@yahoo.com"]
|
10
|
+
s.homepage = "http://github.com/kilgore5/dropbox-api"
|
11
|
+
s.summary = "A Ruby client for the DropBox REST API."
|
12
|
+
s.description = "To deliver a more Rubyesque experience when using the DropBox API."
|
13
|
+
|
14
|
+
s.rubyforge_project = "dropbox-api"
|
15
|
+
|
16
|
+
s.add_dependency 'multi_json'
|
17
|
+
s.add_dependency 'oauth'
|
18
|
+
s.add_dependency 'hashie'
|
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
|
data/lib/dropbox-api.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "oauth"
|
2
|
+
require "multi_json"
|
3
|
+
require "hashie"
|
4
|
+
|
5
|
+
module Dropbox
|
6
|
+
module API
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require "dropbox-api/version"
|
12
|
+
require "dropbox-api/util/config"
|
13
|
+
require "dropbox-api/util/oauth"
|
14
|
+
require "dropbox-api/util/error"
|
15
|
+
require "dropbox-api/util/response"
|
16
|
+
require "dropbox-api/util/util"
|
17
|
+
require "dropbox-api/objects/object"
|
18
|
+
require "dropbox-api/objects/fileops"
|
19
|
+
require "dropbox-api/objects/file"
|
20
|
+
require "dropbox-api/objects/dir"
|
21
|
+
require "dropbox-api/objects/delta"
|
22
|
+
require "dropbox-api/connection"
|
23
|
+
require "dropbox-api/client"
|