boxr 1.10.0 → 1.11.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: 04ca88d5d328877cca29dd525572f39a8d08eb1fab798f161854746daa7b8679
4
- data.tar.gz: 2243419e800241709f0565b0f4ce698e62ebce286f2a1eead58e50202ea66ecb
3
+ metadata.gz: 6969054c88e9121a9e493624a6ca310e25ecef80e7e090a0787072316c134d14
4
+ data.tar.gz: 3bfbb76ecc1ea2b5ee087957d287c6c19cd83ad1ae7223cfaf63e15860c85746
5
5
  SHA512:
6
- metadata.gz: d3b6c2986449944d0d5cca6a2305e615e7387adff4d1e932bad5eb5431d7b48b87c57bb0d6c95a06586e0a98c896aaff94c09cf56a2ae8e9a7a6da36e878b911
7
- data.tar.gz: d8d373850ad0b6f4ac9d99501dfe62a74ff00590a109c05ef7ea7bd1ea579036629114fe5de289db17234da45a49256d365046a819a9332dc2e8cf123fd933ae
6
+ metadata.gz: d13fcc1f7f992e067ca2e08c46dc76b415e61876081cdfd3d0431d5eebe3e7a012647278e4242a649c50b94cc29f44cc06ae1a817040b1fa979f4bd1eb9d850e
7
+ data.tar.gz: b60656c4fe173dd46ab2db57cad3d9db619c2e9eb234a47b7894ef7a22a37b35fad1bcdaf4842258f8fc0da490686b0b8a1b4be7620e0e0d05aded338947947d
@@ -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
- file, response = get(location, process_response: false)
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 file
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
- content_md5 = send_content_md5 ? Digest::SHA1.file(file).hexdigest : nil
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
- attributes = {name: filename, parent: {id: parent_id}}
120
- attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
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
- body = {attributes: JSON.dump(attributes), file: file}
117
+ preflight_check(io, name, parent_id) if preflight_check
124
118
 
125
- file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5)
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(path_to_file, filename, parent_id)
258
- size = File.size(path_to_file)
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}
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "1.10.0"
2
+ VERSION = "1.11.0"
3
3
  end
@@ -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
- file = BOX_CLIENT.download_file(test_file)
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(file)
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)
@@ -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.10.0
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-15 00:00:00.000000000 Z
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler