Class: Google::Reader::Label

Inherits:
Base
  • Object
show all
Defined in:
lib/google/reader/label.rb

Constant Summary collapse

VALID_KEYS =
[:n, :c]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

get_entries, get_token, parse, parse_json, user_info

Constructor Details

#initialize(name, shared = false, count = 0) ⇒ Label

Usage:

Google::Reader::Label.new('friends')
Google::Reader::Label.new('friends', false)
Google::Reader::Label.new('friends', false, 3)


23
24
25
26
27
# File 'lib/google/reader/label.rb', line 23

def initialize(name, shared=false, count=0)
  self.name   = name
  self.shared = shared
  self.count  = count
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



17
18
19
# File 'lib/google/reader/label.rb', line 17

def count
  @count
end

#sharedObject

Returns the value of attribute shared.



16
17
18
# File 'lib/google/reader/label.rb', line 16

def shared
  @shared
end

Class Method Details

.allObject

Usage:

Google::Reader::Label.all


7
8
9
10
11
# File 'lib/google/reader/label.rb', line 7

def all
  parse_json(get(LABELS_URL))['tags'].inject([]) do |labels, l|
    labels << new(l['id'], l['shared'])
  end
end

Instance Method Details

#entries(which = nil, o = {}) ⇒ Object

Usage:

Google::Reader::Label.new('friends').entries
Google::Reader::Label.new('friends').entries(:all, :n => 25)
Google::Reader::Label.new('friends').entries(:unread)
Google::Reader::Label.new('friends').entries(:unread, :n => 25)

To use with continuations:

unread      = Google::Reader::Label.new('friends').entries(:unread)
next_unread = Google::Reader::Label.new('friends').entries(:unread, :c => unread.continuation)

The examples above would grab the first 15 unread entries and then using google reader’s continuations, the next 15 unread after the first 15.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/google/reader/label.rb', line 59

def entries(which=nil, o={})
  options = {:n => 15,}.merge(o)
  query_str = valid_keys_to_query_string(o)
  url = case which.to_s
  when 'unread'
    sprintf(LABEL_URL, @name) + "?xt=#{State::READ}&#{query_str}"
  else
    sprintf(LABEL_URL, @name)
  end
  self.class.get_entries(url, :continuation => true)
end

#nameObject

Returns name; converts broadcast label to shared to be consistent with google



35
36
37
# File 'lib/google/reader/label.rb', line 35

def name
  @name == 'broadcast' ? 'shared' : @name
end

#name=(new_name) ⇒ Object

Converts user/user-id/label/security to security.



30
31
32
# File 'lib/google/reader/label.rb', line 30

def name=(new_name)
  @name = new_name.split('/').last
end