boxr 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4228f0c6466f0201da66c3cd077351503d1d53674d92b28ba0796866d4a4b51c
4
- data.tar.gz: f88a5fa3b4065b3b491dc28491c86bfbe2f02a31c6e5a73cf5312910eb86752f
3
+ metadata.gz: e02b3471599db059d5a1e9f7ae8b06757c60fe66d576b3083fd1e3799fac49f1
4
+ data.tar.gz: d0ce9eb18ef1464b14d48ce45872a6a3768e4be14ebe9d2c903cb3172e0e791c
5
5
  SHA512:
6
- metadata.gz: '045222090425c6e3200174120967ffc2d3b0322db99f1aee9ce834cf7de6a9b5c41ffb0590a4547c21365476f7e1827ad27e84c95e7674645151b1c07c33886a'
7
- data.tar.gz: 94909a12a7d0ab30c3939412bb03d4ae89760b9bfcf2c78552da7fb178bdb3718e060e50cb59cf6f3647804557f79c67194bc9f5ca35544b2d504110e9061c93
6
+ metadata.gz: 6d45931744e3c77a0a29ee071a5da104f91152fff14471421187435e186f62b1964361a81b97b697e38226da95af814d1d9cf3bc0a905aed1980090e47a55deb
7
+ data.tar.gz: a3b3bad61ff4c59678e7d116e0f5250e6172b01d07572a96436e4b23af76dc72e6cca894233278e131610e91a62cb84ed63c1c520fa5ffb1e9a345b8f84da1be
data/README.md CHANGED
@@ -223,11 +223,17 @@ download_url(file, version: nil)
223
223
  upload_file(path_to_file, parent, content_created_at: nil, content_modified_at: nil,
224
224
  preflight_check: true, send_content_md5: true)
225
225
 
226
+ upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil,
227
+ preflight_check: true, send_content_md5: true)
228
+
226
229
  delete_file(file, if_match: nil)
227
230
 
228
231
  upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true,
229
232
  preflight_check: true, if_match: nil)
230
233
 
234
+ upload_new_version_of_file_from_io(io, file, name: nil, content_modified_at: nil, send_content_md5: true,
235
+ preflight_check: true, if_match: nil)
236
+
231
237
  versions_of_file(file)
232
238
 
233
239
  promote_old_version_of_file(file, file_version)
data/lib/boxr/files.rb CHANGED
@@ -136,21 +136,35 @@ module Boxr
136
136
  preflight_check: true, if_match: nil, name: nil)
137
137
  filename = name ? name : File.basename(path_to_file)
138
138
 
139
+ File.open(path_to_file) do |io|
140
+ upload_new_version_of_file_from_io(io, file, name: filename, content_modified_at: content_modified_at, preflight_check: preflight_check, send_content_md5: send_content_md5, if_match: if_match)
141
+ end
142
+ end
143
+
144
+ def upload_new_version_of_file_from_io(io, file, name: nil, content_modified_at: nil, send_content_md5: true,
145
+ preflight_check: true, if_match: nil)
146
+
147
+ filename = name ? name : file.name
148
+
139
149
  file_id = ensure_id(file)
140
- preflight_check_new_version_of_file(path_to_file, file_id) if preflight_check
150
+ preflight_check_new_version_of_file(io, file_id) if preflight_check
141
151
 
142
152
  uri = "#{UPLOAD_URI}/files/#{file_id}/content"
143
153
  file_info = nil
144
154
  response = nil
145
155
 
146
- File.open(path_to_file) do |file|
147
- content_md5 = send_content_md5 ? Digest::SHA1.file(file).hexdigest : nil
148
- attributes = {name: filename}
149
- attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
150
- body = {attributes: JSON.dump(attributes), file: file}
151
- file_info, response = post(uri, body, process_body: false, content_md5: content_md5, if_match: if_match)
156
+ if send_content_md5
157
+ content_md5 = Digest::SHA1.hexdigest(io.read)
158
+ io.rewind
152
159
  end
153
160
 
161
+ attributes = {name: name}
162
+ attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
163
+
164
+ body = {attributes: JSON.dump(attributes), file: io}
165
+
166
+ file_info, response = post(uri, body, process_body: false, content_md5: content_md5, if_match: if_match)
167
+
154
168
  file_info.entries[0]
155
169
  end
156
170
 
@@ -265,8 +279,8 @@ module Boxr
265
279
  body_json, res = options("#{FILES_URI}/content", attributes)
266
280
  end
267
281
 
268
- def preflight_check_new_version_of_file(path_to_file, file_id)
269
- size = File.size(path_to_file)
282
+ def preflight_check_new_version_of_file(io, file_id)
283
+ size = File.size(io)
270
284
  attributes = {size: size}
271
285
  body_json, res = options("#{FILES_URI}/#{file_id}/content", attributes)
272
286
  end
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "1.16.0".freeze
2
+ VERSION = "1.17.0".freeze
3
3
  end
@@ -67,20 +67,25 @@ describe "file operations" do
67
67
  new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}", test_file)
68
68
  expect(new_version.id).to eq(test_file.id)
69
69
 
70
+ puts "upload new version of file from IO"
71
+ io = File.open("./spec/test_files/#{TEST_FILE_NAME}")
72
+ new_version = BOX_CLIENT.upload_new_version_of_file_from_io(io, test_file)
73
+ expect(new_version.id).to eq(test_file.id)
74
+
70
75
  puts "inspect versions of file"
71
76
  versions = BOX_CLIENT.versions_of_file(test_file)
72
- expect(versions.count).to eq(1) #the reason this is 1 instead of 2 is that Box considers 'versions' to be a versions other than 'current'
77
+ expect(versions.count).to eq(2) #the reason this is 2 instead of 3 is that Box considers 'versions' to be a versions other than 'current'
73
78
  v1 = versions.first
74
79
 
75
80
  puts "promote old version of file"
76
81
  newer_version = BOX_CLIENT.promote_old_version_of_file(test_file, v1)
77
82
  versions = BOX_CLIENT.versions_of_file(test_file)
78
- expect(versions.count).to eq(2)
83
+ expect(versions.count).to eq(3)
79
84
 
80
85
  puts "delete old version of file"
81
86
  result = BOX_CLIENT.delete_old_version_of_file(test_file,v1)
82
87
  versions = BOX_CLIENT.versions_of_file(test_file)
83
- expect(versions.count).to eq(2) #this is still 2 because with Box you can restore a trashed old version
88
+ expect(versions.count).to eq(3) #this is still 3 because with Box you can restore a trashed old version
84
89
 
85
90
  puts "get file thumbnail"
86
91
  thumb = BOX_CLIENT.thumbnail(test_file)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Burnette
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-26 00:00:00.000000000 Z
12
+ date: 2021-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler