rdropbox 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.rdoc +84 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/dropbox.gemspec +87 -0
- data/lib/dropbox/api.rb +530 -0
- data/lib/dropbox/entry.rb +96 -0
- data/lib/dropbox/event.rb +109 -0
- data/lib/dropbox/memoization.rb +98 -0
- data/lib/dropbox/revision.rb +197 -0
- data/lib/dropbox/session.rb +160 -0
- data/lib/dropbox.rb +43 -0
- data/lib/extensions/array.rb +9 -0
- data/lib/extensions/hash.rb +61 -0
- data/lib/extensions/module.rb +22 -0
- data/lib/extensions/object.rb +5 -0
- data/lib/extensions/string.rb +9 -0
- data/lib/extensions/to_bool.rb +17 -0
- data/spec/dropbox/api_spec.rb +778 -0
- data/spec/dropbox/entry_spec.rb +144 -0
- data/spec/dropbox/event_spec.rb +122 -0
- data/spec/dropbox/revision_spec.rb +367 -0
- data/spec/dropbox/session_spec.rb +148 -0
- data/spec/dropbox_spec.rb +57 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- metadata +150 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tim Morgan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= Ruby Dropbox Gem
|
2
|
+
|
3
|
+
An easy-to-use third-party interface to the RESTful Dropbox API.
|
4
|
+
|
5
|
+
== Tutorial by Example
|
6
|
+
|
7
|
+
First things first: Be sure you've gotten a consumer key and secret from
|
8
|
+
http://developers.dropbox.com
|
9
|
+
|
10
|
+
# STEP 1: Authorize the user
|
11
|
+
session = Dropbox::Session.new('your_consumer_key', 'your_consumer_secret')
|
12
|
+
puts "Visit #{session.authorize_url} to log in to Dropbox. Hit enter when you have done this."
|
13
|
+
gets
|
14
|
+
session.authorize
|
15
|
+
session.sandbox = true
|
16
|
+
|
17
|
+
# STEP 2: Play!
|
18
|
+
session.upload('testfile.txt')
|
19
|
+
uploaded_file = session.file('testfile.txt')
|
20
|
+
puts uploaded_file.metadata.size
|
21
|
+
|
22
|
+
uploaded_file.move 'new_name.txt'
|
23
|
+
uploaded_file.delete
|
24
|
+
|
25
|
+
== Tutorial by Example, Rails Edition
|
26
|
+
|
27
|
+
A simple Rails controller that allows a user to first authorize their Dropbox
|
28
|
+
account, and then upload a file to their Dropbox.
|
29
|
+
|
30
|
+
class DropboxController < ApplicationController
|
31
|
+
def authorize
|
32
|
+
if params[:oauth_token] then
|
33
|
+
dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
|
34
|
+
dropbox_session.authorize(params)
|
35
|
+
session[:dropbox_session] = dropbox_session.serialize # re-serialize the authenticated session
|
36
|
+
|
37
|
+
redirect_to :action => 'upload'
|
38
|
+
else
|
39
|
+
dropbox_session = Dropbox::Session.new('your_consumer_key', 'your_consumer_secret')
|
40
|
+
session[:dropbox_session] = dropbox_session.serialize
|
41
|
+
redirect_to dropbox_session.authorize_url(:oauth_callback => url_for(:action => 'authorize'))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def upload
|
46
|
+
return redirect_to(:action => 'authorize') unless session[:dropbox_session]
|
47
|
+
dropbox_session = Dropbox::Session.deserialize(session[:dropbox_session])
|
48
|
+
return redirect_to(:action => 'authorize') unless dropbox_session.authorized?
|
49
|
+
|
50
|
+
if request.method == :post then
|
51
|
+
dropbox_session.upload params[:file], 'My Uploads', :sandbox => true
|
52
|
+
render :text => 'Uploaded OK'
|
53
|
+
else
|
54
|
+
# display a multipart file field form
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
== Features and Where to Find Them
|
60
|
+
|
61
|
+
* Start with the Dropbox::Session class. The first thing you should do is
|
62
|
+
authenticate your users and that class is how to do it.
|
63
|
+
* The Dropbox::API module (attached to the Dropbox::Session class) is the meat
|
64
|
+
and potatoes. Use it to modify a user's Dropbox.
|
65
|
+
* The Dropbox::Entry class is a more object-oriented way of manipulating files.
|
66
|
+
It's totally optional; check it out if you like OOP.
|
67
|
+
* The Dropbox::Memoization module has some handy utility methods for memoizing
|
68
|
+
server responses to reduce network calls. It's plug-in compatible with any
|
69
|
+
caching strategy you might already have (memcache, etc.).
|
70
|
+
|
71
|
+
== Note on Patches/Pull Requests
|
72
|
+
|
73
|
+
* Fork the project.
|
74
|
+
* Make your feature addition or bug fix.
|
75
|
+
* Add tests for it. This is important so I don't break it in a
|
76
|
+
future version unintentionally.
|
77
|
+
* Commit, do not mess with rakefile, version, or history.
|
78
|
+
(if you want to have your own version, that is fine but
|
79
|
+
bump version in a commit by itself I can ignore when I pull)
|
80
|
+
* Send me a pull request. Bonus points for topic branches.
|
81
|
+
|
82
|
+
== Copyright
|
83
|
+
|
84
|
+
Copyright (c) 2009 Tim Morgan. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rdropbox"
|
8
|
+
gem.version = File.read("VERSION").chomp.strip
|
9
|
+
gem.summary = %Q{Ruby client library for the official Dropbox API}
|
10
|
+
gem.description = %Q{An easy-to-use client library for the official Dropbox API.}
|
11
|
+
gem.email = "dropbox@timothymorgan.info"
|
12
|
+
gem.homepage = "http://github.com/RISCfuture/dropbox"
|
13
|
+
gem.authors = ["Tim Morgan"]
|
14
|
+
|
15
|
+
gem.files += FileList["lib/dropbox/*.rb"]
|
16
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
|
+
gem.add_runtime_dependency "oauth", ">= 0.3.6"
|
18
|
+
gem.add_runtime_dependency "json", ">= 1.2.0"
|
19
|
+
gem.add_runtime_dependency "multipart-post", ">= 1.0"
|
20
|
+
|
21
|
+
gem.rubyforge_project = "dropbox"
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
Jeweler::RubyforgeTasks.new
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'spec/rake/spectask'
|
30
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
36
|
+
spec.libs << 'lib' << 'spec'
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :spec => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION').chomp.strip : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "Dropbox API Client #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('LICENSE')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/dropbox.gemspec
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{dropbox}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tim Morgan"]
|
12
|
+
s.date = %q{2010-05-05}
|
13
|
+
s.description = %q{An easy-to-use interface to the RESTful Dropbox API.}
|
14
|
+
s.email = %q{dropbox@timothymorgan.info}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"dropbox.gemspec",
|
27
|
+
"lib/dropbox.rb",
|
28
|
+
"lib/dropbox/api.rb",
|
29
|
+
"lib/dropbox/entry.rb",
|
30
|
+
"lib/dropbox/event.rb",
|
31
|
+
"lib/dropbox/memoization.rb",
|
32
|
+
"lib/dropbox/revision.rb",
|
33
|
+
"lib/dropbox/session.rb",
|
34
|
+
"lib/extensions/array.rb",
|
35
|
+
"lib/extensions/hash.rb",
|
36
|
+
"lib/extensions/module.rb",
|
37
|
+
"lib/extensions/object.rb",
|
38
|
+
"lib/extensions/string.rb",
|
39
|
+
"lib/extensions/to_bool.rb",
|
40
|
+
"spec/dropbox/api_spec.rb",
|
41
|
+
"spec/dropbox/entry_spec.rb",
|
42
|
+
"spec/dropbox/event_spec.rb",
|
43
|
+
"spec/dropbox/revision_spec.rb",
|
44
|
+
"spec/dropbox/session_spec.rb",
|
45
|
+
"spec/dropbox_spec.rb",
|
46
|
+
"spec/spec.opts",
|
47
|
+
"spec/spec_helper.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/RISCfuture/dropbox}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubyforge_project = %q{dropbox}
|
53
|
+
s.rubygems_version = %q{1.3.6}
|
54
|
+
s.summary = %q{Ruby Dropbox interface}
|
55
|
+
s.test_files = [
|
56
|
+
"spec/dropbox/api_spec.rb",
|
57
|
+
"spec/dropbox/entry_spec.rb",
|
58
|
+
"spec/dropbox/event_spec.rb",
|
59
|
+
"spec/dropbox/revision_spec.rb",
|
60
|
+
"spec/dropbox/session_spec.rb",
|
61
|
+
"spec/dropbox_spec.rb",
|
62
|
+
"spec/spec_helper.rb"
|
63
|
+
]
|
64
|
+
|
65
|
+
if s.respond_to? :specification_version then
|
66
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
67
|
+
s.specification_version = 3
|
68
|
+
|
69
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
70
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
71
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.3.6"])
|
72
|
+
s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
|
73
|
+
s.add_runtime_dependency(%q<multipart-post>, [">= 1.0"])
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
76
|
+
s.add_dependency(%q<oauth>, [">= 0.3.6"])
|
77
|
+
s.add_dependency(%q<json>, [">= 1.2.0"])
|
78
|
+
s.add_dependency(%q<multipart-post>, [">= 1.0"])
|
79
|
+
end
|
80
|
+
else
|
81
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
82
|
+
s.add_dependency(%q<oauth>, [">= 0.3.6"])
|
83
|
+
s.add_dependency(%q<json>, [">= 1.2.0"])
|
84
|
+
s.add_dependency(%q<multipart-post>, [">= 1.0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|