ruby-box 1.9.2 → 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGE5MjEyYWJjNzVmNmEwZTVjNjkxODVjNDVmNzUyYzExMDU3ZjJjYw==
4
+ ODE3OWJkYWM1ZTZkNzU5NjczZGU3Yzk5Y2I1MjZkNjhiZWI2OGIwZQ==
5
5
  data.tar.gz: !binary |-
6
- YWFmYjlmNWQ2MmQ0YzE1YWZhZjgxOGMyYzA0NDQ3NDJjZDY4YjQwOA==
6
+ NzYxZjVkNWJiZDg2MDdiYTVmMmI5ZDg3MjQwZGIzNzNiMjRiNTQxYg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjFlN2QzYWI5MDg5MThlYzljNzg5MDJlYjgyNzg0MDQ5MGU2YzUzOWU2NDdl
10
- YmU0MWE5MWU1NDNlMzBmNjlmNzY0YzQ3NWIxYzA4NTNlNzQzYjM1ZGM4ZGU2
11
- YjIxNGI5MTE4YmQwMjQxZTQ4NGM1OTI4Y2Q4YTk0MjYwZDhmNTk=
9
+ ZWU0ZjE0YzVjZmNiMGEyZmU3NmNiNWE2ZjRiMDlkYmIyNTY5Mjc2MTRhZTdm
10
+ NGE1NWMyZGYwNDM4MTRmZWI5ZmU5MTM4ZDYzZjQxMmJiZjBhOWQ0ODRiYjdh
11
+ NTVmNDE3OWZkNTlmZTJiZTA1NTU5MjQ2MzNkNmY0MWI5ZGYxNzc=
12
12
  data.tar.gz: !binary |-
13
- YzExZWI2N2ZmYTQyNWU1YjVmZWFjZjZjN2MzOWFlNDc3MjZhOTBiNTMzMGY2
14
- OGM1NDI4MGY3MGU0YjlkM2E4ZWExZWI2MzlhMTUxNWI5YTQ0NTA4NDRmMTc3
15
- N2JkMDFlYzJmZTc3M2E5MDcyMzRiM2U5YWRhOGViZTNlM2U2Y2M=
13
+ MjVmYjNkMjQ4NmMyNmJlMDczZmY5YTQ5ODE1ZmY4MTExMTkwZWMyMWQ3ZGVm
14
+ MGRlZDlkZGJkMDM4ZDk1ZGJhZTI5ZmU4ZTk4ZDc3ZmEwOGZjYmM3YjYxYWQ1
15
+ MWIyM2Y1NDY5OTdjOWUwY2M2MzYwNWNhMzk1OWNhZWUyZjA3M2E=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.2
1
+ 1.9.3
@@ -70,19 +70,19 @@ module RubyBox
70
70
  folder
71
71
  end
72
72
 
73
- def upload_data(path, data)
73
+ def upload_data(path, data, overwrite=true)
74
74
  path = split_path(path)
75
75
  file_name = path.pop
76
76
  folder = create_folder(path.join('/'))
77
- folder.upload_file(file_name, data) if folder
77
+ folder.upload_file(file_name, data, overwrite) if folder
78
78
  end
79
79
 
80
- def upload_file(local_path, remote_path)
80
+ def upload_file(local_path, remote_path, overwrite=true)
81
81
  file_name = local_path.split('/').pop
82
82
  folder = create_folder( remote_path )
83
83
  return unless folder
84
84
  ::File.open( local_path ) do |data|
85
- folder.upload_file(file_name, data)
85
+ folder.upload_file(file_name, data, overwrite)
86
86
  end
87
87
  end
88
88
 
@@ -13,7 +13,7 @@ module RubyBox
13
13
  items_by_type(RubyBox::Folder, name, item_limit, offset, fields)
14
14
  end
15
15
 
16
- def upload_file(filename, data)
16
+ def upload_file(filename, data, overwrite=true)
17
17
  file = RubyBox::File.new(@session, {
18
18
  'name' => filename,
19
19
  'parent' => RubyBox::User.new(@session, {'id' => id})
@@ -22,6 +22,11 @@ module RubyBox
22
22
  begin
23
23
  resp = file.upload_content(data) #write a new file. If there is a conflict, update the conflicted file.
24
24
  rescue RubyBox::ItemNameInUse => e
25
+
26
+ # if overwrite flag is false, simply raise exception.
27
+ raise e unless overwrite
28
+
29
+ # otherwise let's attempt to overwrite the file.
25
30
  data.rewind
26
31
 
27
32
  # The Box API occasionally does not return
data/ruby-box.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-box"
8
- s.version = "1.9.2"
8
+ s.version = "1.9.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Attachments.me"]
12
- s.date = "2013-08-05"
12
+ s.date = "2013-08-07"
13
13
  s.description = "ruby gem for box.com 2.0 api"
14
14
  s.email = "ben@attachments.me"
15
15
  s.extra_rdoc_files = [
@@ -123,6 +123,15 @@ describe RubyBox, :skip => true do
123
123
  file.name.should == '遠志教授.jpg'
124
124
  file.delete
125
125
  end
126
+
127
+ it 'should raise an exception if files collide and overwrite is false' do
128
+ fdata = File.open( 'spec/fixtures/遠志教授.jpg', 'rb' )
129
+ file = @client.upload_data('/ruby-box_gem_testing/cool stuff/遠志教授.jpg', fdata)
130
+ fdata = File.open( 'spec/fixtures/遠志教授.jpg', 'rb' )
131
+
132
+ expect{ @client.upload_data('/ruby-box_gem_testing/cool stuff/遠志教授.jpg', fdata, false) }.to raise_error(RubyBox::ItemNameInUse)
133
+ file.delete
134
+ end
126
135
 
127
136
  it "should upload a new file" do
128
137
  utf8_file_name = '遠志教授.jpg'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attachments.me
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-05 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post