class Moxify::URLTempfile

Attributes

content_type[R]

Public Class Methods

new(url) click to toggle source
Calls superclass method
# File lib/moxify/url_tempfile.rb, line 9
def initialize(url)
  @url = URI.parse(url)

  # see if we can get a filename
  raise "Unable to determine filename for URL uploaded file." unless original_filename

  begin
    # HACK to get around inability to set VERIFY_NONE with open-uri
    old_verify_peer_value = OpenSSL::SSL::VERIFY_PEER
    openssl_verify_peer = OpenSSL::SSL::VERIFY_NONE

    super('urlupload', Dir.tmpdir, :encoding => 'ascii-8bit')
    Kernel.open(url) do |file|
      @content_type = file.content_type
      raise "Unable to determine MIME type for URL uploaded file." unless content_type

      self.write file.read
      self.flush
    end
  ensure
    openssl_verify_peer = old_verify_peer_value
  end
end

Public Instance Methods

original_filename() click to toggle source
# File lib/moxify/url_tempfile.rb, line 33
def original_filename
  # Take the URI path and strip off everything after last slash, assume this
  # to be filename (URI path already removes any query string)
  match = @url.path.match(/^.*\/(.+)$/)
  return (match ? match[1] : nil)
end

Protected Instance Methods

openssl_verify_peer=(value) click to toggle source
# File lib/moxify/url_tempfile.rb, line 42
def openssl_verify_peer=(value)
  silence_warnings do
    OpenSSL::SSL.const_set("VERIFY_PEER", value)
  end
end