Sha256: 8f72947d9db9909579996ea7a09eaae6feead67024505398cd307d6b51e3bfab
Contents?: true
Size: 722 Bytes
Versions: 3
Compression:
Stored size: 722 Bytes
Contents
require 'uri' require 'cgi' require 'httparty' class Videos::URI PROVIDERS_BY_HOST = { 'www.youtube.com' => 'youtube', 'youtu.be' => 'youtube', 'vimeo.com' => 'vimeo' } def initialize(uri) @uri = uri end def obj URI.parse(@uri) end def provider PROVIDERS_BY_HOST.has_key?(obj.host) ? PROVIDERS_BY_HOST[obj.host] : 'video' end def query CGI::parse(obj.query).to_h if obj.query end def content_type @content_type ||= get_content_type end def to_s obj.to_s end private def get_content_type begin resp = HTTParty.head(@uri, follow_redirects: true) resp.headers['content-type'].split(';')[0] rescue end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rb42-videos-1.0.3 | lib/videos/uri.rb |
rb42-videos-1.0.2 | lib/videos/uri.rb |
rb42-videos-1.0.1 | lib/videos/uri.rb |