# encoding: UTF-8 require 'open-uri' require 'rack' module Spontaneous::Field class WebVideo class Vimeo < Provider def self.match(field, url) case url when /vimeo\.com\/(\d+)/ video_id = $1 new(field, :video_id => video_id, :provider => id).metadata else nil end end def metadata @attributes.update(download_metadata) end def download_metadata url = "http://vimeo.com/api/v2/video/%s.json" % video_id response = \ begin open(url).read rescue => e logger.error("Unable to retrieve metadata for video ##{video_id} from Vimeo: '#{e}'") fallback_response end metadata = Spontaneous.parse_json(response) rescue [{}] metadata = (metadata || [{}]).first || {} end def to_html(options = {}) params = player_attributes(options) attributes = hash_to_attributes(params[:attr]) "" end def as_json(options = {}) player_attributes(options) end def player_attributes(options = {}) o = player_options(options) attributes = { :type => "text/html", :frameborder => "0", :width => o.delete(:width), :height => o.delete(:height) } attributes.update(:webkitAllowFullScreen => "yes", :allowFullScreen => "yes") if o[:fullscreen] make_query_options!(o) attributes[:src] = src_with_options(o) {:tagname => "iframe", :tag => "