Class: Buzzr::Feed
- Inherits:
-
Object
- Object
- Buzzr::Feed
- Defined in:
- lib/buzzr/feed.rb
Instance Attribute Summary collapse
-
#atom_feed ⇒ Object
readonly
Returns the value of attribute atom_feed.
-
#feed_url ⇒ Object
readonly
Returns the value of attribute feed_url.
Class Method Summary collapse
-
.discover(profile_name) ⇒ Object
Extract the feed url from the users’s google profile page.
- .retrieve(feed_url) ⇒ Object
Instance Method Summary collapse
-
#entries ⇒ Object
Retrieve the entries in the buzz atom feed as an array of FeedEntry objects This will fetch the feed if it has not already been fetched.
-
#fetch ⇒ Object
Retrieve and parse the buzz atom feed.
-
#initialize(feed_url, options = {}) ⇒ Feed
constructor
A new instance of Feed.
Constructor Details
#initialize(feed_url, options = {}) ⇒ Feed
Returns a new instance of Feed.
8 9 10 |
# File 'lib/buzzr/feed.rb', line 8 def initialize(feed_url, = {}) @feed_url = feed_url end |
Instance Attribute Details
#atom_feed ⇒ Object (readonly)
Returns the value of attribute atom_feed.
6 7 8 |
# File 'lib/buzzr/feed.rb', line 6 def atom_feed @atom_feed end |
#feed_url ⇒ Object (readonly)
Returns the value of attribute feed_url.
5 6 7 |
# File 'lib/buzzr/feed.rb', line 5 def feed_url @feed_url end |
Class Method Details
.discover(profile_name) ⇒ Object
Extract the feed url from the users’s google profile page
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/buzzr/feed.rb', line 19 def self.discover(profile_name) begin page = open("http://www.google.com/profiles/#{profile_name}").read rescue OpenURI::HTTPError => e if e.io.status[0] == '404' raise FeedError, "Could not find profile for #{profile_name} at - http://www.google.com/profiles/#{profile_name}" end end if match = page.match(%r{<link rel="alternate" type="application/atom\+xml" href="([^"]+)}) match[1] else raise FeedError, "Could not find atom feed on profile page" end end |
Instance Method Details
#entries ⇒ Object
Retrieve the entries in the buzz atom feed as an array of FeedEntry objects This will fetch the feed if it has not already been fetched
43 44 45 46 47 |
# File 'lib/buzzr/feed.rb', line 43 def entries return @feed_entries if @feed_entries fetch if @atom_feed.nil? @feed_entries = @atom_feed.entries.collect {|e| FeedEntry.new(e) } end |
#fetch ⇒ Object
Retrieve and parse the buzz atom feed
36 37 38 39 |
# File 'lib/buzzr/feed.rb', line 36 def fetch @feed_entries = nil @atom_feed = Atom::Feed.load_feed(URI.parse(@feed_url)) end |