boxr 1.10.0 → 1.11.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.
- checksums.yaml +4 -4
- data/lib/boxr/files.rb +23 -19
- data/lib/boxr/version.rb +1 -1
- data/spec/boxr/files_spec.rb +10 -2
- data/spec/boxr_spec.rb +1 -0
- 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: 6969054c88e9121a9e493624a6ca310e25ecef80e7e090a0787072316c134d14
|
4
|
+
data.tar.gz: 3bfbb76ecc1ea2b5ee087957d287c6c19cd83ad1ae7223cfaf63e15860c85746
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d13fcc1f7f992e067ca2e08c46dc76b415e61876081cdfd3d0431d5eebe3e7a012647278e4242a649c50b94cc29f44cc06ae1a817040b1fa979f4bd1eb9d850e
|
7
|
+
data.tar.gz: b60656c4fe173dd46ab2db57cad3d9db619c2e9eb234a47b7894ef7a22a37b35fad1bcdaf4842258f8fc0da490686b0b8a1b4be7620e0e0d05aded338947947d
|
data/lib/boxr/files.rb
CHANGED
@@ -75,6 +75,7 @@ module Boxr
|
|
75
75
|
|
76
76
|
def download_file(file, version: nil, follow_redirect: true)
|
77
77
|
file_id = ensure_id(file)
|
78
|
+
|
78
79
|
begin
|
79
80
|
uri = "#{FILES_URI}/#{file_id}/content"
|
80
81
|
query = {}
|
@@ -85,7 +86,8 @@ module Boxr
|
|
85
86
|
location = response.header['Location'][0]
|
86
87
|
|
87
88
|
if(follow_redirect)
|
88
|
-
|
89
|
+
file_content, response = get(location, process_response: false)
|
90
|
+
return file_content
|
89
91
|
else
|
90
92
|
return location #simply return the url
|
91
93
|
end
|
@@ -93,9 +95,7 @@ module Boxr
|
|
93
95
|
retry_after_seconds = response.header['Retry-After'][0]
|
94
96
|
sleep retry_after_seconds.to_i
|
95
97
|
end
|
96
|
-
end until
|
97
|
-
|
98
|
-
file
|
98
|
+
end until file_content
|
99
99
|
end
|
100
100
|
|
101
101
|
def download_url(file, version: nil)
|
@@ -104,27 +104,31 @@ module Boxr
|
|
104
104
|
|
105
105
|
def upload_file(path_to_file, parent, name: nil, content_created_at: nil, content_modified_at: nil,
|
106
106
|
preflight_check: true, send_content_md5: true)
|
107
|
-
|
108
|
-
parent_id = ensure_id(parent)
|
109
|
-
|
110
107
|
filename = name ? name : File.basename(path_to_file)
|
111
|
-
preflight_check(path_to_file, filename, parent_id) if preflight_check
|
112
|
-
|
113
|
-
file_info = nil
|
114
|
-
response = nil
|
115
108
|
|
116
109
|
File.open(path_to_file) do |file|
|
117
|
-
|
110
|
+
upload_file_from_io(file, parent, name: filename, content_created_at: content_created_at, content_modified_at: content_modified_at, preflight_check: preflight_check, send_content_md5: send_content_md5)
|
111
|
+
end
|
112
|
+
end
|
118
113
|
|
119
|
-
|
120
|
-
|
121
|
-
attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
|
114
|
+
def upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true)
|
115
|
+
parent_id = ensure_id(parent)
|
122
116
|
|
123
|
-
|
117
|
+
preflight_check(io, name, parent_id) if preflight_check
|
124
118
|
|
125
|
-
|
119
|
+
if send_content_md5
|
120
|
+
content_md5 = Digest::SHA1.hexdigest(io.read)
|
121
|
+
io.rewind
|
126
122
|
end
|
127
123
|
|
124
|
+
attributes = {name: name, parent: {id: parent_id}}
|
125
|
+
attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
|
126
|
+
attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
|
127
|
+
|
128
|
+
body = {attributes: JSON.dump(attributes), file: io}
|
129
|
+
|
130
|
+
file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5)
|
131
|
+
|
128
132
|
file_info.entries[0]
|
129
133
|
end
|
130
134
|
|
@@ -254,8 +258,8 @@ module Boxr
|
|
254
258
|
|
255
259
|
private
|
256
260
|
|
257
|
-
def preflight_check(
|
258
|
-
size = File.size(
|
261
|
+
def preflight_check(io, filename, parent_id)
|
262
|
+
size = File.size(io)
|
259
263
|
|
260
264
|
#TODO: need to make sure that figuring out the filename from the path_to_file works for people using Windows
|
261
265
|
attributes = {name: filename, parent: {id: "#{parent_id}"}, size: size}
|
data/lib/boxr/version.rb
CHANGED
data/spec/boxr/files_spec.rb
CHANGED
@@ -12,6 +12,11 @@ describe "file operations" do
|
|
12
12
|
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder, name: TEST_FILE_NAME_CUSTOM)
|
13
13
|
expect(new_file.name).to eq(TEST_FILE_NAME_CUSTOM)
|
14
14
|
|
15
|
+
puts "upload a file from IO"
|
16
|
+
io = File.open("./spec/test_files/#{TEST_FILE_NAME}")
|
17
|
+
new_file = BOX_CLIENT.upload_file_from_io(io, @test_folder, name: TEST_FILE_NAME_IO)
|
18
|
+
expect(new_file.name).to eq(TEST_FILE_NAME_IO)
|
19
|
+
|
15
20
|
puts "get file using path"
|
16
21
|
file = BOX_CLIENT.file_from_path("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
|
17
22
|
expect(file.id).to eq(test_file.id)
|
@@ -50,13 +55,16 @@ describe "file operations" do
|
|
50
55
|
expect(unlocked_file.lock).to be_nil
|
51
56
|
|
52
57
|
puts "download file"
|
53
|
-
|
58
|
+
file_content = BOX_CLIENT.download_file(test_file)
|
54
59
|
f = File.open("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}", 'w+')
|
55
|
-
f.write(
|
60
|
+
f.write(file_content)
|
56
61
|
f.close
|
57
62
|
expect(FileUtils.identical?("./spec/test_files/#{TEST_FILE_NAME}","./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")).to eq(true)
|
58
63
|
File.delete("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")
|
59
64
|
|
65
|
+
puts "download invalid file"
|
66
|
+
expect { BOX_CLIENT.download_file('INVALID_FILE_NAME.pdf') }.to raise_exception(Boxr::BoxrError)
|
67
|
+
|
60
68
|
puts "upload new version of file"
|
61
69
|
new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}", test_file)
|
62
70
|
expect(new_version.id).to eq(test_file.id)
|
data/spec/boxr_spec.rb
CHANGED
@@ -29,6 +29,7 @@ describe Boxr::Client do
|
|
29
29
|
SUB_FOLDER_DESCRIPTION = 'This was created by the Boxr test suite'
|
30
30
|
TEST_FILE_NAME = 'test file.txt'
|
31
31
|
TEST_FILE_NAME_CUSTOM = 'test file custom.txt'
|
32
|
+
TEST_FILE_NAME_IO = 'test file io.txt'
|
32
33
|
DOWNLOADED_TEST_FILE_NAME = 'downloaded test file.txt'
|
33
34
|
COMMENT_MESSAGE = 'this is a comment'
|
34
35
|
REPLY_MESSAGE = 'this is a comment reply'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Burnette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|