From 34d0e173ef4774ac13b87653178e44d3ab79fd64 Mon Sep 17 00:00:00 2001 From: Ernesto Rocha Date: Mon, 15 Oct 2012 17:30:59 -0300 Subject: [PATCH 1/6] Adding support to list more than 1000 items at once --- lib/google-reader-api/feed.rb | 17 +++++++++++++++-- lib/google-reader-api/rss_utils.rb | 10 ++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/google-reader-api/feed.rb b/lib/google-reader-api/feed.rb index 5b74b78..3b1cb54 100644 --- a/lib/google-reader-api/feed.rb +++ b/lib/google-reader-api/feed.rb @@ -39,7 +39,20 @@ def starred_items(count=20) # return the number of specified items. (read or not) def items(count = 20) - create_entries get_feed_items(:n => count) + if count <= 1000 + all_items = get_feed_items(:n => count) + else + continuation = nil + feed_items = [] + (count/1000).times do |index| + feed_items << get_feed_items(continuation ? {:n => 1000} : {:n => 1000, :c => continuation}) + continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).captures.first + end + feed_items << get_feed_items({:n => (count%1000), :c => continuation}) + all_items = feed_items + end + + create_entries all_items end # return all the unread items in an array @@ -71,6 +84,6 @@ def get_user_items(state,args={}) def get_feed_items(args={}) @api.get_link "atom/feed/#{url}" , args end - + end end \ No newline at end of file diff --git a/lib/google-reader-api/rss_utils.rb b/lib/google-reader-api/rss_utils.rb index 6feb12d..d0baceb 100644 --- a/lib/google-reader-api/rss_utils.rb +++ b/lib/google-reader-api/rss_utils.rb @@ -6,8 +6,14 @@ module RssUtils private - def create_entries(atom_feed) - RSS::Parser.parse(atom_feed.force_encoding('utf-8')).entries.map {|e| GoogleReaderApi::Entry.new(@api,e) } + def create_entries(atom_feeds) + if atom_feeds.class == String + RSS::Parser.parse(atom_feeds.force_encoding('utf-8')).entries.map {|e| GoogleReaderApi::Entry.new(@api,e) } + elsif atom_feeds.class == Array + atom_feeds.map { |atom_feed| + RSS::Parser.parse(atom_feed.force_encoding('utf-8')).entries.map {|e| GoogleReaderApi::Entry.new(@api,e) } + }.flatten + end end end From 876961a4bd3e1c796168ab9d3224389a0bb44454 Mon Sep 17 00:00:00 2001 From: Ernesto Rocha Date: Mon, 15 Oct 2012 18:47:58 -0300 Subject: [PATCH 2/6] Only send another request if n is not mutiple of 1000 --- lib/google-reader-api/feed.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google-reader-api/feed.rb b/lib/google-reader-api/feed.rb index 3b1cb54..8713ec8 100644 --- a/lib/google-reader-api/feed.rb +++ b/lib/google-reader-api/feed.rb @@ -48,7 +48,7 @@ def items(count = 20) feed_items << get_feed_items(continuation ? {:n => 1000} : {:n => 1000, :c => continuation}) continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).captures.first end - feed_items << get_feed_items({:n => (count%1000), :c => continuation}) + feed_items << get_feed_items({:n => (count%1000), :c => continuation}) if (count%1000) > 0 all_items = feed_items end From 16572b88f3064e694e0144d944077b122b9b7eec Mon Sep 17 00:00:00 2001 From: Ernesto Rocha Date: Tue, 16 Oct 2012 03:40:39 -0300 Subject: [PATCH 3/6] Fixed moronic bug --- lib/google-reader-api/feed.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/google-reader-api/feed.rb b/lib/google-reader-api/feed.rb index 8713ec8..da3d7ab 100644 --- a/lib/google-reader-api/feed.rb +++ b/lib/google-reader-api/feed.rb @@ -38,17 +38,18 @@ def starred_items(count=20) end # return the number of specified items. (read or not) - def items(count = 20) + def itemss(count = 20) if count <= 1000 all_items = get_feed_items(:n => count) else continuation = nil feed_items = [] (count/1000).times do |index| - feed_items << get_feed_items(continuation ? {:n => 1000} : {:n => 1000, :c => continuation}) + args = (continuation ? {:n => 1000, :c => continuation} : {:n => 1000} ) + feed_items << get_feed_items(args) continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).captures.first end - feed_items << get_feed_items({:n => (count%1000), :c => continuation}) if (count%1000) > 0 + (feed_items << get_feed_items({:n => (count%1000), :c => continuation})) if (count%1000) > 0 all_items = feed_items end From 59930b43cd19c14e0d07a0c94b973a4c492a461a Mon Sep 17 00:00:00 2001 From: Ernesto Rocha Date: Tue, 16 Oct 2012 03:43:39 -0300 Subject: [PATCH 4/6] Fixed typo --- lib/google-reader-api/feed.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google-reader-api/feed.rb b/lib/google-reader-api/feed.rb index da3d7ab..0beed78 100644 --- a/lib/google-reader-api/feed.rb +++ b/lib/google-reader-api/feed.rb @@ -38,7 +38,7 @@ def starred_items(count=20) end # return the number of specified items. (read or not) - def itemss(count = 20) + def items(count = 20) if count <= 1000 all_items = get_feed_items(:n => count) else From 030d5a00bfc194fa4ca9f188670e190e770fcc63 Mon Sep 17 00:00:00 2001 From: Ernesto Rocha Date: Tue, 16 Oct 2012 13:48:21 -0300 Subject: [PATCH 5/6] Checking if google returns continuation token --- lib/google-reader-api/feed.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/google-reader-api/feed.rb b/lib/google-reader-api/feed.rb index 0beed78..456b1fb 100644 --- a/lib/google-reader-api/feed.rb +++ b/lib/google-reader-api/feed.rb @@ -47,9 +47,10 @@ def items(count = 20) (count/1000).times do |index| args = (continuation ? {:n => 1000, :c => continuation} : {:n => 1000} ) feed_items << get_feed_items(args) - continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).captures.first + continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).try(:accaptures).try(:first) + break unless continuation end - (feed_items << get_feed_items({:n => (count%1000), :c => continuation})) if (count%1000) > 0 + (feed_items << get_feed_items({:n => (count%1000), :c => continuation})) if (((count%1000) > 0) and continuation) all_items = feed_items end From ecc84f9142b79e6878d0f1d430e5863bc36d2479 Mon Sep 17 00:00:00 2001 From: Ernesto Rocha Date: Tue, 16 Oct 2012 13:57:52 -0300 Subject: [PATCH 6/6] Fixed typo --- lib/google-reader-api/feed.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google-reader-api/feed.rb b/lib/google-reader-api/feed.rb index 456b1fb..0562492 100644 --- a/lib/google-reader-api/feed.rb +++ b/lib/google-reader-api/feed.rb @@ -47,7 +47,7 @@ def items(count = 20) (count/1000).times do |index| args = (continuation ? {:n => 1000, :c => continuation} : {:n => 1000} ) feed_items << get_feed_items(args) - continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).try(:accaptures).try(:first) + continuation = feed_items.last.match(/(.*)<\/gr:continuation>/).try(:captures).try(:first) break unless continuation end (feed_items << get_feed_items({:n => (count%1000), :c => continuation})) if (((count%1000) > 0) and continuation)