Class: GoogleReaderApi::Feed

Inherits:
Object
  • Object
show all
Includes:
RssUtils
Defined in:
lib/google-reader-api-uniq/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, api) ⇒ Feed

Returns a new instance of Feed.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/google-reader-api-uniq/feed.rb', line 9

def initialize(hash,api)
  # strip the first 5 characters of the url (they are 'feed/')
  @url = hash['id'][5..-1]
  @title = hash['title']
  # no idea what this is used for
  @sortid = hash['sortid']
  @categories = hash['categories']
  @firstitemmsec = hash['firstitemmsec']
  
  @api = api
end

Instance Attribute Details

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/google-reader-api-uniq/feed.rb', line 7

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/google-reader-api-uniq/feed.rb', line 7

def url
  @url
end

Instance Method Details

#all_unread_itemsObject

return all the unread items in an array



46
47
48
# File 'lib/google-reader-api-uniq/feed.rb', line 46

def all_unread_items
  unread_count > 0 ? unread_items(unread_count) : []
end

#inspectObject



57
58
59
# File 'lib/google-reader-api-uniq/feed.rb', line 57

def inspect
  to_s
end

#items(count = 20) ⇒ Object

return the number of specified items. (read or not)



41
42
43
# File 'lib/google-reader-api-uniq/feed.rb', line 41

def items(count = 20)
  create_entries get_feed_items(:n => count)
end

#read_items(count = 20) ⇒ Object

return count read items



32
33
34
# File 'lib/google-reader-api-uniq/feed.rb', line 32

def read_items(count=20)
  create_entries get_user_items('read',:n => count)
end

#starred_items(count = 20) ⇒ Object



36
37
38
# File 'lib/google-reader-api-uniq/feed.rb', line 36

def starred_items(count=20)
  create_entries get_user_items('starred',:n => count)
end

#to_sObject



61
62
63
# File 'lib/google-reader-api-uniq/feed.rb', line 61

def to_s
  "<<Feed: #{title} url:#{url}>>"
end

#unread_countObject



26
27
28
29
# File 'lib/google-reader-api-uniq/feed.rb', line 26

def unread_count
  entry = JSON[@api.cached_unread_count]['unreadcounts'].find {|h| h['id'] == "feed/#{url}"}
  entry ? entry['count'] : 0
end

#unread_items(count = 20) ⇒ Object

will return an array of GoogleReader::Feed::Entry objects. will try to return the amount of unread items you specify. unless there are no more. will return 20 unread items by default.



53
54
55
# File 'lib/google-reader-api-uniq/feed.rb', line 53

def unread_items(count = 20)
  create_entries get_feed_items(:n => count,:xt => 'user/-/state/com.google/read')
end

#unsubscribeObject



21
22
23
24
# File 'lib/google-reader-api-uniq/feed.rb', line 21

def unsubscribe
  @api.post_link 'api/0/subscription/edit' , :s => "feed/#{url}",
                                             :ac => :unsubscribe
end