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 329
329: def FeedTools.build_merged_feed(url_array, options = {})
330: FeedTools::GenericHelper.validate_options([ :multi_threaded ],
331: options.keys)
332: options = { :multi_threaded => false }.merge(options)
333: warn("FeedTools.build_merged_feed is deprecated.")
334: return nil if url_array.nil?
335: merged_feed = FeedTools::Feed.new
336: retrieved_feeds = []
337: if options[:multi_threaded]
338: feed_threads = []
339: url_array.each do |feed_url|
340: feed_threads << Thread.new do
341: feed = Feed.open(feed_url)
342: retrieved_feeds << feed
343: end
344: end
345: feed_threads.each do |thread|
346: thread.join
347: end
348: else
349: url_array.each do |feed_url|
350: feed = Feed.open(feed_url)
351: retrieved_feeds << feed
352: end
353: end
354: retrieved_feeds.each do |feed|
355: merged_feed.entries = merged_feed.entries.concat(
356: feed.entries.collect do |entry|
357: new_entry = entry.dup
358: new_entry.title = "#{feed.title}: #{entry.title}"
359: new_entry
360: end
361: )
362: end
363: return merged_feed
364: 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 287
287: def FeedTools.feed_cache
288: return nil if FeedTools.configurations[:feed_cache].blank?
289: class_name = FeedTools.configurations[:feed_cache].to_s
290: if @feed_cache.nil? || @feed_cache.to_s != class_name
291: begin
292: cache_class = eval(class_name)
293: if cache_class.kind_of?(Class)
294: @feed_cache = cache_class
295: if @feed_cache.respond_to? :initialize_cache
296: @feed_cache.initialize_cache
297: end
298: return cache_class
299: else
300: return nil
301: end
302: rescue
303: return nil
304: end
305: else
306: return @feed_cache
307: end
308: 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 313
313: def FeedTools.feed_cache_connected?
314: begin
315: return false if FeedTools.feed_cache.nil?
316: return FeedTools.feed_cache.connected?
317: rescue
318: return false
319: end
320: end
# File lib/feed_tools.rb, line 195
195: def FeedTools.load_configurations
196: if @configurations.blank?
197: # TODO: Load this from a config file.
198: config_hash = {}
199: @configurations = {
200: :feed_cache => nil,
201: :disable_update_from_remote => false,
202: :proxy_address => nil,
203: :proxy_port => nil,
204: :proxy_user => nil,
205: :proxy_password => nil,
206: :auth_user => nil,
207: :auth_password => nil,
208: :auth_scheme => nil,
209: :http_timeout => nil,
210: :user_agent =>
211: "FeedTools/#{FeedTools::FEED_TOOLS_VERSION::STRING} " +
212: "+http://www.sporkmonger.com/projects/feedtools/",
213: :generator_name =>
214: "FeedTools/#{FeedTools::FEED_TOOLS_VERSION::STRING}",
215: :generator_href =>
216: "http://www.sporkmonger.com/projects/feedtools/",
217: :tidy_enabled => false,
218: :tidy_options => {},
219: :lazy_parsing_enabled => true,
220: :serialization_enabled => false,
221: :idn_enabled => true,
222: :sanitization_enabled => true,
223: :sanitize_with_nofollow => true,
224: :always_strip_wrapper_elements => true,
225: :timestamp_estimation_enabled => true,
226: :url_normalization_enabled => true,
227: :entry_sorting_property => "time",
228: :strip_comment_count => false,
229: :tab_spaces => 2,
230: :max_ttl => 3.days.to_s,
231: :default_ttl => 1.hour.to_s,
232: :output_encoding => "utf-8"
233: }.merge(config_hash)
234: end
235: return @configurations
236: end