Class: Feedzirra::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/feedzirra/feed.rb

Overview

TODO - remove this class, and only use the Feedzirra::Reader class for accessing feed data.

Class Method Summary collapse

Class Method Details

.fetch_and_parse(urls, options = {}) ⇒ Object

Fetches and returns the parsed XML for each URL provided.

Parameters

[urls or ] A single feed URL, or an array of feed URLs. [options] Valid keys for this argument as as followed:

  • :user_agent - String that overrides the default user agent.
  • :if_modified_since - Time object representing when the feed was last updated.
  • :if_none_match - String, an etag for the request that was stored previously.
  • :on_success - Block that gets executed after a successful request.
  • :on_failure - Block that gets executed after a failed request.

Returns

A Feed object if a single URL is passed.

A Hash if multiple URL's are passed. The key will be the URL, and the value the Feed object.



20
21
22
23
24
# File 'lib/feedzirra/feed.rb', line 20

def self.fetch_and_parse(urls, options = {})
  multi = Feedzirra::HttpMulti.new(urls, options)
  multi.perform
  urls.is_a?(String) ? multi.responses.values.first : multi.responses
end

.fetch_raw(urls, options = {}) ⇒ Object

Fetches and returns the raw XML for each URL provided.

Parameters

[urls or ] A single feed URL, or an array of feed URLs. [options] Valid keys for this argument as as followed: :user_agent - String that overrides the default user agent. :if_modified_since - Time object representing when the feed was last updated. :if_none_match - String that's normally an etag for the request that was stored previously. :on_success - Block that gets executed after a successful request. :on_failure - Block that gets executed after a failed request.

Returns

A String of XML if a single URL is passed.

A Hash if multiple URL's are passed. The key will be the URL, and the value the XML.

FIXME - Raw mode is currently not supported!



61
62
63
64
65
# File 'lib/feedzirra/feed.rb', line 61

def self.fetch_raw(urls, options = {})
  multi = Feedzirra::HttpMulti.new(urls, options.merge(:raw => true))
  multi.perform
  urls.is_a?(String) ? multi.responses.values.first : multi.responses
end

.update(feeds, options = {}) ⇒ Object

Updates each feed for each Feed object provided.

Parameters

[feeds or ] A single feed object, or an array of feed objects. [options] Valid keys for this argument as as followed: * :user_agent - String that overrides the default user agent. * :on_success - Block that gets executed after a successful request. * :on_failure - Block that gets executed after a failed request.

Returns

A updated Feed object if a single URL is passed.

A Hash if multiple Feeds are passed. The key will be the URL, and the value the updated Feed object.



38
39
40
41
42
43
# File 'lib/feedzirra/feed.rb', line 38

def self.update(feeds, options = {})
  multi = Feedzirra::HttpMulti.new(urls, options)

  multi.perform
  multi.responses.size == 1 ? multi.responses.values.first : multi.responses.values
end