-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to creates a request to download multiple files and fol…
…ders as a zip file (#116)
- Loading branch information
Showing
8 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Boxr | ||
class Client | ||
def create_zip_download(targets, download_file_name: nil) | ||
attributes = { | ||
download_file_name: download_file_name, | ||
items: targets | ||
} | ||
zip_download, _response = post(ZIP_DOWNLOADS_URI, attributes, success_codes: [200, 202]) | ||
zip_download | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'zip' | ||
|
||
# rake spec SPEC_OPTS="-e \"invokes zip downloads operations"\" | ||
describe 'zip downloads operations' do | ||
it 'invokes zip downloads operations' do | ||
test_file_path = "./spec/test_files/#{TEST_FILE_NAME}" | ||
download_zip_path = "./spec/test_files/#{DOWNLOADED_ZIP_TEST_FILE_NAME}" | ||
unzip_path = "./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}" | ||
|
||
puts 'upload a file' | ||
new_file = BOX_CLIENT.upload_file(test_file_path, @test_folder) | ||
expect(new_file.name).to eq(TEST_FILE_NAME) | ||
|
||
puts 'create zip downloads' | ||
new_zip_download = BOX_CLIENT.create_zip_download( | ||
[{ id: new_file.id, type: 'file' }], | ||
download_file_name: 'test.zip' | ||
) | ||
expect(new_zip_download.download_url).to match(URI::regexp) | ||
expect(new_zip_download.status_url).to match(URI::regexp) | ||
|
||
# download and unzip | ||
URI.open(new_zip_download.download_url) do |zip_content| | ||
File.open(download_zip_path, 'w+') { |file| file.write(zip_content.read) } | ||
end | ||
Zip::File.open(download_zip_path) do |zip_file| | ||
zip_file.each { |entry| entry.extract(unzip_path) } | ||
end | ||
|
||
expect(FileUtils.identical?(test_file_path, unzip_path)).to eq(true) | ||
ensure | ||
File.delete(unzip_path) | ||
File.delete(download_zip_path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.