Sha256: 5dc467fefeb87f870d5e59d0899bf15dd102f92ec357973b10b1042c4a980066

Contents?: true

Size: 660 Bytes

Versions: 1

Compression:

Stored size: 660 Bytes

Contents

# frozen_string_literal: true

module SimpleImagesDownloader
  class Downloader
    include Validatable

    def initialize(uri, client = Client.new, validators = [MimeTypeValidator.new])
      @uri        = uri
      @client     = client
      @validators = validators
    end

    def download
      puts "Downloading #{@uri}"

      io = @client.open(@uri)

      raise Errors::EmptyResponse, @uri if io.nil?

      validate!({ path: @uri.to_s, io: io })

      tempfile = StringioToTempfile.convert(io)

      Dispenser.new(tempfile, @uri.path).place

      puts 'Downloading is finished'
    ensure
      io&.close
      tempfile&.close
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple-images-downloader-1.1.0 lib/simple_images_downloader/downloader.rb