Sha256: dd85545be236aed77488a2f3e6f9b881cd052698b96e73fc040c0e55bb33e140
Contents?: true
Size: 758 Bytes
Versions: 4
Compression:
Stored size: 758 Bytes
Contents
require 'uri' require 'cgi' require 'httparty' class Videos::URI PROVIDERS_BY_HOST = { 'www.youtube.com' => 'youtube', '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
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rb42-videos-1.0.7 | lib/videos/uri.rb |
rb42-videos-1.0.6 | lib/videos/uri.rb |
rb42-videos-1.0.5 | lib/videos/uri.rb |
rb42-videos-1.0.4 | lib/videos/uri.rb |