Class: Buzzr::Feed

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @feed_url = feed_url
end

Instance Attribute Details

#atom_feedObject (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_urlObject (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

.retrieve(feed_url) ⇒ Object



12
13
14
15
16
# File 'lib/buzzr/feed.rb', line 12

def self.retrieve(feed_url)
  feed = Feed.new(feed_url)
  feed.fetch
  feed
end

Instance Method Details

#entriesObject

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

#fetchObject

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