greedy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/greedy.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{greedy}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Weiland"]
12
- s.date = %q{2010-07-24}
12
+ s.date = %q{2010-07-25}
13
13
  s.description = %q{With greedy, you can access and manipulate the reading list for a Google Reader account via the API. Inspired by John Nunemaker's GoogleReader gem.}
14
14
  s.email = %q{jeremy6d@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,8 +1,3 @@
1
- require 'gdata'
2
- require 'nokogiri'
3
- require 'json'
4
- require 'cgi'
5
-
6
1
  module Greedy
7
2
  class Connection
8
3
  BASE_URL = "http://www.google.com/reader/api/0/"
data/lib/greedy/entry.rb CHANGED
@@ -2,22 +2,18 @@ module Greedy
2
2
  class Entry
3
3
  attr_reader :title, :author, :href, :google_item_id, :feed,
4
4
  :categories, :body, :truncated_body, :stream
5
-
6
- # Entry States
7
- # read A read item will have the state read
8
- # kept-unread Once you've clicked on "keep unread", an item will have the state kept-unread
9
- # fresh When a new item of one of your feeds arrive, it's labeled as fresh. When (need to find what remove fresh label), the fresh label disappear.
10
- # starred When your mark an item with a star, you set it's starred state
11
- # broadcast When your mark an item as being public, you set it's broadcast state
12
- # reading-list All you items are flagged with the reading-list state. To see all your items, just ask for items in the state reading-list
13
- # tracking-body-link-used Set if you ever clicked on a link in the description of the item.
14
- # tracking-emailed Set if you ever emailed the item to someone.
15
- # tracking-item-link-used Set if you ever clicked on a link in the description of the item.
16
- # tracking-kept-unread Set if you ever mark your read item as unread.
5
+
17
6
  module States
18
- ALL = ["read", "kept-unread", "fresh", "starred", "broadcast",
19
- "reading-list", "tracking-body-link-used", "tracking-emailed",
20
- "tracking-item-link-used", "tracking-kept-unread"]
7
+ ALL = ["read", # A read item will have the state read
8
+ "kept-unread", # Once you've clicked on "keep unread", an item will have the state kept-unread
9
+ "fresh", # When a new item of one of your feeds arrive, it's labeled as fresh. When (need to find what remove fresh label), the fresh label disappear.
10
+ "broadcast", # When your mark an item as being public, you set it's broadcast state
11
+ "reading-list", # All you items are flagged with the reading-list state. To see all your items, just ask for items in the state reading-list
12
+ "tracking-body-link-used", # Set if you ever clicked on a link in the description of the item.
13
+ "tracking-emailed", # Set if you ever emailed the item to someone.
14
+ "tracking-item-link-used", # Set if you ever clicked on a link in the description of the item.
15
+ "tracking-kept-unread" # Set if you ever mark your read item as unread.
16
+ ]
21
17
  ALL.each do |name|
22
18
  const_set name.upcase.gsub("-", "_"), "user/-/state/com.google/#{name}"
23
19
  end
@@ -26,7 +22,7 @@ module Greedy
26
22
  DEFAULT_CHAR_COUNT = 2000
27
23
 
28
24
  # Instantiate and normalize a new Google Reader entry
29
- def initialize(item, stream)
25
+ def initialize(item, stream = nil)
30
26
  @stream = stream
31
27
  raise "Title is nil" unless item['title']
32
28
  @title = normalize item['title']
@@ -35,9 +31,11 @@ module Greedy
35
31
  @google_item_id = item['id']
36
32
  @published = item['published']
37
33
  @updated = item['updated']
38
- body = get_body(item)
34
+ puts "error rendering body for hash\n#{item.inspect}" unless set_body!(item)
39
35
  @feed = Greedy::Feed.new(item['origin'])
40
36
  end
37
+
38
+ def
41
39
 
42
40
  # Provide the entry time by which the entry should be sorted amongst other entries
43
41
  def sort_by_time
@@ -55,8 +53,16 @@ module Greedy
55
53
  end
56
54
 
57
55
  # Set the body of the entry as normalized text and create a truncated version
58
- def body=(text, char_count = DEFAULT_CHAR_COUNT)
59
- @body = normalize(text)
56
+ def set_body!(in_hash)
57
+ raw_text = begin
58
+ key = %w(content summary container).detect { |key| in_hash[key] }
59
+ in_hash[key]['content']
60
+ rescue
61
+ return false
62
+ end
63
+
64
+ @body = normalize raw_text
65
+
60
66
  doc = Nokogiri::XML::DocumentFragment.parse(@body)
61
67
  count = index = 0
62
68
  truncated = false
@@ -64,14 +70,14 @@ module Greedy
64
70
  doc.children.each do |child|
65
71
  count = count + child.content.length.to_i
66
72
  index = index + 1
67
- if count > char_count
73
+ if count > DEFAULT_CHAR_COUNT
68
74
  truncated = true
69
75
  break
70
76
  end
71
77
  end
72
78
 
73
79
  @truncated_body = doc.children.slice(0, index).to_html
74
- @body
80
+ true
75
81
  end
76
82
 
77
83
  def mark_as_read!
@@ -83,13 +89,6 @@ module Greedy
83
89
  end
84
90
 
85
91
  protected
86
-
87
- def get_body(item_hash)
88
- container = item_hash['content'] || item_hash['summary'] || item_hash['description']
89
- return container['content']
90
- rescue
91
- nil
92
- end
93
92
 
94
93
  def normalize(text)
95
94
  return text if text.nil?
data/lib/greedy/stream.rb CHANGED
@@ -1,8 +1,3 @@
1
- require 'gdata'
2
- require 'nokogiri'
3
- require 'json'
4
- require 'cgi'
5
-
6
1
  module Greedy
7
2
  class Stream
8
3
  BASE_PATH = "stream/contents/"
@@ -39,7 +34,6 @@ module Greedy
39
34
  end
40
35
 
41
36
  def change_state_for(entry, state)
42
- debugger
43
37
  @connection.post((BASE_PATH + CHANGE_STATE_PATH), { :a => state,
44
38
  :i => entry.google_item_id,
45
39
  :s => entry.feed.google_feed_id })
data/lib/greedy.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), %w[lib]))
2
2
 
3
+ puts "\n\nLOCAL VERSION\n\n"
4
+
3
5
  require "rubygems"
4
6
 
5
7
  require 'gdata'
6
8
  require 'nokogiri'
7
9
  require 'json'
8
10
  require 'cgi'
11
+ require 'ruby-debug'
9
12
 
10
13
  require 'greedy/connection'
11
14
  require 'greedy/stream'
data/test/test_entry.rb CHANGED
@@ -16,8 +16,14 @@ class TestEntry < Test::Unit::TestCase
16
16
  @entry.href.should == "http://feeds.officer.com/~r/officerrss/top_news_stories/~3/UmVWa_XwtRc/article.jsp"
17
17
  end
18
18
 
19
+ should "set body correctly" do
20
+ @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\">"
21
+ @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\">"
22
+ end
23
+
19
24
  should "set truncated_body correctly" do
20
- @entry.body = File.open("test/fixtures/lorem_ipsum.txt").read
25
+ @raw_entry['summary']['content'] = File.open("test/fixtures/lorem_ipsum.txt").read
26
+ @entry = Greedy::Entry.new(@raw_entry, @stream)
21
27
  @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>"
22
28
  end
23
29
 
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Weiland
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-24 00:00:00 -04:00
18
+ date: 2010-07-25 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency