Sha256: d14d03c4ae8f7d903a7d01b8c17449ae93d36f5df2a38121b18427eb72734a97

Contents?: true

Size: 651 Bytes

Versions: 11

Compression:

Stored size: 651 Bytes

Contents

require 'uri'

module ConvertApi
  class UploadIO
    def initialize(io, filename = nil)
      @io = io
      @filename = filename || io_filename || raise(FileNameError, 'IO filename must be provided')
    end

    def to_s
      file_id
    end

    def file_id
      result['FileId']
    end

    def file_name
      result['FileName']
    end

    def file_ext
      result['FileExt']
    end

    private

    def result
      @result ||= upload_file
    end

    def upload_file
      ConvertApi.client.upload(@io, @filename)
    end

    def io_filename
      return unless @io.respond_to?(:path)
      File.basename(@io.path)
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
convert_api-3.0.0 lib/convert_api/upload_io.rb
convert_api-2.0.0 lib/convert_api/upload_io.rb
convert_api-1.4.0 lib/convert_api/upload_io.rb
convert_api-1.3.2 lib/convert_api/upload_io.rb
convert_api-1.3.1 lib/convert_api/upload_io.rb
convert_api-1.3.0 lib/convert_api/upload_io.rb
convert_api-1.2.1 lib/convert_api/upload_io.rb
convert_api-1.2.0 lib/convert_api/upload_io.rb
convert_api187-1.1.2 lib/convert_api/upload_io.rb
convert_api187-1.1.0 lib/convert_api/upload_io.rb
convert_api-1.1.0 lib/convert_api/upload_io.rb