greedy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -12
- data/VERSION +1 -1
- data/greedy.gemspec +1 -1
- data/lib/greedy/entry.rb +26 -23
- data/lib/greedy.rb +0 -2
- data/test/test_entry.rb +63 -13
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -8,18 +8,17 @@ A simple way to use the Google Reader API to retrieve streams of content.
|
|
8
8
|
|
9
9
|
== Usage Example
|
10
10
|
|
11
|
-
|
12
|
-
list.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
list.
|
22
|
-
list.entries.size = 80+
|
11
|
+
list = Greedy::Stream.new("username", "password")
|
12
|
+
list.entries.each do |e| # iterate over each Greedy::Entry
|
13
|
+
puts e.title
|
14
|
+
puts e.body
|
15
|
+
end
|
16
|
+
list.continue!(20).each do |e| # pull next 20 and iterate over them
|
17
|
+
e.mark_as_read!
|
18
|
+
e.share!
|
19
|
+
end
|
20
|
+
list.continue!(50)
|
21
|
+
list.entries.size # 80
|
23
22
|
|
24
23
|
== Note on Patches/Pull Requests
|
25
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/greedy.gemspec
CHANGED
data/lib/greedy/entry.rb
CHANGED
@@ -24,22 +24,21 @@ module Greedy
|
|
24
24
|
# Instantiate and normalize a new Google Reader entry
|
25
25
|
def initialize(item, stream = nil)
|
26
26
|
@stream = stream
|
27
|
-
|
28
|
-
|
27
|
+
@feed = Greedy::Feed.new(item['origin'])
|
28
|
+
|
29
29
|
@author = normalize item['author']
|
30
30
|
@href = item['alternate'].first['href']
|
31
31
|
@google_item_id = item['id']
|
32
32
|
@published = item['published']
|
33
33
|
@updated = item['updated']
|
34
|
-
|
35
|
-
|
34
|
+
|
35
|
+
set_body!(item)
|
36
|
+
set_title!(item)
|
36
37
|
end
|
37
|
-
|
38
|
-
def
|
39
38
|
|
40
39
|
# Provide the entry time by which the entry should be sorted amongst other entries
|
41
40
|
def sort_by_time
|
42
|
-
updated_at || published_at
|
41
|
+
(updated_at || published_at)
|
43
42
|
end
|
44
43
|
|
45
44
|
# Provide the canonical publish date in +Time+ format
|
@@ -51,8 +50,27 @@ module Greedy
|
|
51
50
|
def updated_at
|
52
51
|
Time.at @updated rescue nil
|
53
52
|
end
|
53
|
+
|
54
|
+
def mark_as_read!
|
55
|
+
stream.change_state_for(self, States::READ)
|
56
|
+
end
|
57
|
+
|
58
|
+
def share!
|
59
|
+
stream.change_state_for(self, States::BROADCAST)
|
60
|
+
end
|
54
61
|
|
55
|
-
|
62
|
+
protected
|
63
|
+
def set_title!(hash)
|
64
|
+
raw_title = hash['title'] || "#{@feed.title} - #{published_at.strftime "%B %d"}"
|
65
|
+
@title = normalize raw_title
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
def normalize(text)
|
70
|
+
return text if text.nil?
|
71
|
+
Nokogiri::XML::DocumentFragment.parse(text).to_html
|
72
|
+
end
|
73
|
+
|
56
74
|
def set_body!(in_hash)
|
57
75
|
raw_text = begin
|
58
76
|
key = %w(content summary container).detect { |key| in_hash[key] }
|
@@ -79,20 +97,5 @@ module Greedy
|
|
79
97
|
@truncated_body = doc.children.slice(0, index).to_html
|
80
98
|
true
|
81
99
|
end
|
82
|
-
|
83
|
-
def mark_as_read!
|
84
|
-
stream.change_state_for(self, States::READ)
|
85
|
-
end
|
86
|
-
|
87
|
-
def share!
|
88
|
-
stream.change_state_for(self, States::BROADCAST)
|
89
|
-
end
|
90
|
-
|
91
|
-
protected
|
92
|
-
|
93
|
-
def normalize(text)
|
94
|
-
return text if text.nil?
|
95
|
-
Nokogiri::XML::DocumentFragment.parse(text).to_html
|
96
|
-
end
|
97
100
|
end
|
98
101
|
end
|
data/lib/greedy.rb
CHANGED
data/test/test_entry.rb
CHANGED
@@ -4,21 +4,33 @@ class TestEntry < Test::Unit::TestCase
|
|
4
4
|
context "A Greedy entry" do
|
5
5
|
setup do
|
6
6
|
@stream = stub("Greedy::Stream")
|
7
|
-
@raw_entry =
|
8
|
-
@
|
7
|
+
@raw_entry = a_typical_raw_entry_hash
|
8
|
+
@feed = stub("Greedy::Feed", :title => "The Feed Title")
|
9
|
+
Greedy::Feed.stubs(:new).returns(@feed)
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
context "initializing" do
|
13
|
+
setup do
|
14
|
+
@entry = Greedy::Entry.new(@raw_entry, @stream)
|
15
|
+
end
|
16
|
+
|
17
|
+
should "be able to instantiate from a raw entry hash and a stream" do
|
18
|
+
|
19
|
+
@entry.class.should == Greedy::Entry
|
20
|
+
end
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
|
22
|
+
should "set href correctly" do
|
23
|
+
@entry.href.should == "http://feeds.officer.com/~r/officerrss/top_news_stories/~3/UmVWa_XwtRc/article.jsp"
|
24
|
+
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
should "set body correctly" do
|
27
|
+
@entry.body.should == "Jeremy Hernandez, 20, was arrested after he tried to pull over an undercover police officer.<img src=\"http://feeds.feedburner.com/~r/officerrss/top_news_stories/~4/UmVWa_XwtRc\" height=\"1\" width=\"1\">"
|
28
|
+
@entry.truncated_body.should == "Jeremy Hernandez, 20, was arrested after he tried to pull over an undercover police officer.<img src=\"http://feeds.feedburner.com/~r/officerrss/top_news_stories/~4/UmVWa_XwtRc\" height=\"1\" width=\"1\">"
|
29
|
+
end
|
30
|
+
|
31
|
+
should "set feed correctly" do
|
32
|
+
@entry.feed.should == @feed
|
33
|
+
end
|
22
34
|
end
|
23
35
|
|
24
36
|
should "set truncated_body correctly" do
|
@@ -27,8 +39,46 @@ class TestEntry < Test::Unit::TestCase
|
|
27
39
|
@entry.truncated_body.should == "<p>Lorem ipsum putant alterum in ius. Ex partiendo honestatis ius, ex ignota lucilius eam. Nec modo utroque mentitum id, id erant adipisci democritum qui. Veniam altera vim ex. In nullam constituto mei, singulis electram adipiscing eu nam. Eos debet impedit perpetua ad, movet luptatum sit at. </p> <p> Ut sale utinam has, at eam enim fabellas probatus. Id sea autem nostro maiorum, ridens cotidieque an eam. Dolore corpora pro cu, eu quodsi probatus deseruisse sea. Eu ullum oratio voluptatum vim. </p> <p> Quo labore iisque erroribus ne, homero doctus ex usu. His dicant aliquam verterem in. Eum id zzril altera. Per ei novum perpetua salutandi, noluisse scaevola sententiae an eam. </p> <p> Mea no noluisse persequeris, ea eos mazim possit salutandi, aeque malorum eloquentiam usu te. Et vidit nostrum pertinax sea, eros voluptua officiis in vis. Te dolorum molestie inciderint est. Mea ei populo quaeque euripidis, invenire democritum omittantur et mel. Nullam epicurei ex nam, no mea cetero disputationi. Ne utinam feugait sed. No impedit appareat mei, qui at facete aperiam comprehensam, omnes complectitur mea id. </p> <p> Eum nostrud laoreet invidunt ne, puto elitr per ex. Modo accusamus ex eos. Sit cu dicam nominati, animal regione eam at. Prima tation suavitate ea eam. Sea error perpetua consetetur ex, duo inani decore dissentias ne. Quidam inimicus vis ad, modo duis et pro, id porro dicunt maluisset eos. </p> <p> In elitr ceteros laboramus vis, cu meliore scribentur eum. Ne graece corpora vim, in zzril tamquam persecuti pro. Mel dicit eripuit ad, fugit rationibus consectetuer cu cum. Qui mandamus adipiscing in. Ei duo meis liber, his admodum tincidunt ad. Mea ut detracto iracundia. </p> <p> Vel altera labore ponderum an, ea has sapientem gloriatur, ad vim prompta eleifend. Ut per nostro alterum noluisse, in eruditi nostrum vim. No fugit virtute alterum mei, vis ne autem clita. Duo in sonet epicurei expetenda, ea movet erroribus ius, ne usu nihil nobis. Legere liberavisse his ne, pri cibo invenire cotidieque ut. No elaboraret referrentur sit, sea ne iuvaret oporteat. Eum cu quidam maiorum, est ex indoctum rationibus voluptatibus. </p>"
|
28
40
|
end
|
29
41
|
|
30
|
-
should "
|
31
|
-
|
42
|
+
should "set the title to a default setting if the feed supplies no entry title" do
|
43
|
+
@raw_entry['title'] = nil
|
44
|
+
Greedy::Entry.new(@raw_entry, @stream).title.should == "The Feed Title - July 22"
|
45
|
+
end
|
46
|
+
|
47
|
+
should_eventually "be able to share itself" do
|
48
|
+
@stream.expects(:change_state_for).with(@entry, "broadcast").returns(true)
|
49
|
+
@entry.share!
|
50
|
+
end
|
51
|
+
|
52
|
+
should_eventually "be able to mark itself read" do
|
53
|
+
@stream.expects(:change_state_for).with(@entry, "read").returns(true)
|
54
|
+
@entry.mark_as_read!
|
32
55
|
end
|
33
56
|
end
|
57
|
+
|
58
|
+
def a_typical_raw_entry_hash
|
59
|
+
{
|
60
|
+
"likingUsers" => [],
|
61
|
+
"comments" => [],
|
62
|
+
"author" => "rss@officer.com (Maggie Ybarra)",
|
63
|
+
"title" => "Fake Texas Cop Tries to Pull Over Undercover Officer",
|
64
|
+
"crawlTimeMsec" => "1279769942562",
|
65
|
+
"published" => 1279773120,
|
66
|
+
"annotations" => [],
|
67
|
+
"alternate" => [ { "href" => "http://feeds.officer.com/~r/officerrss/top_news_stories/~3/UmVWa_XwtRc/article.jsp",
|
68
|
+
"type" => "text/html"} ],
|
69
|
+
"id" => "tag:google.com,2005:reader/item/1b233c6c984c64b0",
|
70
|
+
"origin" => { "title" => "Officer.com: Top News Stories",
|
71
|
+
"htmlUrl" => "http://www.officer.com",
|
72
|
+
"streamId" => "feed/http://feeds.officer.com/officerrss/top_news_stories" },
|
73
|
+
"summary" => { "content" => "Jeremy Hernandez, 20, was arrested after he tried to pull over an undercover police officer.<img src=\"http://feeds.feedburner.com/~r/officerrss/top_news_stories/~4/UmVWa_XwtRc\" height=\"1\" width=\"1\">",
|
74
|
+
"direction" => "ltr" },
|
75
|
+
"categories" => [ "user/17398194162169227368/label/law_enforcement",
|
76
|
+
"user/17398194162169227368/label/mainstream",
|
77
|
+
"user/17398194162169227368/label/news",
|
78
|
+
"user/17398194162169227368/state/com.google/reading-list",
|
79
|
+
"user/17398194162169227368/state/com.google/fresh",
|
80
|
+
"Top News Stories" ],
|
81
|
+
"updated" => 1279773120
|
82
|
+
}
|
83
|
+
end
|
34
84
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greedy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Weiland
|