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
-
#initialize(atom_feed_url, last_entry_id = nil, page_fetch_limit = nil) ⇒ Feed
constructor
A new instance of Feed.
Constructor Details
#initialize(atom_feed_url, last_entry_id = nil, page_fetch_limit = nil) ⇒ Feed
Returns a new instance of Feed.
6 7 8 9 10 |
# File 'lib/go_api_client/atom/feed.rb', line 6 def initialize(atom_feed_url, last_entry_id=nil, page_fetch_limit=nil) @atom_feed_url = atom_feed_url @last_entry_id = last_entry_id @page_fetch_limit = page_fetch_limit.to_i 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/go_api_client/atom/feed.rb', line 12 def fetch!(http_fetcher = HttpFetcher.new) self.entries = [] pages_fetched = 0 feed_url = @atom_feed_url begin doc = Nokogiri::XML(http_fetcher.get_response_body(feed_url)) pages_fetched += 1 if @page_fetch_limit > 0 && pages_fetched > @page_fetch_limit puts "=" * 100 puts "" puts "[GoApiClient] not fetching past #{@page_fetch_limit} pages of the Go.CD event feed." puts "If there is no green build in those pages, your app may not work properly." puts "Get your build green first!" puts "" puts "=" * 100 break end 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 |