Class/Module Index [+]

Quicksearch

FeedTools

feed_tools.rb

FeedTools was designed to be a simple XML feed parser, generator, and translator with a built-in
caching system.

Example

slashdot_feed = FeedTools::Feed.open('http://www.slashdot.org/index.rss')
slashdot_feed.title
=> "Slashdot"
slashdot_feed.description
=> "News for nerds, stuff that matters"
slashdot_feed.link       
=> "http://slashdot.org/"
slashdot_feed.items.first.find_node("slash:hitparade/text()").value
=> "43,37,28,23,11,3,1"

database_feed_cache.rb

The <tt>DatabaseFeedCache</tt> is the default caching mechanism for
FeedTools.  This mechanism can be replaced easily by creating another
class with the required set of methods and setting
<tt>FeedTools#feed_cache</tt> to the new class.

TODO: Not used yet, don't load since it'll only be a performance hit

require 'net/https'
require 'net/ftp'

This module provides helper methods for simplifying normal interactions with the FeedTools library.

Constants

EnclosureCredit
EnclosureHash

TODO: Make these actual classes instead of structs

EnclosurePlayer
EnclosureThumbnail

Public Class Methods

build_merged_feed(url_array, options = {}) click to toggle source

Creates a merged "planet" feed from a set of urls.

Options are:

  • :multi_threaded - If set to true, feeds will be retrieved concurrently. Not recommended when used in conjunction with the DatabaseFeedCache as it will open multiple connections to the database.

# File lib/feed_tools.rb, line 329
def FeedTools.build_merged_feed(url_array, options = {})
  FeedTools::GenericHelper.validate_options([ :multi_threaded ],
                   options.keys)
  options = { :multi_threaded => false }.merge(options)
  warn("FeedTools.build_merged_feed is deprecated.")
  return nil if url_array.nil?
  merged_feed = FeedTools::Feed.new
  retrieved_feeds = []
  if options[:multi_threaded]
    feed_threads = []
    url_array.each do |feed_url|
      feed_threads << Thread.new do
        feed = Feed.open(feed_url)
        retrieved_feeds << feed
      end
    end
    feed_threads.each do |thread|
      thread.join
    end
  else
    url_array.each do |feed_url|
      feed = Feed.open(feed_url)
      retrieved_feeds << feed
    end
  end
  retrieved_feeds.each do |feed|
    merged_feed.entries = merged_feed.entries.concat(
      feed.entries.collect do |entry|
        new_entry = entry.dup
        new_entry.title = "#{feed.title}: #{entry.title}"
        new_entry
      end
    )
  end
  return merged_feed
end
configurations() click to toggle source

Returns the configuration hash for FeedTools

# File lib/feed_tools.rb, line 245
def FeedTools.configurations
  if @configurations.blank?
    FeedTools.load_configurations()
  end
  return @configurations
end
configurations=(new_configurations) click to toggle source

Sets the configuration hash for FeedTools

# File lib/feed_tools.rb, line 253
def FeedTools.configurations=(new_configurations)
  @configurations = new_configurations
end
feed_cache() click to toggle source

Returns the current caching mechanism.

Objects of this class must accept the following messages:

id
id=
url
url=
title
title=
link
link=
feed_data
feed_data=
feed_data_type
feed_data_type=
etag
etag=
last_modified
last_modified=
save

Additionally, the class itself must accept the following messages:

find_by_id
find_by_url
initialize_cache
connected?
# File lib/feed_tools.rb, line 287
def FeedTools.feed_cache
  return nil if FeedTools.configurations[:feed_cache].blank?
  class_name = FeedTools.configurations[:feed_cache].to_s
  if @feed_cache.nil? || @feed_cache.to_s != class_name
    begin
      cache_class = eval(class_name)
      if cache_class.kind_of?(Class)
        @feed_cache = cache_class
        if @feed_cache.respond_to? :initialize_cache
          @feed_cache.initialize_cache
        end
        return cache_class
      else
        return nil
      end
    rescue
      return nil
    end
  else
    return @feed_cache
  end
end
feed_cache_connected?() click to toggle source

Returns true if FeedTools.feed_cache is not nil and a connection with the cache has been successfully established. Also returns false if an error is raised while trying to determine the status of the cache.

# File lib/feed_tools.rb, line 313
def FeedTools.feed_cache_connected?
  begin
    return false if FeedTools.feed_cache.nil?
    return FeedTools.feed_cache.connected?
  rescue
    return false
  end
end
load_configurations() click to toggle source
# File lib/feed_tools.rb, line 195
def FeedTools.load_configurations
  if @configurations.blank?
    # TODO: Load this from a config file.
    config_hash = {}
    @configurations = {
      :feed_cache => nil,
      :disable_update_from_remote => false,
      :proxy_address => nil,
      :proxy_port => nil,
      :proxy_user => nil,
      :proxy_password => nil,
      :auth_user => nil,
      :auth_password => nil,
      :auth_scheme => nil,
      :http_timeout => nil,
      :user_agent =>
        "FeedTools/#{FeedTools::FEED_TOOLS_VERSION::STRING} " + 
        "+http://www.sporkmonger.com/projects/feedtools/",
      :generator_name =>
        "FeedTools/#{FeedTools::FEED_TOOLS_VERSION::STRING}",
      :generator_href =>
        "http://www.sporkmonger.com/projects/feedtools/",
      :tidy_enabled => false,
      :tidy_options => {},
      :lazy_parsing_enabled => true,
      :serialization_enabled => false,
      :idn_enabled => true,
      :sanitization_enabled => true,
      :sanitize_with_nofollow => true,
      :always_strip_wrapper_elements => true,
      :timestamp_estimation_enabled => true,
      :url_normalization_enabled => true,
      :entry_sorting_property => "time",
      :strip_comment_count => false,
      :tab_spaces => 2,
      :max_ttl => 3.days.to_s,
      :default_ttl => 1.hour.to_s,
      :output_encoding => "utf-8"
    }.merge(config_hash)
  end
  return @configurations
end
reset_configurations() click to toggle source

Resets configuration to a clean load

# File lib/feed_tools.rb, line 239
def FeedTools.reset_configurations
  @configurations = nil
  FeedTools.load_configurations
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.