class Videos::URI

Constants

PROVIDERS_BY_HOST

Public Class Methods

new(uri) click to toggle source
# File lib/videos/uri.rb, line 13
def initialize(uri)
  @uri = uri
end

Public Instance Methods

content_type() click to toggle source
# File lib/videos/uri.rb, line 29
def content_type
  @content_type ||= get_content_type
end
obj() click to toggle source
# File lib/videos/uri.rb, line 17
def obj
  URI.parse(@uri)
end
provider() click to toggle source
# File lib/videos/uri.rb, line 21
def provider
  PROVIDERS_BY_HOST.has_key?(obj.host) ? PROVIDERS_BY_HOST[obj.host] : 'video'
end
query() click to toggle source
# File lib/videos/uri.rb, line 25
def query
  CGI::parse(obj.query).to_h if obj.query
end
to_s() click to toggle source
# File lib/videos/uri.rb, line 33
def to_s
  obj.to_s
end

Private Instance Methods

get_content_type() click to toggle source
# File lib/videos/uri.rb, line 39
def get_content_type
  begin
    resp = HTTParty.head(@uri, follow_redirects: true)
    resp.headers['content-type'].split(';')[0]
  rescue
  end
end