Class: GReader::Feed

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/greader/feed.rb

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.tags         #=> [#<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

Instance Method Summary collapse

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, options={})
  @client  = client
  @options = options
  @title   = options['title']
  @url     = options['id'].gsub("feed/","")
  @sortid  = options['sortid']
  @id      = options['id']
  @tags_   = options['categories']
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



49
50
51
# File 'lib/greader/feed.rb', line 49

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



48
49
50
# File 'lib/greader/feed.rb', line 48

def id
  @id
end

#sortidObject (readonly)

Returns the value of attribute sortid.



47
48
49
# File 'lib/greader/feed.rb', line 47

def sortid
  @sortid
end

#titleObject (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

#urlObject (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 if order is :asc.

Quirks

The results are cached. If you want to purge the cache, use #expire!.

Examples:


@client.feeds[2].entries
@client.feeds[2].entries limit: 10
@client.feeds[2].entries order: :asc, start_time: Time.now-86400

Returns:

  • (Entries)

    The entries it contains.



97
98
99
# File 'lib/greader/feed.rb', line 97

def entries(options={})
  @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

#inspectObject



101
102
103
# File 'lib/greader/feed.rb', line 101

def inspect
  "#<#{self.class.name} \"#{title}\" (#{url})>"
end

#tagsObject



63
64
65
66
67
# File 'lib/greader/feed.rb', line 63

def tags
  @tags ||= begin
    @tags_.map { |tag| @client.tag(tag['id']) }
  end
end

#to_paramObject



69
70
71
# File 'lib/greader/feed.rb', line 69

def to_param
  slug @id
end