Module: FeedTools

Defined in:
lib/feed_tools.rb,
lib/feed_tools/feed.rb,
lib/feed_tools/version.rb,
lib/feed_tools/feed_item.rb,
lib/feed_tools/vendor/uri.rb,
lib/feed_tools/feed_structures.rb,
lib/feed_tools/helpers/uri_helper.rb,
lib/feed_tools/helpers/xml_helper.rb,
lib/feed_tools/database_feed_cache.rb,
lib/feed_tools/helpers/feed_helper.rb,
lib/feed_tools/helpers/html_helper.rb,
lib/feed_tools/helpers/debug_helper.rb,
lib/feed_tools/helpers/generic_helper.rb,
lib/feed_tools/helpers/feed_item_helper.rb,
lib/feed_tools/helpers/retrieval_helper.rb,
lib/feed_tools/helpers/feed_tools_helper.rb

Overview

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

Defined Under Namespace

Modules: DebugHelper, FEED_TOOLS_VERSION, FeedHelper, FeedItemHelper, FeedToolsHelper, GenericHelper, HtmlHelper, RetrievalHelper, UriHelper, XmlHelper Classes: Author, Category, Cloud, DatabaseFeedCache, Enclosure, EnclosureCredit, EnclosureHash, EnclosurePlayer, EnclosureThumbnail, Feed, FeedAccessError, FeedItem, Image, Link, TextInput, URI

Class Method Summary collapse

Class Method Details

.build_merged_feed(url_array, options = {}) ⇒ Object

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.



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/feed_tools.rb', line 338

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

.configurationsObject

Returns the configuration hash for FeedTools



254
255
256
257
258
259
# File 'lib/feed_tools.rb', line 254

def FeedTools.configurations
  if @configurations.blank?
    FeedTools.load_configurations()
  end
  return @configurations
end

.configurations=(new_configurations) ⇒ Object

Sets the configuration hash for FeedTools



262
263
264
# File 'lib/feed_tools.rb', line 262

def FeedTools.configurations=(new_configurations)
  @configurations = new_configurations
end

.feed_cacheObject

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?


296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/feed_tools.rb', line 296

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?Boolean

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.

Returns:

  • (Boolean)


322
323
324
325
326
327
328
329
# File 'lib/feed_tools.rb', line 322

def FeedTools.feed_cache_connected?
  begin
    return false if FeedTools.feed_cache.nil?
    return FeedTools.feed_cache.connected?
  rescue
    return false
  end
end

.load_configurationsObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/feed_tools.rb', line 204

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_configurationsObject

Resets configuration to a clean load



248
249
250
251
# File 'lib/feed_tools.rb', line 248

def FeedTools.reset_configurations
  @configurations = nil
  FeedTools.load_configurations
end