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