Skip to content

Instantly share code, notes, and snippets.

@marano
Created June 12, 2010 17:19

Revisions

  1. marano revised this gist Jun 12, 2010. 3 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  2. marano revised this gist Jun 12, 2010. 3 changed files with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.rb → gistfile1.builder
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@ class FlickrEntry
    include SAXMachine
    include FeedEntryUtilities
    element :guid, :as => :id

    element :link, :as => :url

    element :title
    element :"media:title", :as => :title
    File renamed without changes.
    File renamed without changes.
  3. @bananastalktome bananastalktome created this gist Feb 25, 2010.
    59 changes: 59 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    module Feedzirra

    module Parser

    class FlickrEntry
    include SAXMachine
    include FeedEntryUtilities
    element :guid, :as => :id

    element :title
    element :"media:title", :as => :title

    element :link, :as => :url

    element :pubDate, :as => :published
    element :pubdate, :as => :published

    element :"media:description", :as => :summary

    element :"media:credit", :as => :author, :with => { :role => "photographer" }
    element :"media:thumbnail", :as => :thumbnail, :value => :url

    element :"media:content", :as => :content, :value => :url

    element :"media:category", :as => :categories, :with => { :scheme => "urn:flickr:tags" }

    def tags
    @categories.blank? ? [] : @categories.split(" ")
    end

    end
    end
    end

    module Feedzirra

    module Parser

    class Flickr
    include SAXMachine
    include FeedUtilities
    element :title

    element :pubDate, :as => :published
    element :pubdate, :as => :published
    element :lastBuildDate, :as => :updated

    elements :item, :as => :entries, :class => FlickrEntry


    attr_accessor :feed_url

    def self.able_to_parse?(xml) #:nodoc:
    xml =~ /xmlns:flickr=\"urn:flickr:\"/im
    end

    end
    end
    end
    69 changes: 69 additions & 0 deletions gistfile2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    module Feedzirra

    module Parser

    class VimeoEntry
    include SAXMachine
    include FeedEntryUtilities
    element :guid, :as => :id

    element :title
    element :"media:title", :as => :title

    element :link, :as => :url

    element :"dc:creator", :as => :author
    element :"media:credit", :as => :author, :with => { :role => "author" }

    element :description, :as => :summary

    element :pubDate, :as => :published
    element :pubdate, :as => :published


    element :"media:player", :as => :content, :value => :url
    element :enclosure, :as => :content, :value => :url, :with => { :type => "application/x-shockwave-flash" }

    element :"media:category", :as => :keyword_list
    element :"media:thumbnail", :as => :thumbnail, :value => :url

    def embed_code
    "<object width=\"400\" height=\"225\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"#{@content}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><embed src=\"#{@content}&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"400\" height=\"225\"></embed></object>"
    end

    def media_id
    if @url =~ /http:\/\/vimeo.com\/(\d*)/i
    $1
    elsif @content =~ /http:\/\/vimeo.com\/moogaloop.swf?clip_id=(\d*)/i
    $1
    else
    ''
    end
    end

    def tags
    @keyword_list.blank? ? [] : @keyword_list.split(",")
    end
    end
    end
    end

    module Feedzirra

    module Parser

    class Vimeo
    include SAXMachine
    include FeedUtilities
    element :title
    element :link, :as => :url
    element :"atom:link", :as => :feed_url, :value => :href, :with => { :rel => "self" }
    elements :item, :as => :entries, :class => VimeoEntry

    def self.able_to_parse?(xml) #:nodoc:
    xml =~ /xmlns:atom=\"http:\/\/www.w3.org\/2005\/Atom\" xmlns:dc=\"http:\/\/purl.org\/dc\/elements\/1.1\/\" xmlns:media=\"http:\/\/search.yahoo.com\/mrss\/\"/im
    end

    end
    end
    end
    78 changes: 78 additions & 0 deletions gistfile3.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,78 @@
    module Feedzirra

    module Parser

    class YoutubeEntry
    include SAXMachine
    include FeedEntryUtilities
    element :id

    element :title
    element :content, :as => :summary
    element :name, :as => :author

    element :link, :as => :url, :value => :href, :with => { :rel => "alternate" }

    element :published
    element :updated

    element :"media:player", :as => :url, :value => :url
    element :"media:content", :as => :content, :value => :url, :with => { :type => "application/x-shockwave-flash" }
    element :"media:keywords", :as => :keyword_list
    element :"yt:duration", :as => :duration, :value => :seconds

    elements :category, :as => :keywords, :value => :term, :with => { :scheme => "http://gdata.youtube.com/schemas/2007/keywords.cat" }

    elements :category, :as => :categories, :value => :term, :with => { :scheme => "http://gdata.youtube.com/schemas/2007/categories.cat" }

    elements :"media:thumbnail", :as => :thumbnails, :value => :url

    def embed_code
    "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"#{@content}\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"#{@content}\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>"
    end

    def thumbnail
    @thumbnails.reject { |t| t !~ /0.jpg/ }.to_s
    end

    def media_id
    if @id =~ /http:\/\/gdata.youtube.com\/feeds\/api\/videos\/(\S[^\/?]*)/i
    $1
    elsif @url =~ /http:\/\/www.youtube.com\/watch\?v\=(\S[^(&amp\;)]*)/i
    $1
    else
    ''
    end
    end

    def tags
    @keywords || @keyword_list.blank? ? [] : @keyword_list.split(",")
    end

    end
    end
    end

    module Feedzirra

    module Parser

    class Youtube
    include SAXMachine
    include FeedUtilities
    element :id
    element :updated
    element :title
    element :name, :as => :author
    element :link, :as => :feed_url, :value => :href, :with => { :rel => "http://schemas.google.com/g/2005#feed" }
    element :link, :as => :url, :value => :href, :with => { :rel => "alternate" }
    elements :entry, :as => :entries, :class => YoutubeEntry


    def self.able_to_parse?(xml) #:nodoc:
    xml =~ /xmlns:yt=\'http:\/\/gdata.youtube.com\/schemas\/2007\'/im
    end

    end
    end
    end