Class: Greedy::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/greedy/stream.rb

Constant Summary collapse

BASE_PATH =
"stream/contents/"
CHANGE_STATE_PATH =
"user/-/state/com.google/edit-tag"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, in_state = nil, in_options = {}) ⇒ Stream

Instantiate a new Google Reader stream of entries based on a given entry state



9
10
11
12
# File 'lib/greedy/stream.rb', line 9

def initialize(username, password, in_state = nil, in_options = {})
  @connection = Greedy::Connection.new(username, password, in_options[:connection_name] || "Greedy::Stream")
  reset!(in_state, in_options)
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



6
7
8
# File 'lib/greedy/stream.rb', line 6

def entries
  @entries
end

#feedsObject

Returns the value of attribute feeds.



6
7
8
# File 'lib/greedy/stream.rb', line 6

def feeds
  @feeds
end

#last_update_tokenObject

Returns the value of attribute last_update_token.



6
7
8
# File 'lib/greedy/stream.rb', line 6

def last_update_token
  @last_update_token
end

Instance Method Details

#change_state_for(entry, state) ⇒ Object



37
38
39
40
41
# File 'lib/greedy/stream.rb', line 37

def change_state_for(entry, state)
  @connection.post((BASE_PATH + CHANGE_STATE_PATH), { :a => state,
                                                      :i => entry.google_item_id,
                                                      :s => entry.feed.google_feed_id })
end

#continue!Object

Continue fetching earlier entries from where the last request left off



23
24
25
26
27
28
# File 'lib/greedy/stream.rb', line 23

def continue!
  return [] unless @continuation_token
  new_entries = pull!(endpoint(@state), @options.merge(:c => @continuation_token))
  @entries.concat new_entries
  new_entries
end

#mark_all_as_read!Object



47
48
49
# File 'lib/greedy/stream.rb', line 47

def mark_all_as_read!
  @entries.each { |e| e.mark_as_read! }
end

#reset!(in_state = nil, in_options = {}) ⇒ Object

Wipe the stream and reinitialize with the given state



15
16
17
18
19
20
# File 'lib/greedy/stream.rb', line 15

def reset!(in_state = nil, in_options = {})
  @state = in_state || @state || Greedy::Entry::States::READING_LIST
  @options = in_options
  @entries = pull!(endpoint(@state), @options)
  @feeds = distill_feeds_from @entries
end

#share_all!Object



43
44
45
# File 'lib/greedy/stream.rb', line 43

def share_all!
  @entries.each { |e| e.share! }
end

#update!Object

Continue fetching later entries from where the last request left off



31
32
33
34
35
# File 'lib/greedy/stream.rb', line 31

def update!
  new_entries = pull!(endpoint(@state), @options.merge(:ot => @last_update_token))
  @entries = new_entries + @entries
  new_entries
end