Sha256: 938a5d2843c08fe08c9a96e7ba13a65f01fd288c0677748e2154d758f572a62d
Contents?: true
Size: 1.1 KB
Versions: 3
Compression:
Stored size: 1.1 KB
Contents
class RemoteBoard ItemTypeError = Class.new(NameError) attr_reader :id, :items, :url, :state CHUNK_SIZE = 6 * 1024 * 1024 def initialize(id:, state:, url:, name:, description: '', items: []) @id = id @state = state @url = url @name = name @description = description @items = to_instances(items: items) end def prepare_file_upload(client:, file:, part_number:) url = file.request_board_upload_url(client: client, board_id: @id, part_number: part_number) [url, CHUNK_SIZE] end def prepare_file_completion(client:, file:) file.complete_board_file(client: client, board_id: @id) end def files @items.select { |item| item.class == RemoteFile } end def links @items.select { |item| item.class == RemoteLink } end private def to_instances(items:) items.map do |item| begin remote_class = "Remote#{item[:type].capitalize}" Module.const_get(remote_class) .new(item) rescue NameError raise ItemTypeError, "Cannot instantiate item with type '#{item[:type]}' and id '#{item[:id]}'" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
wetransfer-0.9.0.beta2 | lib/we_transfer_client/remote_board.rb |
wetransfer-0.9.0.beta1 | lib/we_transfer_client/remote_board.rb |
wetransfer-0.9.0.beta | lib/we_transfer_client/remote_board.rb |