FeedTools was designed to be a simple XML feed parser, generator, and translator with a built-in caching system.
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"
EnclosureHash | = | Struct.new( "EnclosureHash", :hash, :type ) |
TODO: Make these actual classes instead of structs
============================================ |
|
EnclosurePlayer | = | Struct.new( "EnclosurePlayer", :url, :height, :width ) | ||
EnclosureCredit | = | Struct.new( "EnclosureCredit", :name, :role ) | ||
EnclosureThumbnail | = | Struct.new( "EnclosureThumbnail", :url, :height, :width ) |
Creates a merged "planet" feed from a set of urls.
Options are:
# File lib/feed_tools.rb, line 337 337: def FeedTools.build_merged_feed(url_array, options = {}) 338: FeedTools::GenericHelper.validate_options([ :multi_threaded ], 339: options.keys) 340: options = { :multi_threaded => false }.merge(options) 341: warn("FeedTools.build_merged_feed is deprecated.") 342: return nil if url_array.nil? 343: merged_feed = FeedTools::Feed.new 344: retrieved_feeds = [] 345: if options[:multi_threaded] 346: feed_threads = [] 347: url_array.each do |feed_url| 348: feed_threads << Thread.new do 349: feed = Feed.open(feed_url) 350: retrieved_feeds << feed 351: end 352: end 353: feed_threads.each do |thread| 354: thread.join 355: end 356: else 357: url_array.each do |feed_url| 358: feed = Feed.open(feed_url) 359: retrieved_feeds << feed 360: end 361: end 362: retrieved_feeds.each do |feed| 363: merged_feed.entries = merged_feed.entries.concat( 364: feed.entries.collect do |entry| 365: new_entry = entry.dup 366: new_entry.title = "#{feed.title}: #{entry.title}" 367: new_entry 368: end 369: ) 370: end 371: return merged_feed 372: end
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 295 295: def FeedTools.feed_cache 296: return nil if FeedTools.configurations[:feed_cache].blank? 297: class_name = FeedTools.configurations[:feed_cache].to_s 298: if @feed_cache.nil? || @feed_cache.to_s != class_name 299: begin 300: cache_class = eval(class_name) 301: if cache_class.kind_of?(Class) 302: @feed_cache = cache_class 303: if @feed_cache.respond_to? :initialize_cache 304: @feed_cache.initialize_cache 305: end 306: return cache_class 307: else 308: return nil 309: end 310: rescue 311: return nil 312: end 313: else 314: return @feed_cache 315: end 316: end
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 321 321: def FeedTools.feed_cache_connected? 322: begin 323: return false if FeedTools.feed_cache.nil? 324: return FeedTools.feed_cache.connected? 325: rescue 326: return false 327: end 328: end
# File lib/feed_tools.rb, line 203 203: def FeedTools.load_configurations 204: if @configurations.blank? 205: # TODO: Load this from a config file. 206: config_hash = {} 207: @configurations = { 208: :feed_cache => nil, 209: :disable_update_from_remote => false, 210: :proxy_address => nil, 211: :proxy_port => nil, 212: :proxy_user => nil, 213: :proxy_password => nil, 214: :auth_user => nil, 215: :auth_password => nil, 216: :auth_scheme => nil, 217: :http_timeout => nil, 218: :user_agent => 219: "FeedTools/#{FeedTools::FEED_TOOLS_VERSION::STRING} " + 220: "+http://www.sporkmonger.com/projects/feedtools/", 221: :generator_name => 222: "FeedTools/#{FeedTools::FEED_TOOLS_VERSION::STRING}", 223: :generator_href => 224: "http://www.sporkmonger.com/projects/feedtools/", 225: :tidy_enabled => false, 226: :tidy_options => {}, 227: :lazy_parsing_enabled => true, 228: :serialization_enabled => false, 229: :idn_enabled => true, 230: :sanitization_enabled => true, 231: :sanitize_with_nofollow => true, 232: :always_strip_wrapper_elements => true, 233: :timestamp_estimation_enabled => true, 234: :url_normalization_enabled => true, 235: :entry_sorting_property => "time", 236: :strip_comment_count => false, 237: :tab_spaces => 2, 238: :max_ttl => 3.days.to_s, 239: :default_ttl => 1.hour.to_s, 240: :output_encoding => "utf-8" 241: }.merge(config_hash) 242: end 243: return @configurations 244: end