Sunday, September 21, 2008

RSS

what is RSS
RSS is a format for syndicating news and the content of news-like sites, including major news sites like Wired, news-oriented community sites like Slashdot, and personal weblogs. But it's not just for news. Pretty much anything that can be broken down into discrete items can be syndicated via RSS: the "recent changes" page of a wiki, a changelog of CVS checkins, even the revision history of a book. Once information about each item is in RSS format, an RSS-aware program can check the feed for changes and react to the changes in an appropriate way.

precisely in points

-> Really Simple Syndication.

->It is a easy way to share defined content and news/titles/posts from www

->RSS is written in XML

uses of RSS

RSS started out with the intent of distributing news related headlines. The potential for RSS is significantly larger. Consider using RSS for the following:

New Homes - realtors can provide updated feeds of new home listings on the market

Job Openings - placement firms and newspapers can provide a classifieds feed of job vacancies

Auction Items - auction vendors can provide feeds containing items that have been recently added to ebay or other auction sites

Forum Headlines - support forums can provide a listing of new forum threads

Product Sales or Specials - one look at Amazon opens the mind to the endless product sale potential using RSS. Currently Amazon delivering a headline-view of the top 10 bestsellers in that category or set of search results.

Airlines - report flight delays

Schools - schools can relay homework assignments and quickly announce school cancellations.

Entertainment - listings of the latest tv programs or movies at local theatres

Press Distribution - feed for press with new releases

News & Announcements - headlines, notices and any list of announcements

Document listings - lists of added or changed pages, so that people don't need to constantly check for updates

Bookmarks and other external links - perfect for sharing lists of external links

Calendars - listings of past or upcoming events, deadlines or holidays

Law Enforcement - let the community know of location and status of sex offenders as they move into a community.

Search results - to let people track changing or new results to their searches

RSS in the Government - Site details how RSS is used by various government agencies

How to use RSS

Ruby excellently supports the RSS implementations. RSS (v0.9, v1.0, v2.0), maker and parser. Moving ahead here I will be showing few examples how do we parse/generate the RSS feeds in Rails application.

Note: An RSS document is often referred as “feed” or "channel"
Posted by shaik abdul hafeez at 3:01 AM 0 comments
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

1 comment:

Haritha said...

Excellent material for RSS. its very much useful.