dbox 0.3.0 → 0.4.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/README.md CHANGED
@@ -97,6 +97,12 @@ $ dbox pull [<local_path>]
97
97
  $ dbox push [<local_path>]
98
98
  ```
99
99
 
100
+ #### Move (move/rename the Dropbox folder)
101
+
102
+ ```sh
103
+ $ dbox move <new_remote_path> [<local_path>]
104
+ ```
105
+
100
106
  #### Example
101
107
 
102
108
  ```sh
@@ -140,6 +146,12 @@ Oh, Hello
140
146
  Using dbox from Ruby
141
147
  --------------------
142
148
 
149
+ The Ruby clone, pull, and push APIs return a hash listing the changes made during that pull/push.
150
+
151
+ ```ruby
152
+ { :created => ["foo.txt"], :deleted => [], :updated => [] }
153
+ ```
154
+
143
155
  ### Usage
144
156
 
145
157
  #### Setup
@@ -174,6 +186,12 @@ Dbox.pull(local_path)
174
186
  Dbox.push(local_path)
175
187
  ```
176
188
 
189
+ #### Move (move/rename the Dropbox folder)
190
+
191
+ ```ruby
192
+ Dbox.move(new_remote_path, local_path)
193
+ ```
194
+
177
195
  #### Example
178
196
 
179
197
  ```sh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/bin/dbox CHANGED
@@ -9,11 +9,12 @@ def usage
9
9
  Usage: dbox <commond> [<args>]
10
10
 
11
11
  Commands:
12
- authorize Generate auth keys
13
- create <remote_path> [<local_path>] Create a new Dropbox folder
14
- clone <remote_path> [<local_path>] Clone an existing Dropbox folder
15
- pull [<local_path>] Pull chonges from Dropbox
16
- push [<local_path>] Push changes to Dropbox
12
+ authorize Generate auth keys
13
+ create <remote_path> [<local_path>] Create a new Dropbox folder
14
+ clone <remote_path> [<local_path>] Clone an existing Dropbox folder
15
+ pull [<local_path>] Pull chonges from Dropbox
16
+ push [<local_path>] Push changes to Dropbox
17
+ move <new_remote_path> [<local_path>] Move the remote Dropbox folder to a new location
17
18
 
18
19
  Environment varables needed for everything:
19
20
  export DROPBOX_APP_KEY=cmlrrjd3j0gbend
@@ -56,6 +57,13 @@ when "pull", "push"
56
57
  local_path = args[0] || "."
57
58
 
58
59
  Dbox.send(command, local_path)
60
+ when "move"
61
+ remote_path = args[0]
62
+
63
+ # default to current directory
64
+ local_path = args[1] || "."
65
+
66
+ Dbox.send(command, remote_path, local_path)
59
67
  else
60
68
  print_usage_and_quit
61
69
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dbox}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Ken Pratt}]
12
- s.date = %q{2011-05-14}
12
+ s.date = %q{2011-05-16}
13
13
  s.description = %q{An easy-to-use Dropbox client with fine-grained control over syncs.}
14
14
  s.email = %q{ken@kenpratt.net}
15
15
  s.executables = [%q{dbox}]
@@ -39,6 +39,12 @@ module Dbox
39
39
  Dbox::DB.push(local_path)
40
40
  end
41
41
 
42
+ def self.move(new_remote_path, local_path)
43
+ new_remote_path = clean_remote_path(new_remote_path)
44
+ local_path = clean_local_path(local_path)
45
+ Dbox::DB.move(new_remote_path, local_path)
46
+ end
47
+
42
48
  private
43
49
 
44
50
  def self.clean_remote_path(path)
@@ -120,6 +120,19 @@ module Dbox
120
120
  end
121
121
  end
122
122
 
123
+ def move(old_path, new_path)
124
+ log.info "Moving #{old_path} to #{new_path}"
125
+ run(old_path) do |old_path|
126
+ new_path = escape_path(new_path)
127
+ case res = @client.file_move(@conf["root"], old_path, new_path)
128
+ when Net::HTTPBadRequest
129
+ raise RemoteAlreadyExists, "Error during move -- there may already be a Dropbox folder at #{new_path}"
130
+ else
131
+ res
132
+ end
133
+ end
134
+ end
135
+
123
136
  def escape_path(path)
124
137
  URI.escape(path)
125
138
  end
@@ -41,6 +41,10 @@ module Dbox
41
41
  load(local_path).push
42
42
  end
43
43
 
44
+ def self.move(new_remote_path, local_path)
45
+ load(local_path).move(new_remote_path)
46
+ end
47
+
44
48
  # IMPORTANT: DropboxDb.new is private. Please use DropboxDb.create, DropboxDb.clone, or DropboxDb.load as the entry point.
45
49
  private_class_method :new
46
50
  def initialize(local_path, res)
@@ -69,6 +73,12 @@ module Dbox
69
73
  res
70
74
  end
71
75
 
76
+ def move(new_remote_path)
77
+ api.move(@remote_path, new_remote_path)
78
+ @remote_path = new_remote_path
79
+ save
80
+ end
81
+
72
82
  def local_to_relative_path(path)
73
83
  if path.include?(@local_path)
74
84
  path.sub(@local_path, "").sub(/^\//, "")
@@ -182,4 +182,30 @@ describe Dbox do
182
182
  Dbox.pull(@local).should eql(:created => [], :deleted => [], :updated => [])
183
183
  end
184
184
  end
185
+
186
+ describe "#move" do
187
+ before(:each) do
188
+ @new_name = randname()
189
+ @new_local = File.join(LOCAL_TEST_PATH, @new_name)
190
+ @new_remote = File.join(REMOTE_TEST_PATH, @new_name)
191
+ end
192
+
193
+ it "should fail if the local dir is missing" do
194
+ expect { Dbox.move(@new_remote, @local) }.to raise_error(Dbox::MissingDatabase)
195
+ end
196
+
197
+ it "should be able to move" do
198
+ Dbox.create(@remote, @local)
199
+ expect { Dbox.move(@new_remote, @local) }.to_not raise_error
200
+ @local.should exist
201
+ expect { Dbox.clone(@new_remote, @new_local) }.to_not raise_error
202
+ @new_local.should exist
203
+ end
204
+
205
+ it "should not be able to move to a location that exists" do
206
+ Dbox.create(@remote, @local)
207
+ Dbox.create(@new_remote, @new_local)
208
+ expect { Dbox.move(@new_remote, @local) }.to raise_error(Dbox::RemoteAlreadyExists)
209
+ end
210
+ end
185
211
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Pratt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-14 00:00:00 Z
18
+ date: 2011-05-16 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: An easy-to-use Dropbox client with fine-grained control over syncs.