Sha256: 0697838d4749a975ad45f85dec87f29bd8e1fbdcba33f11e3eb5226e91cbef30

Contents?: true

Size: 893 Bytes

Versions: 6

Compression:

Stored size: 893 Bytes

Contents

module Yawast
  module Shared
    class Uri
      def self.extract_uri(url)
        #this might be buggy - actually, I know it is...
        url = 'http://' + url unless url.include?('http://') || url.include?('https://')

        #make sure the path is at least a slash
        uri = URI.parse(url)
        uri.path = '/' if uri.path == ''

        #this is buggy, but we don't handle files anyhow...
        #if the path doesn't end in a slash, add one.
        if uri.path[-1, 1] != '/'
          uri.path.concat '/'
        end

        #see if we can resolve the host
        # we don't really need it, it just serves as validation
        begin
          dns = Resolv::DNS.new
          dns.getaddress(uri.host)
        rescue => e
          raise ArgumentError.new("Invalid URL (#{e.message})") unless uri.host == 'localhost'
        end

        return uri
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yawast-0.4.0.beta3 lib/shared/uri.rb
yawast-0.4.0.beta2 lib/shared/uri.rb
yawast-0.4.0.beta1 lib/shared/uri.rb
yawast-0.3.0 lib/shared/uri.rb
yawast-0.3.0.beta2 lib/shared/uri.rb
yawast-0.3.0.beta1 lib/shared/uri.rb