Class: GoApiClient::Atom::Feed
- Inherits:
-
Object
- Object
- GoApiClient::Atom::Feed
- Defined in:
- lib/go_api_client/atom/feed.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#feed_pages ⇒ Object
Returns the value of attribute feed_pages.
Instance Method Summary collapse
- #fetch!(http_fetcher = HttpFetcher.new) ⇒ Object
- #fetch_all!(http_fetcher = HttpFetcher.new) ⇒ Object
-
#initialize(atom_feed_url, last_entry_id = nil) ⇒ Feed
constructor
A new instance of Feed.
Constructor Details
#initialize(atom_feed_url, last_entry_id = nil) ⇒ Feed
Returns a new instance of Feed.
6 7 8 9 |
# File 'lib/go_api_client/atom/feed.rb', line 6 def initialize(atom_feed_url, last_entry_id=nil) @atom_feed_url = atom_feed_url @last_entry_id = last_entry_id end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
4 5 6 |
# File 'lib/go_api_client/atom/feed.rb', line 4 def entries @entries end |
#feed_pages ⇒ Object
Returns the value of attribute feed_pages.
4 5 6 |
# File 'lib/go_api_client/atom/feed.rb', line 4 def feed_pages @feed_pages end |
Instance Method Details
#fetch!(http_fetcher = HttpFetcher.new) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/go_api_client/atom/feed.rb', line 11 def fetch!(http_fetcher = HttpFetcher.new) self.entries = [] feed_url = @atom_feed_url begin doc = Nokogiri::XML(http_fetcher.get!(feed_url)) feed_page = GoApiClient::Atom::FeedPage.new(doc.root).parse! self.entries += if feed_page.contains_entry?(@last_entry_id) feed_page.entries_after(@last_entry_id) else feed_page.entries end feed_url = feed_page.next_page end while feed_page.next_page && !feed_page.contains_entry?(@last_entry_id) self end |
#fetch_all!(http_fetcher = HttpFetcher.new) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/go_api_client/atom/feed.rb', line 29 def fetch_all!(http_fetcher = HttpFetcher.new) begin doc = Nokogiri::XML(http_fetcher.get!(@atom_feed_url)) doc.css("pipeline").inject({}) do |hash, feed| hash[feed.attr("href")] = GoApiClient::Atom::Feed.new(feed.attr("href")).fetch! hash end end end |