dropbox-api-alt 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a72f407ae5bfd6b00b5843a714ae427cf4f2d9e
4
+ data.tar.gz: a02eeb052f097792ed7138c8dc2c6bcdf46e568c
5
+ SHA512:
6
+ metadata.gz: 3f4185e0ec2a02456565a7a198733eda5518ef170b90447a6a77bdf3be48696e7fd97fa3d170213ee7e32f3144f6825d2659a1bdc02daf4f5e6f8f9b73f453a0
7
+ data.tar.gz: 7debfde04c74cac8f6f3668e493f6b0d875ce0727fb317c6669ac0c2da4d657bff8091ecf0df27be131c61f284fd394e96bea8bb9ec63664d6fd604dfbcacb20
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ spec/connection.yml
6
+ bin
7
+ coverage
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ 0.4.6
2
+ + Add Dropbox::API::Client#destroy
3
+ 0.4.5
4
+ + Add Dropbox::API::Client#chunked_upload
5
+ 0.4.4
6
+ + Add Dropbox::API::Dir#hash which returns the dropbox hash
7
+ 0.4.3
8
+ + Allow passing of parameters to Dropbox::API::Client#delta
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dropbox-api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011-2014 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,369 @@
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_KEY
47
+ Dropbox::API::Config.app_secret = YOUR_APP_SECRET
48
+ Dropbox::API::Config.mode = "sandbox" # if you have a single-directory app
49
+ # Dropbox::API::Config.mode = "dropbox" # if your app has access to the whole dropbox
50
+ ```
51
+
52
+ Dropbox::API::Client
53
+ --------------------
54
+
55
+ The client is the base for all communication with the API and wraps around almost all calls
56
+ available in the API.
57
+
58
+ Web-based Authorization
59
+ -----------------------
60
+
61
+ In order to create a Dropbox::API::Client object, you need to have the configuration set up for OAuth.
62
+ Second thing you need is to have the user authorize your app using OAuth. Here's a short intro
63
+ on how to do this:
64
+
65
+ ```ruby
66
+ consumer = Dropbox::API::OAuth.consumer(:authorize)
67
+ request_token = consumer.get_request_token
68
+ # Store the token and secret so after redirecting we have the same request token
69
+ session[:token] = request_token.token
70
+ session[:token_secret] = request_token.secret
71
+ request_token.authorize_url(:oauth_callback => 'http://yoursite.com/callback')
72
+ # Here the user goes to Dropbox, authorizes the app and is redirected
73
+ # This would be typically run in a Rails controller
74
+ hash = { oauth_token: session[:token], oauth_token_secret: session[:token_secret]}
75
+ request_token = OAuth::RequestToken.from_hash(consumer, hash)
76
+ oauth_verifier = params[:oauth_verifier]
77
+ result = request_token.get_access_token(:oauth_verifier => oauth_verifier)
78
+ ```
79
+
80
+ Now that you have the oauth token and secret, you can create a new instance of the Dropbox::API::Client, like this:
81
+
82
+ ```ruby
83
+ client = Dropbox::API::Client.new :token => result.token, :secret => result.secret
84
+ ```
85
+
86
+ Rake-based authorization
87
+ ------------------------
88
+
89
+ Dropbox::API supplies you with a helper rake which will authorize a single client. This is useful for development and testing.
90
+
91
+ In order to have this rake available, put this on your Rakefile:
92
+
93
+ ```ruby
94
+ require "dropbox-api"
95
+ require "dropbox-api/tasks"
96
+ Dropbox::API::Tasks.install
97
+ ```
98
+
99
+ You will notice that you have a new rake task - dropbox:authorize
100
+
101
+ When you call this Rake task, it will ask you to provide the app key and app secret. Afterwards it will present you with an authorize url on Dropbox.
102
+
103
+ Simply go to that url, authorize the app, then press enter in the console.
104
+
105
+ The rake task will output valid ruby code which you can use to create a client.
106
+
107
+ What differs this from the Dropbox Ruby SDK?
108
+ --------------------------------------------
109
+
110
+ A few things:
111
+
112
+ * It's using the ruby oauth gem, instead of reinventing the wheel and implementing OAuth communication
113
+ * It treats files and directories as Ruby objects with appropriate classes, on which you can perform operations
114
+
115
+ Consider the following example which takes all files with names like 'test.txt' and copies them with a suffix '.old'
116
+
117
+ This is how it would look using the SDK:
118
+
119
+ ```ruby
120
+ # Because you need the session with the right access token, you need to create one instance per user
121
+ @session = DropboxSession.new(APP_TOKEN, APP_SECRET)
122
+ @session.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
123
+ @client = DropboxClient.new(@session, :app_folder)
124
+ # The result is a hash, so we need to call a method on the client, supplying the right key from the hash
125
+ @client.search('/', 'test.txt').each do |hash|
126
+ @client.file_copy(hash['path'], hash['path'] + ".old")
127
+ end
128
+ ```
129
+
130
+ With Dropbox::API, you can clean it up, first you put the app token and secret in a config or initializer file:
131
+
132
+ ```ruby
133
+ Dropbox::API::Config.app_key = APP_TOKEN
134
+ Dropbox::API::Config.app_secret = APP_SECRET
135
+ ```
136
+
137
+ And when you want to use it, just create a new client object with a specific access token and secret:
138
+
139
+ ```ruby
140
+ # The app token and secret are read from config, that's all you need to have a client ready for one user
141
+ @client = Dropbox::API::Client.new(:token => ACCESS_TOKEN, :secret => ACCESS_SECRET)
142
+ # The file is a Dropbox::API::File object, so you can call methods on it!
143
+ @client.search('test.txt').each do |file|
144
+ file.copy(file.path + ".old2")
145
+ end
146
+ ```
147
+
148
+ What differs this from the dropbox gem?
149
+ --------------------------------------
150
+
151
+ Dropbox::API does not extend the Ruby primitives, like the dropbox gem:
152
+
153
+ https://github.com/RISCfuture/dropbox/tree/master/lib/dropbox/extensions
154
+
155
+ Dropbox::API::Client methods
156
+ ----------------------------
157
+
158
+ ### Dropbox::API::Client#account
159
+
160
+ Returns a simple object with information about the account:
161
+
162
+ ```ruby
163
+ client.account # => #<Dropbox::API::Object>
164
+ ```
165
+
166
+ For more info, see [https://www.dropbox.com/developers/reference/api#account-info](https://www.dropbox.com/developers/reference/api#account-info)
167
+
168
+ ### Dropbox::API::Client#find
169
+
170
+ When provided a path, returns a single file or directory
171
+
172
+ ```ruby
173
+ client.find 'file.txt' # => #<Dropbox::API::File>
174
+ ```
175
+
176
+ ### Dropbox::API::Client#destroy
177
+
178
+ Removes the file specified by path
179
+
180
+ Returns a Dropbox::API::File object of the deleted file
181
+
182
+ ```ruby
183
+ client.destroy 'file.txt' # => #<Dropbox::API::File>
184
+ ```
185
+
186
+ ### Dropbox::API::Client#ls
187
+
188
+ When provided a path, returns a list of files or directories within that path
189
+
190
+ By default it's the root path:
191
+
192
+ ```ruby
193
+ client.ls # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
194
+ ```
195
+
196
+ But you can provide your own path:
197
+
198
+ ```ruby
199
+ client.ls 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
200
+ ```
201
+
202
+ ### Dropbox::API::Client#mkdir
203
+
204
+ Creates a new directory and returns a Dropbox::API::Dir object
205
+
206
+ ```ruby
207
+ client.mkdir 'new_dir' # => #<Dropbox::API::Dir>
208
+ ```
209
+
210
+ ### Dropbox::API::Client#upload
211
+
212
+ Stores a file with a provided body under a provided name and returns a Dropbox::API::File object
213
+
214
+ ```ruby
215
+ client.upload 'file.txt', 'file body' # => #<Dropbox::API::File>
216
+ ```
217
+
218
+ ### Dropbox::API::Client#chunked_upload
219
+
220
+ Stores a file from a File object under a provided name and returns a Dropbox::API::File object. It should be used for larger files.
221
+
222
+ ```ruby
223
+ client.chunked_upload 'file.txt', File.open('file.txt') # => #<Dropbox::API::File>
224
+ ```
225
+
226
+ ### Dropbox::API::Client#download
227
+
228
+ Downloads a file with a provided name and returns it's content
229
+
230
+ ```ruby
231
+ client.download 'file.txt' # => 'file body'
232
+ ```
233
+
234
+ ### Dropbox::API::Client#search
235
+
236
+ When provided a pattern, returns a list of files or directories within that path
237
+
238
+ By default it searches the root path:
239
+
240
+ ```ruby
241
+ client.search 'pattern' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
242
+ ```
243
+
244
+ However, you can specify your own path:
245
+
246
+ ```ruby
247
+ client.search 'pattern', :path => 'somedir' # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
248
+ ```
249
+
250
+ ### Dropbox::API::Client#delta
251
+
252
+ Returns a cursor and a list of files that have changed since the cursor was generated.
253
+
254
+ ```ruby
255
+ delta = client.delta 'abc123'
256
+ delta.cursor # => 'def456'
257
+ delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
258
+ ```
259
+
260
+ When called without a cursor, it returns all the files.
261
+
262
+ ```ruby
263
+ delta = client.delta 'abc123'
264
+ delta.cursor # => 'abc123'
265
+ delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
266
+ ```
267
+
268
+ Optionally, you can set additional parameters, e.g. **path_prefix**. You can find all available parameters in the [Dropbox API documentation](https://www.dropbox.com/developers/core/docs#delta).
269
+
270
+ ```ruby
271
+ delta = client.delta 'abc123', path_prefix: '/Path/To/My/Folder'
272
+ delta.cursor # => 'abc123'
273
+ delta.entries # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
274
+ ```
275
+
276
+
277
+ Dropbox::API::File and Dropbox::API::Dir methods
278
+ ----------------------------
279
+
280
+ These methods are shared by Dropbox::API::File and Dropbox::API::Dir
281
+
282
+ ### Dropbox::API::File#copy | Dropbox::API::Dir#copy
283
+
284
+ Copies a file/directory to a new specified filename
285
+
286
+ ```ruby
287
+ file.copy 'newfilename.txt' # => #<Dropbox::API::File>
288
+ ```
289
+
290
+ ### Dropbox::API::File#move | Dropbox::API::Dir#move
291
+
292
+ Moves a file/directory to a new specified filename
293
+
294
+ ```ruby
295
+ file.move 'newfilename.txt' # => #<Dropbox::API::File>
296
+ ```
297
+
298
+ ### Dropbox::API::File#destroy | Dropbox::API::Dir#destroy
299
+
300
+ Deletes a file/directory
301
+
302
+ ```ruby
303
+ file.destroy 'newfilename.txt' # => #<Dropbox::API::File>
304
+ ```
305
+
306
+
307
+ Dropbox::API::File methods
308
+ ----------------------------
309
+
310
+ ### Dropbox::API::File#revisions
311
+
312
+ Returns an Array of Dropbox::API::File objects with appropriate rev attribute
313
+
314
+ For more info, see [https://www.dropbox.com/developers/reference/api#revisions](https://www.dropbox.com/developers/reference/api#revisions)
315
+
316
+ ### Dropbox::API::File#restore
317
+
318
+ Restores a file to a specific revision
319
+
320
+ For more info, see [https://www.dropbox.com/developers/reference/api#restore](https://www.dropbox.com/developers/reference/api#restore)
321
+
322
+ ### Dropbox::API::File#share_url
323
+
324
+ Returns the link to a file page in Dropbox
325
+
326
+ For more info, see [https://www.dropbox.com/developers/reference/api#shares](https://www.dropbox.com/developers/reference/api#shares)
327
+
328
+ ### Dropbox::API::File#direct_url
329
+
330
+ Returns the link to a file in Dropbox
331
+
332
+ For more info, see [https://www.dropbox.com/developers/reference/api#media](https://www.dropbox.com/developers/reference/api#media)
333
+
334
+ ### Dropbox::API::File#thumbnail
335
+
336
+ Returns the thumbnail for an image
337
+
338
+ For more info, see [https://www.dropbox.com/developers/reference/api#thumbnail](https://www.dropbox.com/developers/reference/api#thumbnail)
339
+
340
+ ### Dropbox::API::File#download
341
+
342
+ Downloads a file and returns it's content
343
+
344
+ ```ruby
345
+ file.download # => 'file body'
346
+ ```
347
+
348
+ Dropbox::API::Dir methods
349
+ ----------------------------
350
+
351
+ ### Dropbox::API::Dir#ls
352
+
353
+ Returns a list of files or directorys within that directory
354
+
355
+ ```ruby
356
+ dir.ls # => [#<Dropbox::API::File>, #<Dropbox::API::Dir>]
357
+ ```
358
+
359
+ Testing
360
+ ---------
361
+
362
+ 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.
363
+
364
+ Check out spec/connection.sample.yml for an example.
365
+
366
+ Copyright
367
+ ---------
368
+
369
+ Copyright (c) 2011 Marcin Bunsch, Future Simple Inc. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require "dropbox-api/tasks"
4
+ Dropbox::API::Tasks.install
@@ -0,0 +1,34 @@
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-alt"
7
+ s.version = Dropbox::API::VERSION
8
+ s.authors = ["Marcin Bunsch","Jonathan Soeder"]
9
+ s.email = ["marcin@futuresimple.com","jonathan.soeder@gmail.com"]
10
+ s.homepage = "http://github.com/datapimp/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
+ s.license = 'MIT'
14
+
15
+ s.rubyforge_project = "dropbox-api-alt"
16
+
17
+ s.add_dependency 'multi_json', '~> 1.10'
18
+ s.add_dependency 'oauth', '~> 0.4.7'
19
+ s.add_dependency 'hashie', '~> 2.0.5'
20
+
21
+ s.add_development_dependency 'rspec','2.14.1'
22
+ s.add_development_dependency 'rake', '10.1.0'
23
+ s.add_development_dependency 'simplecov', '~> 0.8.2'
24
+ s.add_development_dependency 'yajl-ruby', '~> 1.2.0'
25
+
26
+ if RUBY_VERSION < "1.9"
27
+ s.add_development_dependency 'ruby-debug19'
28
+ end
29
+
30
+ s.files = `git ls-files`.split("\n")
31
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
32
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
33
+ s.require_paths = ["lib"]
34
+ end