class TransferBuilder
Attributes
items[R]
Public Class Methods
new()
click to toggle source
# File lib/we_transfer_client/transfer_builder.rb, line 5 def initialize @items = [] end
Public Instance Methods
add_file(name:, io:)
click to toggle source
# File lib/we_transfer_client/transfer_builder.rb, line 9 def add_file(name:, io:) ensure_io_compliant!(io) @items << FutureFileItem.new(name: name, io: io) true end
add_file_at(path:)
click to toggle source
# File lib/we_transfer_client/transfer_builder.rb, line 15 def add_file_at(path:) add_file(name: File.basename(path), io: File.open(path, 'rb')) end
add_web_url(url:, title: nil)
click to toggle source
# File lib/we_transfer_client/transfer_builder.rb, line 19 def add_web_url(url:, title: nil) title ||= url @items << FutureWebItem.new(url: url, title: title) true end
ensure_io_compliant!(io)
click to toggle source
# File lib/we_transfer_client/transfer_builder.rb, line 25 def ensure_io_compliant!(io) io.seek(0) io.read(1) # Will cause things like Errno::EACCESS to happen early, before the upload begins io.seek(0) # Also rewinds the IO for later uploading action size = io.size # Will cause a NoMethodError raise TransferIOError, 'The IO object given to add_file has a size of 0' if size <= 0 rescue NoMethodError raise TransferIOError, "The IO object given to add_file must respond to seek(), read() and size(), but #{io.inspect} did not" end