dropbox-api-petems 0.4.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +5 -0
  3. data/README.markdown +13 -8
  4. data/Rakefile +5 -0
  5. data/dropbox-api.gemspec +9 -8
  6. data/lib/dropbox-api.rb +1 -0
  7. data/lib/dropbox-api/objects/dir.rb +5 -0
  8. data/lib/dropbox-api/objects/file.rb +5 -10
  9. data/lib/dropbox-api/objects/fileops.rb +5 -0
  10. data/lib/dropbox-api/tasks.rb +2 -2
  11. data/lib/dropbox-api/version.rb +1 -1
  12. data/spec/connection.offline.yml +5 -0
  13. data/spec/lib/dropbox-api/client_spec.rb +96 -68
  14. data/spec/lib/dropbox-api/connection_spec.rb +1 -1
  15. data/spec/lib/dropbox-api/dir_spec.rb +12 -6
  16. data/spec/lib/dropbox-api/file_spec.rb +7 -11
  17. data/spec/lib/dropbox-api/oauth_spec.rb +22 -1
  18. data/spec/lib/dropbox-api/thumbnail_spec.rb +4 -4
  19. data/spec/spec_helper.rb +13 -4
  20. data/spec/support/config.rb +5 -1
  21. data/spec/vcr/cassettes/Dropbox_API_Client/_account/retrieves_the_account_object.yml +54 -0
  22. data/spec/vcr/cassettes/Dropbox_API_Client/_chunked_upload/puts_a_5MB_file_in_dropbox.yml +150 -0
  23. data/spec/vcr/cassettes/Dropbox_API_Client/_chunked_upload/yields_current_offset_and_upload_id.yml +150 -0
  24. data/spec/vcr/cassettes/Dropbox_API_Client/_copy_from_copy_ref/copies_a_file_from_a_copy_ref.yml +271 -0
  25. data/spec/vcr/cassettes/Dropbox_API_Client/_delta/returns_a_cursor_and_list_of_files.yml +184 -0
  26. data/spec/vcr/cassettes/Dropbox_API_Client/_delta/returns_the_files_that_have_changed_since_the_cursor_was_made.yml +361 -0
  27. data/spec/vcr/cassettes/Dropbox_API_Client/_download/a_file/downloads_a_file.yml +58 -0
  28. data/spec/vcr/cassettes/Dropbox_API_Client/_download/a_non-existant_file/raises_a_404.yml +38 -0
  29. data/spec/vcr/cassettes/Dropbox_API_Client/_find/returns_a_single_directory.yml +63 -0
  30. data/spec/vcr/cassettes/Dropbox_API_Client/_find/returns_a_single_file.yml +55 -0
  31. data/spec/vcr/cassettes/Dropbox_API_Client/_ls/a_directory/returns_an_item_array_of_directory_contents.yml +107 -0
  32. data/spec/vcr/cassettes/Dropbox_API_Client/_ls/a_single_file/returns_a_single_item_array_of_if_we_ls_a_file.yml +107 -0
  33. data/spec/vcr/cassettes/Dropbox_API_Client/_ls/no_value/returns_an_array_of_files_and_dirs.yml +115 -0
  34. data/spec/vcr/cassettes/Dropbox_API_Client/_mkdir/creates_dirs_with_tricky_characters.yml +61 -0
  35. data/spec/vcr/cassettes/Dropbox_API_Client/_mkdir/creates_dirs_with_utf8_characters.yml +61 -0
  36. data/spec/vcr/cassettes/Dropbox_API_Client/_mkdir/returns_an_array_of_files_and_dirs.yml +61 -0
  37. data/spec/vcr/cassettes/Dropbox_API_Client/_search/no_path_given/finds_the_file_if_in_root.yml +55 -0
  38. data/spec/vcr/cassettes/Dropbox_API_Client/_search/path_with_leading_slash/finds_the_file.yml +56 -0
  39. data/spec/vcr/cassettes/Dropbox_API_Client/_search/with_path/finds_a_file.yml +56 -0
  40. data/spec/vcr/cassettes/Dropbox_API_Client/_upload/a_file_with_tricky_characters/is_uploaded.yml +56 -0
  41. data/spec/vcr/cassettes/Dropbox_API_Client/_upload/a_file_with_utf8/is_uploaded.yml +56 -0
  42. data/spec/vcr/cassettes/Dropbox_API_Client/_upload/a_simple_file/is_uploaded.yml +55 -0
  43. data/spec/vcr/cassettes/Dropbox_API_Dir/_copy/copies_the_dir_properly.yml +120 -0
  44. data/spec/vcr/cassettes/Dropbox_API_Dir/_destroy/destroys_the_dir_properly.yml +120 -0
  45. data/spec/vcr/cassettes/Dropbox_API_Dir/_direct_url/gives_the_direct_url.yml +115 -0
  46. data/spec/vcr/cassettes/Dropbox_API_Dir/_move/moves_the_dir_properly.yml +120 -0
  47. data/spec/vcr/cassettes/Dropbox_API_File/_copy/copies_the_file_properly.yml +115 -0
  48. data/spec/vcr/cassettes/Dropbox_API_File/_copy_ref/returns_a_copy_ref_object.yml +104 -0
  49. data/spec/vcr/cassettes/Dropbox_API_File/_destroy/destroys_the_file_properly.yml +115 -0
  50. data/spec/vcr/cassettes/Dropbox_API_File/_direct_url/returns_an_Url_object.yml +109 -0
  51. data/spec/vcr/cassettes/Dropbox_API_File/_download/should_download_the_file.yml +109 -0
  52. data/spec/vcr/cassettes/Dropbox_API_File/_move/moves_the_file_properly.yml +115 -0
  53. data/spec/vcr/cassettes/Dropbox_API_File/_restore/restores_the_file_to_a_specific_revision.yml +270 -0
  54. data/spec/vcr/cassettes/Dropbox_API_File/_revisions/retrieves_all_revisions_as_an_Array_of_File_objects.yml +166 -0
  55. data/spec/vcr/cassettes/Dropbox_API_File/_share_url/returns_an_Url_object.yml +109 -0
  56. data/spec/vcr/cassettes/Dropbox_API_File/_thumbnail/downloads_a_thumbnail.yml +427 -0
  57. data/spec/vcr/cassettes/Dropbox_API_OAuth/_consumer/provides_an_oauth_method.yml +105 -0
  58. metadata +127 -41
  59. data/.ruby-version +0 -1
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5579887689aae6d9cd0627331ed6bc316cf716db
4
+ data.tar.gz: 92ba58dd36d5563a5ef7ee365c39e58c7762ae4d
5
+ SHA512:
6
+ metadata.gz: 899c18b56ef26a3a02e7f8aeb45be847926880b8a3a21e89db9b6c44367a08dd5c2627c7823fd9a994ef22f26ff309007a8a53de14cc5d1d1ccee29a953538ba
7
+ data.tar.gz: b4d6bc59570bf29e6dc2432840183181f73a5818b5255ee1539689d2439540ada2b49dc8fb7e18356cd0b62a991a7acb4bfd00a722698b920ecce8600fa9761b
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
data/README.markdown CHANGED
@@ -1,11 +1,11 @@
1
1
  Dropbox::API - Dropbox Ruby API client (PeteMS fork...)
2
2
  =========
3
3
 
4
- A Ruby client for the DropBox REST API.
4
+ A Ruby client for the Dropbox REST API.
5
5
 
6
6
  Goal:
7
7
 
8
- To deliver a more Rubyesque experience when using the DropBox API.
8
+ To deliver a more Rubyesque experience when using the Dropbox API.
9
9
 
10
10
  Current state:
11
11
 
@@ -14,11 +14,11 @@ First release, whole API covered.
14
14
  Important!!!
15
15
  ------------
16
16
 
17
- From version 0.2.0, Dropbox::API::File#delete and Dropbox::API::Dir#delete *are gone*!!
17
+ From version 0.2.0, `Dropbox::API::File#delete` and `Dropbox::API::Dir#delete` *are gone*!!
18
18
 
19
19
  The reason is that it's based on Hashie::Mash and was screwing Hash#delete.
20
20
 
21
- It is replaced with Dropbox::API::File#destroy and Dropbox::API::Dir#destroy.
21
+ It is replaced with `Dropbox::API::File#destroy` and `Dropbox::API::Dir#destroy`.
22
22
 
23
23
  Installation
24
24
  ------------
@@ -43,9 +43,10 @@ In order to use this client, you need to have an app created on https://www.drop
43
43
  Once you have it, put this configuration somewhere in your code, before you start working with the client.
44
44
 
45
45
  ```ruby
46
- Dropbox::API::Config.app_key = YOUR_APP_TOKEN
46
+ Dropbox::API::Config.app_key = YOUR_APP_KEY
47
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
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
49
50
  ```
50
51
 
51
52
  Dropbox::API::Client
@@ -54,6 +55,9 @@ Dropbox::API::Client
54
55
  The client is the base for all communication with the API and wraps around almost all calls
55
56
  available in the API.
56
57
 
58
+ Web-based Authorization
59
+ -----------------------
60
+
57
61
  In order to create a Dropbox::API::Client object, you need to have the configuration set up for OAuth.
58
62
  Second thing you need is to have the user authorize your app using OAuth. Here's a short intro
59
63
  on how to do this:
@@ -85,19 +89,20 @@ Dropbox::API supplies you with a helper rake which will authorize a single clien
85
89
  In order to have this rake available, put this on your Rakefile:
86
90
 
87
91
  ```ruby
92
+ require "dropbox-api"
88
93
  require "dropbox-api/tasks"
89
94
  Dropbox::API::Tasks.install
90
95
  ```
91
96
 
92
97
  You will notice that you have a new rake task - dropbox:authorize
93
98
 
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.
99
+ 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.
95
100
 
96
101
  Simply go to that url, authorize the app, then press enter in the console.
97
102
 
98
103
  The rake task will output valid ruby code which you can use to create a client.
99
104
 
100
- What differs this from the DropBox Ruby SDK?
105
+ What differs this from the Dropbox Ruby SDK?
101
106
  --------------------------------------------
102
107
 
103
108
  A few things:
data/Rakefile CHANGED
@@ -1,4 +1,9 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
2
7
 
3
8
  require "dropbox-api/tasks"
4
9
  Dropbox::API::Tasks.install
data/dropbox-api.gemspec CHANGED
@@ -11,20 +11,21 @@ Gem::Specification.new do |s|
11
11
  s.summary = "A Ruby client for the DropBox REST API (Originally by marcinbunsch, forked by petems)"
12
12
  s.description = "To deliver a more Rubyesque experience when using the DropBox API (forked by petems)."
13
13
 
14
- s.rubyforge_project = "dropbox-api"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
15
18
 
16
19
  s.add_dependency 'multi_json', '1.7.9'
17
20
  s.add_dependency 'oauth', '0.4.7'
18
21
  s.add_dependency 'hashie', '2.0.5'
22
+ s.add_dependency 'backports', '3.6.0'
19
23
 
20
24
  s.add_development_dependency 'rspec','2.14.1'
21
25
  s.add_development_dependency 'rake', '10.1.0'
22
- s.add_development_dependency 'simplecov', '0.7.1'
23
- s.add_development_dependency 'ruby-debug19', '0.11.6'
24
- s.add_development_dependency 'yajl-ruby', '1.1.0'
26
+ s.add_development_dependency 'simplecov', '~> 0.8.2'
27
+ s.add_development_dependency 'yajl-ruby', '~> 1.2.0'
25
28
 
26
- s.files = `git ls-files`.split("\n")
27
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
- s.require_paths = ["lib"]
29
+ s.add_development_dependency 'webmock', '~> 1.15.0'
30
+ s.add_development_dependency 'vcr', '~> 2.8.0'
30
31
  end
data/lib/dropbox-api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "oauth"
2
2
  require "multi_json"
3
3
  require "hashie"
4
+ require 'backports'
4
5
 
5
6
  module Dropbox
6
7
  module API
@@ -14,6 +14,11 @@ module Dropbox
14
14
  end
15
15
  end
16
16
 
17
+ def direct_url(options = {})
18
+ response = client.raw.shares({ :path => self.path, :short_url => false }.merge(options))
19
+ Dropbox::API::Object.init(response, client)
20
+ end
21
+
17
22
  end
18
23
 
19
24
  end
@@ -15,16 +15,6 @@ module Dropbox
15
15
  self.update response
16
16
  end
17
17
 
18
- def share_url(options = {})
19
- response = client.raw.shares({ :path => self.path }.merge(options))
20
- Dropbox::API::Object.init(response, client)
21
- end
22
-
23
- def direct_url(options = {})
24
- response = client.raw.media({ :path => self.path }.merge(options))
25
- Dropbox::API::Object.init(response, client)
26
- end
27
-
28
18
  def thumbnail(options = {})
29
19
  client.raw.thumbnails({ :path => self.path }.merge(options))
30
20
  end
@@ -38,6 +28,11 @@ module Dropbox
38
28
  client.download(self.path)
39
29
  end
40
30
 
31
+ def direct_url(options = {})
32
+ response = client.raw.media({ :path => self.path }.merge(options))
33
+ Dropbox::API::Object.init(response, client)
34
+ end
35
+
41
36
  end
42
37
 
43
38
  end
@@ -22,6 +22,11 @@ module Dropbox
22
22
  self['path'].sub(/^\//, '')
23
23
  end
24
24
 
25
+ def share_url(options = {})
26
+ response = client.raw.shares({ :path => self.path }.merge(options))
27
+ Dropbox::API::Object.init(response, client)
28
+ end
29
+
25
30
  end
26
31
 
27
32
  end
@@ -12,9 +12,9 @@ module Dropbox
12
12
  task :authorize do
13
13
  require "dropbox-api"
14
14
  require "cgi"
15
- print "Enter consumer key: "
15
+ print "Enter dropbox app key: "
16
16
  consumer_key = $stdin.gets.chomp
17
- print "Enter consumer secret: "
17
+ print "Enter dropbox app secret: "
18
18
  consumer_secret = $stdin.gets.chomp
19
19
 
20
20
  Dropbox::API::Config.app_key = consumer_key
@@ -1,5 +1,5 @@
1
1
  module Dropbox
2
2
  module API
3
- VERSION = "0.4.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ app_key: '4h2z7bkqpoxnrk5' # CONSUMER KEY
2
+ app_secret: 'jm01iazkteh0iox' # CONSUMER SECRET
3
+ token: 'uaq3brdzaspkyyel' # ACCESS TOKEN
4
+ secret: 'ttg5h86znfxxfgf' # ACCESS SECRET
5
+ mode: 'dropbox' # 'sandbox' or 'dropbox'
@@ -2,10 +2,9 @@
2
2
  require "spec_helper"
3
3
  require "tempfile"
4
4
 
5
- describe Dropbox::API::Client do
5
+ describe Dropbox::API::Client, :vcr => true do
6
6
 
7
7
  before do
8
- # pending
9
8
  @client = Dropbox::Spec.instance
10
9
  end
11
10
 
@@ -22,29 +21,22 @@ describe Dropbox::API::Client do
22
21
  it "retrieves the account object" do
23
22
  response = @client.account
24
23
  response.should be_an_instance_of(Dropbox::API::Object)
24
+ response.email.should eql 'testman@example.com'
25
25
  end
26
26
 
27
27
  end
28
28
 
29
29
  describe "#find" do
30
30
 
31
- before do
32
- @filename = "#{Dropbox::Spec.test_dir}/spec-find-file-test-#{Time.now.to_i}.txt"
33
- @file = @client.upload @filename, "spec file"
34
-
35
- @dirname = "#{Dropbox::Spec.test_dir}/spec-find-dir-test-#{Time.now.to_i}"
36
- @dir = @client.mkdir @dirname
37
- end
38
-
39
31
  it "returns a single file" do
40
- response = @client.find(@filename)
41
- response.path.should == @file.path
32
+ response = @client.find('baz.txt')
33
+ response.path.should == 'baz.txt'
42
34
  response.should be_an_instance_of(Dropbox::API::File)
43
35
  end
44
36
 
45
37
  it "returns a single directory" do
46
- response = @client.find(@dirname)
47
- response.path.should == @dir.path
38
+ response = @client.find('awesome-tests')
39
+ response.path.should == 'awesome-tests'
48
40
  response.should be_an_instance_of(Dropbox::API::Dir)
49
41
  end
50
42
 
@@ -52,16 +44,30 @@ describe Dropbox::API::Client do
52
44
 
53
45
  describe "#ls" do
54
46
 
55
- it "returns an array of files and dirs" do
56
- result = @client.ls
57
- result.should be_an_instance_of(Array)
47
+ context "no value" do
48
+
49
+ it "returns an array of files and dirs" do
50
+ result = @client.ls
51
+ result.should be_an_instance_of(Array)
52
+ end
58
53
  end
59
54
 
60
- it "returns a single item array of if we ls a file" do
61
- result = @client.ls(Dropbox::Spec.test_dir)
62
- first_file = result.detect { |f| f.class == Dropbox::API::File }
63
- result = @client.ls first_file.path
64
- result.should be_an_instance_of(Array)
55
+ context "a single file" do
56
+ it "returns a single item array of if we ls a file" do
57
+ result = @client.ls('foo.txt')
58
+ first_file = result.detect { |f| f.class == Dropbox::API::File }
59
+ result = @client.ls first_file.path
60
+ result.should be_an_instance_of(Array)
61
+ end
62
+ end
63
+
64
+ context "a directory" do
65
+ it "returns an item array of directory contents" do
66
+ result = @client.ls('foo.txt')
67
+ first_file = result.detect { |f| f.class == Dropbox::API::File }
68
+ result = @client.ls first_file.path
69
+ result.should be_an_instance_of(Array)
70
+ end
65
71
  end
66
72
 
67
73
  end
@@ -69,21 +75,21 @@ describe Dropbox::API::Client do
69
75
  describe "#mkdir" do
70
76
 
71
77
  it "returns an array of files and dirs" do
72
- dirname = "#{Dropbox::Spec.test_dir}/test-dir-#{Dropbox::Spec.namespace}"
78
+ dirname = "awesome-tests"
73
79
  response = @client.mkdir dirname
74
80
  response.path.should == dirname
75
81
  response.should be_an_instance_of(Dropbox::API::Dir)
76
82
  end
77
83
 
78
84
  it "creates dirs with tricky characters" do
79
- dirname = "#{Dropbox::Spec.test_dir}/test-dir |!@\#$%^&*{b}[].;'.,<>?: #{Dropbox::Spec.namespace}"
85
+ dirname = "awesome-tests-|!@\#$%^&*{b}[].;'.,<>?:"
80
86
  response = @client.mkdir dirname
81
87
  response.path.should == dirname.gsub(/[\\\:\?\*\<\>\"\|]+/, '')
82
88
  response.should be_an_instance_of(Dropbox::API::Dir)
83
89
  end
84
90
 
85
91
  it "creates dirs with utf8 characters" do
86
- dirname = "#{Dropbox::Spec.test_dir}/test-dir łółą #{Dropbox::Spec.namespace}"
92
+ dirname = "awesome-tests-łółą"
87
93
  response = @client.mkdir dirname
88
94
  response.path.should == dirname
89
95
  response.should be_an_instance_of(Dropbox::API::Dir)
@@ -93,26 +99,33 @@ describe Dropbox::API::Client do
93
99
 
94
100
  describe "#upload" do
95
101
 
96
- it "puts the file in dropbox" do
97
- filename = "#{Dropbox::Spec.test_dir}/test-#{Dropbox::Spec.namespace}.txt"
98
- response = @client.upload filename, "Some file"
99
- response.path.should == filename
100
- response.bytes.should == 9
102
+ context "a simple file" do
103
+ it "is uploaded" do
104
+ filename = "test.txt"
105
+ response = @client.upload filename, "Some file"
106
+ response.path.should == filename
107
+ response.bytes.should == 9
108
+ end
101
109
  end
102
110
 
103
- it "uploads the file with tricky characters" do
104
- filename = "#{Dropbox::Spec.test_dir}/test ,|!@\#$%^&*{b}[].;'.,<>?:-#{Dropbox::Spec.namespace}.txt"
105
- response = @client.upload filename, "Some file"
106
- response.path.should == filename
107
- response.bytes.should == 9
111
+ context "a file with tricky characters" do
112
+ it "is uploaded" do
113
+ filename = "test ,|!@\#$%^&*{b}[].;'.,<>?:.txt"
114
+ response = @client.upload filename, "Some file"
115
+ response.path.should == filename
116
+ response.bytes.should == 9
117
+ end
108
118
  end
109
119
 
110
- it "uploads the file with utf8" do
111
- filename = "#{Dropbox::Spec.test_dir}/test łołąó-#{Dropbox::Spec.namespace}.txt"
112
- response = @client.upload filename, "Some file"
113
- response.path.should == filename
114
- response.bytes.should == 9
120
+ context "a file with utf8" do
121
+ it "is uploaded" do
122
+ filename = "test łołąó.txt"
123
+ response = @client.upload filename, "Some file"
124
+ response.path.should == filename
125
+ response.bytes.should == 9
126
+ end
115
127
  end
128
+
116
129
  end
117
130
 
118
131
  describe "#chunked_upload" do
@@ -123,14 +136,18 @@ describe Dropbox::API::Client do
123
136
  @file = File.open(@filename, "w") {|f| f.write "a"*@size}
124
137
  end
125
138
 
126
- it "puts a 5MB file in dropbox" do
139
+ it "puts a 5MB file in dropbox", :vcr => { :match_requests_on => [:host] } do
127
140
  filename = "#{Dropbox::Spec.test_dir}/test-5MB-#{Dropbox::Spec.namespace}.txt"
128
141
  response = @client.chunked_upload filename, File.open(@filename)
129
- response.path.should == filename
142
+ if ENV['RECORDING'] == 'true'
143
+ response.path.should == filename
144
+ else
145
+ response.path.should == 'test-1410120674/test-5MB-1410120674.txt'
146
+ end
130
147
  response.bytes.should == @size
131
148
  end
132
149
 
133
- it "yields current offset and upload id" do
150
+ it "yields current offset and upload id", :vcr => { :match_requests_on => [:host] } do
134
151
  filename = "#{Dropbox::Spec.test_dir}/test-yield-#{Dropbox::Spec.namespace}.txt"
135
152
  log_offset = ""
136
153
  log_upload = ""
@@ -140,7 +157,11 @@ describe Dropbox::API::Client do
140
157
  log_upload += upload.inspect
141
158
  upload[:upload_id].length.should eq(22)
142
159
  end
143
- response.path.should == filename
160
+ if ENV['RECORDING'] == 'true'
161
+ response.path.should == filename
162
+ else
163
+ response.path.should == 'test-1410121457/test-yield-1410121457.txt'
164
+ end
144
165
  response.bytes.should == @size
145
166
  log_offset.should match(/[\d]{7},[\d]{7},/)
146
167
  log_upload.should include("Dropbox::API::Object","upload_id=")
@@ -154,24 +175,30 @@ describe Dropbox::API::Client do
154
175
 
155
176
  describe "#search" do
156
177
 
157
- let(:term) { "searchable-test-#{Dropbox::Spec.namespace}" }
158
-
159
- before do
160
- filename = "#{Dropbox::Spec.test_dir}/searchable-test-#{Dropbox::Spec.namespace}.txt"
161
- @client.upload filename, "Some file"
162
- end
178
+ let(:term) { "foo.txt" }
163
179
 
164
180
  after do
165
181
  @response.size.should == 1
166
182
  @response.first.class.should == Dropbox::API::File
167
183
  end
168
184
 
169
- it "finds a file" do
170
- @response = @client.search term, :path => "#{Dropbox::Spec.test_dir}"
185
+ context "with path" do
186
+ it "finds a file" do
187
+ @response = @client.search term, :path => "awesome-tests"
188
+ end
189
+ end
190
+
191
+ context "path with leading slash" do
192
+ it "finds the file" do
193
+ @response = @client.search term, :path => "/awesome-tests"
194
+ end
195
+
171
196
  end
172
197
 
173
- it "works if leading slash is present in path" do
174
- @response = @client.search term, :path => "/#{Dropbox::Spec.test_dir}"
198
+ context "no path given" do
199
+ it "finds the file if in root" do
200
+ @response = @client.search term
201
+ end
175
202
  end
176
203
 
177
204
  end
@@ -179,12 +206,12 @@ describe Dropbox::API::Client do
179
206
  describe "#copy_from_copy_ref" do
180
207
 
181
208
  it "copies a file from a copy_ref" do
182
- filename = "test/searchable-test-#{Dropbox::Spec.namespace}.txt"
209
+ filename = "test/searchable-test-100.txt"
183
210
  @client.upload filename, "Some file"
184
- response = @client.search "searchable-test-#{Dropbox::Spec.namespace}", :path => 'test'
211
+ response = @client.search "searchable-test-100", :path => 'test'
185
212
  ref = response.first.copy_ref['copy_ref']
186
213
  @client.copy_from_copy_ref ref, "#{filename}.copied"
187
- response = @client.search "searchable-test-#{Dropbox::Spec.namespace}.txt.copied", :path => 'test'
214
+ response = @client.search "searchable-test-100.txt.copied", :path => 'test'
188
215
  response.size.should == 1
189
216
  response.first.class.should == Dropbox::API::File
190
217
  end
@@ -193,23 +220,24 @@ describe Dropbox::API::Client do
193
220
 
194
221
  describe "#download" do
195
222
 
196
- it "downloads a file from Dropbox" do
197
- @client.upload "#{Dropbox::Spec.test_dir}/test.txt", "Some file"
198
- file = @client.download "#{Dropbox::Spec.test_dir}/test.txt"
199
- file.should == "Some file"
223
+ context "a file" do
224
+ it "downloads a file" do
225
+ file = @client.download "awesome-tests/foo.txt"
226
+ file.should == "Some file"
227
+ end
200
228
  end
201
229
 
202
- it "raises a 404 when a file is not found in Dropbox" do
203
- lambda {
204
- @client.download "#{Dropbox::Spec.test_dir}/no.txt"
205
- }.should raise_error(Dropbox::API::Error::NotFound)
230
+ context "a non-existant file" do
231
+ it "raises a 404" do
232
+ expect { @client.download "awesome-tests/no.txt"}.to raise_error(Dropbox::API::Error::NotFound)
233
+ end
206
234
  end
207
235
 
208
236
  end
209
237
 
210
238
  describe "#delta" do
211
239
  it "returns a cursor and list of files" do
212
- filename = "#{Dropbox::Spec.test_dir}/delta-test-#{Dropbox::Spec.namespace}.txt"
240
+ filename = "awesome-tests/delta-test-foo.txt"
213
241
  @client.upload filename, 'Some file'
214
242
  response = @client.delta
215
243
  cursor, files = response.cursor, response.entries
@@ -219,8 +247,8 @@ describe Dropbox::API::Client do
219
247
  end
220
248
 
221
249
  it "returns the files that have changed since the cursor was made" do
222
- filename = "#{Dropbox::Spec.test_dir}/delta-test-#{Dropbox::Spec.namespace}.txt"
223
- delete_filename = "#{Dropbox::Spec.test_dir}/delta-test-delete-#{Dropbox::Spec.namespace}.txt"
250
+ filename = "awesome-tests/delta-test-bar.txt"
251
+ delete_filename = "awesome-tests/delta-test-baz.txt"
224
252
  @client.upload delete_filename, 'Some file'
225
253
  response = @client.delta
226
254
  cursor, files = response.cursor, response.entries