Class: Google::Reader::Search

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

get_entries, get_token, parse, parse_json, user_info

Constructor Details

#initialize(q) ⇒ Search

Returns a new instance of Search.



9
10
11
12
# File 'lib/google/reader/search.rb', line 9

def initialize(q)
  self.q = q
  @executed = false
end

Instance Attribute Details

#idsObject

:nodoc:



7
8
9
# File 'lib/google/reader/search.rb', line 7

def ids
  @ids
end

#qObject

:nodoc:



7
8
9
# File 'lib/google/reader/search.rb', line 7

def q
  @q
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
# File 'lib/google/reader/search.rb', line 14

def execute
  response = self.class.get(SEARCH_IDS_URL, :query_hash => {
    :num => 1000, 
    :output => 'json', 
    :q => q
  })
  self.ids = self.class.parse_json(response)['results'].collect { |r| r['id'] }
  @executed = true
end

#results(o = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/google/reader/search.rb', line 24

def results(o={})
  options = {
    :token => nil,
    :start => 0,
    :num   => 20,
  }.merge(o)
  
  options[:token] ||= self.class.get_token
  
  if ids.size > 0
    i_str = ids[options[:start]] + '&'
    i_str += ids[(options[:start]+1)..options[:num]].collect { |id| ["i=#{id}&"] unless id.nil? }.join('')
    
    self.class.post(SEARCH_CONTENTS_URL, :form_data => {
      :T => options[:token],
      :i => i_str,
    })
  end
end