Sha256: a8c15d9482b431855a382f2b2b8d7a7cdc77ddb76b0d1beffd37638f9e58e8f4

Contents?: true

Size: 963 Bytes

Versions: 5

Compression:

Stored size: 963 Bytes

Contents

require "oembedr/providers"
require "uri"

module Oembedr
  class ParsedUrl
    attr_accessor :raw_url, :url

    include Oembedr::Providers

    # TODO: support xml at some point :)
    def initialize the_url
      self.raw_url = the_url
      endpoint = service_endpoint(raw_url)
      if endpoint
        self.url = URI.parse(endpoint.gsub(/\{format\}/, "json"))
      else
        self.url = false
      end
    end

    # Returns the scheme and host portion of the uri, intelligently concatenated
    #
    # Examples
    #
    #   self.new("https://twitter.com/#!/hypomodern").host # => "https://twitter.com"
    #   self.new("http://youtu.be/v/234543").host # => "http://youtube.com"
    #
    # @return url [String]
    def host
      return false unless url
      url.scheme + "://" + url.host
    end

    # Returns the path portion of the uri
    #
    # @return path [String]
    def path
      return false unless url
      url.path
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oembedr-1.1.1 lib/oembedr/parsed_url.rb
oembedr-1.1.0 lib/oembedr/parsed_url.rb
oembedr-1.0.0 lib/oembedr/parsed_url.rb
oembedr-0.0.3 lib/oembedr/parsed_url.rb
oembedr-0.0.2 lib/oembedr/parsed_url.rb