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 +4 -4
- data/README.md +6 -0
- data/lib/boxr/files.rb +23 -9
- data/lib/boxr/version.rb +1 -1
- data/spec/boxr/files_spec.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e02b3471599db059d5a1e9f7ae8b06757c60fe66d576b3083fd1e3799fac49f1
|
4
|
+
data.tar.gz: d0ce9eb18ef1464b14d48ce45872a6a3768e4be14ebe9d2c903cb3172e0e791c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
-
|
147
|
-
content_md5 =
|
148
|
-
|
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(
|
269
|
-
size = File.size(
|
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
data/spec/boxr/files_spec.rb
CHANGED
@@ -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(
|
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(
|
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(
|
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.
|
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:
|
12
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|