dropbox-api-petems 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
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/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dropbox-api.gemspec
4
+ gemspec
5
+
6
+ gem "rspec"
7
+ gem "rake"
8
+ gem 'simplecov'
9
+ gem "ruby-debug19"
10
+ gem "yajl-ruby"
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 (PeteMS fork...)
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,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require "dropbox-api/tasks"
4
+ Dropbox::API::Tasks.install
@@ -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-petems"
7
+ s.version = Dropbox::API::VERSION
8
+ s.authors = ["Peter Souter"]
9
+ s.email = ["p.morsou@gmail.com"]
10
+ s.homepage = "http://github.com/petems/dropbox-api-petems"
11
+ s.summary = "A Ruby client for the DropBox REST API (Originally by marcinbunsch, forked by petems)"
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
@@ -0,0 +1,40 @@
1
+ module Dropbox
2
+ module API
3
+
4
+ class Client
5
+
6
+ module Files
7
+
8
+ def download(path, options = {})
9
+ root = options.delete(:root) || Dropbox::API::Config.mode
10
+ path = Dropbox::API::Util.escape(path)
11
+ url = ['', "files", root, path].compact.join('/')
12
+ connection.get_raw(:content, url)
13
+ end
14
+
15
+ def upload(path, data, options = {})
16
+ root = options.delete(:root) || Dropbox::API::Config.mode
17
+ query = Dropbox::API::Util.query(options)
18
+ path = Dropbox::API::Util.escape(path)
19
+ url = ['', "files_put", root, path].compact.join('/')
20
+ response = connection.put(:content, "#{url}?#{query}", data, {
21
+ 'Content-Type' => "application/octet-stream",
22
+ "Content-Length" => data.length.to_s
23
+ })
24
+ Dropbox::API::File.init(response, self)
25
+ end
26
+
27
+ def copy_from_copy_ref(copy_ref, to, options = {})
28
+ raw.copy({
29
+ :from_copy_ref => copy_ref,
30
+ :to_path => to
31
+ }.merge(options))
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+
@@ -0,0 +1,51 @@
1
+ module Dropbox
2
+ module API
3
+
4
+ class Raw
5
+
6
+ attr_accessor :connection
7
+
8
+ def initialize(options = {})
9
+ @connection = options[:connection]
10
+ end
11
+
12
+ def self.add_method(method, action, options = {})
13
+ # Add the default root bit, but allow it to be disabled by a config option
14
+ root = options[:root] == false ? '' : "options[:root] ||= Dropbox::API::Config.mode"
15
+ self.class_eval <<-STR
16
+ def #{options[:as] || action}(options = {})
17
+ #{root}
18
+ request(:#{options[:endpoint] || 'main'}, :#{method}, "#{action}", options)
19
+ end
20
+ STR
21
+ end
22
+
23
+ def request(endpoint, method, action, data = {})
24
+ action.sub! ':root', data.delete(:root) if action.match ':root'
25
+ action.sub! ':path', Dropbox::API::Util.escape(data.delete(:path)) if action.match ':path'
26
+ action = Dropbox::API::Util.remove_double_slashes(action)
27
+ connection.send(method, endpoint, action, data)
28
+ end
29
+
30
+ add_method :get, "/account/info", :as => 'account', :root => false
31
+
32
+ add_method :get, "/metadata/:root/:path", :as => 'metadata'
33
+ add_method :post, "/delta", :as => 'delta', :root => false
34
+ add_method :get, "/revisions/:root/:path", :as => 'revisions'
35
+ add_method :post, "/restore/:root/:path", :as => 'restore'
36
+ add_method :get, "/search/:root/:path", :as => 'search'
37
+ add_method :post, "/shares/:root/:path", :as => 'shares'
38
+ add_method :post, "/media/:root/:path", :as => 'media'
39
+
40
+ add_method :get_raw, "/thumbnails/:root/:path", :as => 'thumbnails', :endpoint => :content
41
+
42
+ add_method :post, "/fileops/copy", :as => "copy"
43
+ add_method :get, "/copy_ref/:root/:path", :as => 'copy_ref'
44
+ add_method :post, "/fileops/create_folder", :as => "create_folder"
45
+ add_method :post, "/fileops/delete", :as => "delete"
46
+ add_method :post, "/fileops/move", :as => "move"
47
+
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,68 @@
1
+ require "dropbox-api/client/raw"
2
+ require "dropbox-api/client/files"
3
+
4
+ module Dropbox
5
+ module API
6
+
7
+ class Client
8
+
9
+ attr_accessor :raw, :connection
10
+
11
+ def initialize(options = {})
12
+ @connection = Dropbox::API::Connection.new(:token => options.delete(:token),
13
+ :secret => options.delete(:secret))
14
+ @raw = Dropbox::API::Raw.new :connection => @connection
15
+ @options = options
16
+ end
17
+
18
+ include Dropbox::API::Client::Files
19
+
20
+ def find(filename)
21
+ data = self.raw.metadata(:path => filename)
22
+ data.delete('contents')
23
+ Dropbox::API::Object.convert(data, self)
24
+ end
25
+
26
+ def ls(path = '')
27
+ Dropbox::API::Dir.init({'path' => path}, self).ls
28
+ end
29
+
30
+ def account
31
+ Dropbox::API::Object.init(self.raw.account, self)
32
+ end
33
+
34
+ def mkdir(path)
35
+ # Remove the characters not allowed by Dropbox
36
+ path = path.gsub(/[\\\:\?\*\<\>\"\|]+/, '')
37
+ response = raw.create_folder :path => path
38
+ Dropbox::API::Dir.init(response, self)
39
+ end
40
+
41
+ def search(term, options = {})
42
+ options[:path] ||= ''
43
+ results = raw.search({ :query => term }.merge(options))
44
+ Dropbox::API::Object.convert(results, self)
45
+ end
46
+
47
+ def delta(cursor=nil)
48
+ entries = []
49
+ has_more = true
50
+ params = cursor ? {:cursor => cursor} : {}
51
+ while has_more
52
+ response = raw.delta(params)
53
+ params[:cursor] = response['cursor']
54
+ has_more = response['has_more']
55
+ entries.push *response['entries']
56
+ end
57
+
58
+ files = entries.map do |entry|
59
+ entry.last || {:is_deleted => true, :path => entry.first}
60
+ end
61
+
62
+ Delta.new(params[:cursor], Dropbox::API::Object.convert(files, self))
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,79 @@
1
+ module Dropbox
2
+ module API
3
+
4
+ class Connection
5
+
6
+ module Requests
7
+
8
+ def request(options = {})
9
+ response = yield
10
+ raise Dropbox::API::Error::ConnectionFailed if !response
11
+ status = response.code.to_i
12
+ case status
13
+ when 400
14
+ parsed = MultiJson.decode(response.body)
15
+ raise Dropbox::API::Error::BadInput.new("400 - Bad input parameter - #{parsed['error']}")
16
+ when 401
17
+ raise Dropbox::API::Error::Unauthorized.new("401 - Bad or expired token")
18
+ when 403
19
+ parsed = MultiJson.decode(response.body)
20
+ raise Dropbox::API::Error::Forbidden.new('403 - Bad OAuth request')
21
+ when 404
22
+ raise Dropbox::API::Error::NotFound.new("404 - Not found")
23
+ when 405
24
+ parsed = MultiJson.decode(response.body)
25
+ raise Dropbox::API::Error::WrongMethod.new("405 - Request method not expected - #{parsed['error']}")
26
+ when 406
27
+ parsed = MultiJson.decode(response.body)
28
+ raise Dropbox::API::Error.new("#{status} - #{parsed['error']}")
29
+ when 429
30
+ raise Dropbox::API::Error::RateLimit.new('429 - Rate Limiting in affect')
31
+ when 300..399
32
+ raise Dropbox::API::Error::Redirect.new("#{status} - Redirect Error")
33
+ when 503
34
+ parsed = MultiJson.decode(response.body)
35
+ raise Dropbox::API::Error.new("503 - Possible Rate Limiting: #{parsed["error"]}")
36
+ when 507
37
+ raise Dropbox::API::Error::StorageQuota.new("507 - Dropbox storage quota exceeded.")
38
+ when 500..599
39
+ parsed = MultiJson.decode(response.body)
40
+ raise Dropbox::API::Error.new("#{status} - Server error. Check http://status.dropbox.com/")
41
+ else
42
+ options[:raw] ? response.body : MultiJson.decode(response.body)
43
+ end
44
+ end
45
+
46
+
47
+
48
+ def get_raw(endpoint, path, data = {}, headers = {})
49
+ query = Dropbox::API::Util.query(data)
50
+ request(:raw => true) do
51
+ token(endpoint).get "#{Dropbox::API::Config.prefix}#{path}?#{URI.parse(URI.encode(query))}", headers
52
+ end
53
+ end
54
+
55
+ def get(endpoint, path, data = {}, headers = {})
56
+ query = Dropbox::API::Util.query(data)
57
+ request do
58
+ token(endpoint).get "#{Dropbox::API::Config.prefix}#{path}?#{URI.parse(URI.encode(query))}", headers
59
+ end
60
+ end
61
+
62
+ def post(endpoint, path, data = {}, headers = {})
63
+ request do
64
+ token(endpoint).post "#{Dropbox::API::Config.prefix}#{path}", data, headers
65
+ end
66
+ end
67
+
68
+ def put(endpoint, path, data = {}, headers = {})
69
+ request do
70
+ token(endpoint).put "#{Dropbox::API::Config.prefix}#{path}", data, headers
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,34 @@
1
+ require "dropbox-api/connection/requests"
2
+
3
+ module Dropbox
4
+ module API
5
+
6
+ class Connection
7
+
8
+ include Dropbox::API::Connection::Requests
9
+
10
+ attr_accessor :consumers
11
+ attr_accessor :tokens
12
+
13
+ def initialize(options = {})
14
+ @options = options
15
+ @consumers = {}
16
+ @tokens = {}
17
+ Dropbox::API::Config.endpoints.each do |endpoint, url|
18
+ @consumers[endpoint] = Dropbox::API::OAuth.consumer(endpoint)
19
+ @tokens[endpoint] = Dropbox::API::OAuth.access_token(@consumers[endpoint], options)
20
+ end
21
+ end
22
+
23
+ def consumer(endpoint = :main)
24
+ @consumers[endpoint]
25
+ end
26
+
27
+ def token(endpoint = :main)
28
+ @tokens[endpoint]
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end