Sha256: 3f73f58d7985ab4f5f8d0596625edcf3132728a602a80f94c773fdddee8d8273
Contents?: true
Size: 1.53 KB
Versions: 5
Compression:
Stored size: 1.53 KB
Contents
module Asana module Resources # Internal: Mixin to add the ability to upload an attachment to a specific # Asana resource (a Task, really). module AttachmentUploading # Uploads a new attachment to the resource. # # filename - [String] the absolute path of the file to upload OR the desired filename when using +io+ # mime - [String] the MIME type of the file # io - [IO] an object which returns the file's content on +#read+, e.g. a +::StringIO+ # options - [Hash] the request I/O options # data - [Hash] extra attributes to post # # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength def attach(filename: required('filename'), mime: required('mime'), io: nil, options: {}, **data) upload = if io.nil? path = File.expand_path(filename) raise ArgumentError, "file #{filename} doesn't exist" unless File.exist?(path) Faraday::FilePart.new(path, mime) else Faraday::FilePart.new(io, mime, filename) end response = client.post("/#{self.class.plural_name}/#{gid}/attachments", body: data, upload: upload, options: options) Attachment.new(parse(response).first, client: client) end # rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/AbcSize end end end
Version data entries
5 entries across 5 versions & 1 rubygems