Class: GReader::Feed
Overview
A feed is a collection of entries.
Common usage
Getting feeds:
feed = client.feed('FEED_ID')
Common metadata:
feed.title #=> "Rico's blog" (or #to_s)
feed.url #=> "http://ricostacruz.com"
feed.id #=> "feed/http://ricostacruz.com" (from Google)
Collections:
feed.entries #=> [#<Entry>, ...]
feed. #=> [#<Tag>, ...]
Entry lookup:
feed.entries['ENTRY_ID']
Other ways of getting feeds:
client.feeds.each { |feed| }
client.tag('TAG_ID').feeds.each { |feed| }
:stopdoc: This is what Google spits out as JSON.
id: feed/http://xkcd.com/rss.xml
title: xkcd.com
categories:
- id: user/05185502537486227907/label/Misc | Comics
label: Misc | Comics
sortid: 6795ABCE
firstitemmsec: "1205294559301"
htmlUrl: http://xkcd.com/
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sortid ⇒ Object
readonly
Returns the value of attribute sortid.
-
#title ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#entries(options = {}) ⇒ Entries
List of entries.
- #expire! ⇒ Object
-
#initialize(client = Client.new, options = {}) ⇒ Feed
constructor
A new instance of Feed.
- #inspect ⇒ Object
- #tags ⇒ Object
- #to_param ⇒ Object
Methods included from Utilities
#escape, #kv_map, #slug, #strip_tags
Constructor Details
#initialize(client = Client.new, options = {}) ⇒ Feed
Returns a new instance of Feed.
53 54 55 56 57 58 59 60 61 |
# File 'lib/greader/feed.rb', line 53 def initialize(client=Client.new, ={}) @client = client @options = @title = ['title'] @url = ['id'].gsub("feed/","") @sortid = ['sortid'] @id = ['id'] @tags_ = ['categories'] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
49 50 51 |
# File 'lib/greader/feed.rb', line 49 def client @client end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
48 49 50 |
# File 'lib/greader/feed.rb', line 48 def id @id end |
#sortid ⇒ Object (readonly)
Returns the value of attribute sortid.
47 48 49 |
# File 'lib/greader/feed.rb', line 47 def sortid @sortid end |
#title ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute title.
46 47 48 |
# File 'lib/greader/feed.rb', line 46 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
45 46 47 |
# File 'lib/greader/feed.rb', line 45 def url @url end |
Instance Method Details
#<=>(other) ⇒ Object
73 74 75 |
# File 'lib/greader/feed.rb', line 73 def <=>(other) sortid <=> other.sortid end |
#entries(options = {}) ⇒ Entries
List of entries.
Options
- limit
-
The number of items (default
20
) - order
-
The order of items;
:desc
is recent first,:asc
is earliest first (default:desc
) - start_time
-
The time (
Time
object) from which to start getting items. Only applicable iforder
is:asc
.
Quirks
The results are cached. If you want to purge the cache, use #expire!.
97 98 99 |
# File 'lib/greader/feed.rb', line 97 def entries(={}) @entries ||= Entries.fetch @client, "stream/contents/#{escape id}" end |
#expire! ⇒ Object
105 106 107 |
# File 'lib/greader/feed.rb', line 105 def expire! @entries = nil end |
#inspect ⇒ Object
101 102 103 |
# File 'lib/greader/feed.rb', line 101 def inspect "#<#{self.class.name} \"#{title}\" (#{url})>" end |
#tags ⇒ Object
63 64 65 66 67 |
# File 'lib/greader/feed.rb', line 63 def @tags ||= begin @tags_.map { |tag| @client.tag(tag['id']) } end end |
#to_param ⇒ Object
69 70 71 |
# File 'lib/greader/feed.rb', line 69 def to_param slug @id end |