[ANN] rss-client-2.0.9

S

Stoyan Zhekov

ABOUT
Fetching and parsing RSS feeds with easy. Ruby library (mixin) for
adding RSS feeds download
and parsing functionality. The RSS fetch command line utility, using
the library is also included.

DEPENDS
feed-normalizer for the RSS feeds parsing.

URIs
Homepage: http://rubyforge.org/projects/rss-client
Download: http://rubyforge.org/frs/?group_id=5309
SVN: svn checkout http://rss-client.rubyforge.org/svn/
Mercurial: hg clone http://hg.assembla.com/rss-client rss-client

I'm using mostly mercurial, so you can follow the development on:

http://trac-hg.assembla.com/rss-client/

Only releases/gems will be posted to rubyforge. Some main milestones/
bug fixes will be commited
to the rubyforge SVN.

INSTALLATION

Normal Installation
You can install rss-client with the following command:

$ ruby install.rb

from its distribution directory.

GEM Installation
Download and install rss-client with the following:

$ gem install --remote rss-client


COMMAND LINE UTILITY USAGE
$ rssclient [options] feed_url

Options
-h, --help Displays help message
-V, --version Display the version, then exit
-q, --quiet Output as little as possible, overrides verbose
-v, --verbose Verbose output
-p, --proxy Use proxy (format http://user:pass@address:port
)
-r, --raw Use raw RSS fetch (no error code processing)
-g, --giveup Giveup on fetching after timeout (seconds)
-f, --force Force fresh feed fetch (no 304 code processing)
-s, --since Only changes from {since} seconds ago

Examples
$ rssclient -q http://example.com/atom.xml
$ rssclient -r -f http://test:[email protected]/atom.xml
$ rssclient --verbose http://example.com/atom.xml
$ rssclient --giveup 20 -f http://example.com/atom.xml
$ rssclient --since 600 http://example.com/atom.xml
$ rssclient -f -p http://aa:bb@localhost:8088 http://example.com/atom.xml


LIBRARY USAGE IN YOUR OWN RUBY CLASSES
The main method the library exports is:

get_feed(url, opts)

where,

url - string with the feed url
opts - OpenStruct with options (see the example below)

The method returns the output from the FeedNormalizer.parse() on
sucess and nil on failure/not modified.
The raw feed is saved in @rssc_raw for future processing
The method handles:
- successful download (200) - @rssc_raw have the original feed and
the output from the method is the
parsed one.
- not modidied (304) - returns nil and 304 in the @rssc_raw.status
- redirects (301, 302) - automaticaly redirect to the new url and
trying to fetch the feed again

Example
require 'rss-client

class Feed
include RSSClient

def fetch
opts = OpenStruct.new
opts.forceUpdate = false # set true to force the download (no
304 code handling)
opts.giveup = 10 # on error giveup after 10 sec timeout

rss = get_feed('http://rubyforge.org/export/
rss_sfnews.php',opts)
return nil unless @rssc_raw # download error
return 304 if @rssc_raw.status == 304 # feed not modified
return nil unless rss # error in parsing

# some title, items etc. processing
self.title = rss.channel.title.to_s
self.description = rss.channel.description.to_s
rss.entries.each do |i|
...
end
end

end

get_feed() using get_url(url, opts) method, which in turn is powered
by HTTPAccess2::Client.
get_url() can be used for low-level connection debugging (the -r
option in the command line
utility). get_url() example output for http://rubyforge.org/export/rss_sfnews.php:

$ rssclient -r http://rubyforge.org/export/rss_sfnews.php
Status code: 200
Headers:
- Status: 200 OK
- Date: Mon, 21 Jan 2008 09:37:00 GMT
- Server: Apache
- X-Powered-By: PHP/4.4.8
- Vary: Accept-Encoding
- Connection: close
- Transfer-Encoding: chunked
- Content-Type: text/plain
- Content-Length: 0
- Content-Type: text/html; charset=us-ascii


CREDITS
Hiroshi Nakamura - For the http-access2 library.
Todd Werth - For the ruby command-line application skeleton

LICENSE
rss-client is available under an MIT-style license.


And one question/problem: when installed with 'ruby install.rb' the '-
h' option properly displaying
the help/usage. When installed via gems, '-h' returns:

rssclient version 2.0.9
This file was generated by RubyGems.

The application 'rss-client' is installed as part of a gem, and this
file is here to facilitate running it.
 
N

Nick Atkins

I tried to use the latest rss-client in a Rails app and I get the
following error:

undefined method `new' for class `Class'
RAILS_ROOT: /home/998640e2/web/apple/config/..

Application Trace | Framework Trace | Full Trace
/opt/local/lib/ruby/gems/1.8/gems/rss-client-2.0.9/lib/rss-client/http-access2/http.rb:393
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in
`new_constants_in'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/rss-client-2.0.9/lib/rss-client/http-access2.rb:21
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in
`new_constants_in'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/rss-client-2.0.9/lib/rss-client.rb:3
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
/opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in
`require'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:in
`new_constants_in'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:in
`require'
/home/998640e2/web/apple/app/controllers/rss_controller.rb:1
/opt/local/bin/mongrel_rails:16:in `load'
/opt/local/bin/mongrel_rails:16
This error occurred while loading the following files:
rss-client
rss-client/http-access2
rss-client/http-access2/http

I installed the gem as described. Ruby version 1.8.6

Any ideas?

Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top