Sha256: 211bdcb0b84937e22f64a5669173f97fe4224a5688f217f166263c151d441380

Contents?: true

Size: 894 Bytes

Versions: 2

Compression:

Stored size: 894 Bytes

Contents

require 'httparty'

class FilmSnob
  class VideoSite

    attr_reader :url, :options

    def initialize(url, options)
      @url = url
      @options = options
    end

    def id
      @id ||= matching_pattern.match(url)[1]
    end

    def site
      @site ||= self.class.to_s.split('::').last.downcase.to_sym
    end

    def self.valid_url_patterns
      []
    end

    def self.oembed_endpoint
      ''
    end

    def title
      oembed['title']
    end

    def html
      oembed['html'] || (raise NotEmbeddableError.new("#{clean_url} is not embeddable"))
    end

    private

      def matching_pattern
        self.class.valid_url_patterns.find do |pattern|
          pattern.match(url)
        end
      end

      def oembed
        @oembed ||= HTTParty.get(
          self.class.oembed_endpoint,
          query: { url: clean_url }.merge(options)
        )
      end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
film_snob-0.3.8 lib/film_snob/video_site.rb
film_snob-0.3.7 lib/film_snob/video_site.rb