Sha256: af6b2b9a2b19de1f3c8060b16e48af1fe020597b689b3f00e5441facf0d7e2f1

Contents?: true

Size: 416 Bytes

Versions: 8

Compression:

Stored size: 416 Bytes

Contents

require "uri"
require_relative "error"

module RemoveBg
  class UrlValidator
    PERMITTED_SCHEMES = ["http", "https"].freeze

    def self.validate(url)
      parsed = URI.parse(url)

      unless parsed.absolute? && PERMITTED_SCHEMES.include?(parsed.scheme)
        raise RemoveBg::InvalidUrlError.new(url)
      end
    rescue URI::InvalidURIError
      raise RemoveBg::InvalidUrlError.new(url)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
remove_bg-1.5.0 lib/remove_bg/url_validator.rb
remove_bg-1.4.1 lib/remove_bg/url_validator.rb
remove_bg-1.4.0 lib/remove_bg/url_validator.rb
remove_bg-1.3.0 lib/remove_bg/url_validator.rb
remove_bg-1.2.1 lib/remove_bg/url_validator.rb
remove_bg-1.2.0 lib/remove_bg/url_validator.rb
remove_bg-1.1.0 lib/remove_bg/url_validator.rb
remove_bg-1.0.0 lib/remove_bg/url_validator.rb