Wednesday, September 17, 2008

Maker:

Maker creates/generates the feed/RSS document of a site/blog. Since there are multiple versions of the RSS available based on the version we need to include/require those libraries while making the feed.


# A controller that would handle all the feed related actions, includes/refers the required libraries.
# An action/method that would use the rss/maker library to read the feed.
# Extract the necessary elements/content.
# Pass on the elements/content to the views (RHTML/RXML).

# making feed for Top urls feeds



def generate_feed
version = "2.0" # ["0.9", "1.0", "2.0"]
destination = "destination file" # local file to write
content = RSS::Maker.make(version) do |m|
m.channel.title = "tilte of RSS feeds"
m.channel.link = "http://rubyforge.org"
m.channel.description = "These are my Top url clips"
m.channel.webMaster ="webmaster@rubyforge.org"
m.channel.date = Time.now

i = m.items.new_item
i.title = "give title here"
i.link = "give link here"
i.description = "write description here"
i.date = Time.now
end
# content = @response
File.open(destination,"w") do |f|
f.write(content)
end
end

Parser:

Parser identifies the feed Url provided and reads the document and we can publish the feed with our own display options. So all that we need is a simple feed url. Let us say we need to publish the feed content of particular site on our blog/site.

Since there are multiple versions of the RSS available based on the version we need to include/require those libraries while parsing the feed.

# A controller that would handle all the feed related actions, includes/refers the required libraries.
# An action/method that would use the rss/parser library to read the feed.
# Extract the necessary elements/content.
# Pass on the elements/content to the views.


class RssFeedController <>

#This action is used to get the rss feed of the blog mentioned

def parse_feed

source = "here source file" # url or local file
content = "" # raw content of rss feed will be loaded here
open(source) do |s| content = s.read end
rss = RSS::Parser.parse(content, false)
@rss=rss
render :layout => false
end
end

No comments: