Sha256: 851143597ecf0b56f123e7bb35551a8a838a012545b0569b47aeacc2f8da9474

Contents?: true

Size: 777 Bytes

Versions: 12

Compression:

Stored size: 777 Bytes

Contents

require_relative "uploaders/s3"

module Vzaar
  class Uploader < Struct.new(:conn, :signature, :opts)
    attr_reader :guid

    def upload
      begin
        if link_upload?
          link
        else
          success = s3.upload
          yield(self) if block_given? && success
        end
      rescue Exception => e
        raise(Vzaar::Error, "Upload error: " + e.message)
      end
    end

    def processing_params
      opts.merge guid: guid
    end

    private

    def link_upload?
      opts[:url]
    end

    def guid
      signature.guid
    end

    def s3
      Uploaders::S3.new(opts[:path], signature)
    end

    def link
      _opts = opts.merge({ guid: guid, key: signature.key })
      Request::LinkUpload.new(conn, _opts).execute
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vzaar-1.5.3 lib/vzaar/uploader.rb
vzaar-1.5.2 lib/vzaar/uploader.rb
vzaar-1.5.1 lib/vzaar/uploader.rb
vzaar-1.5.0 lib/vzaar/uploader.rb
vzaar-1.4.4 lib/vzaar/uploader.rb
vzaar-1.4.1 lib/vzaar/uploader.rb
vzaar-1.3.1 lib/vzaar/uploader.rb
vzaar-1.3.0 lib/vzaar/uploader.rb
vzaar-1.2.4 lib/vzaar/uploader.rb
vzaar-1.2.3 lib/vzaar/uploader.rb
vzaar-1.2.2 lib/vzaar/uploader.rb
vzaar-1.0.0 lib/vzaar/uploader.rb