Class: RakutenWebService::SearchResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rakuten_web_service/search_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, resource_class) ⇒ SearchResult

Returns a new instance of SearchResult.



7
8
9
10
11
# File 'lib/rakuten_web_service/search_result.rb', line 7

def initialize(params, resource_class)
  @params = params.dup
  @resource_class = resource_class
  @client = RakutenWebService::Client.new(resource_class)
end

Instance Method Details

#all(&block) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/rakuten_web_service/search_result.rb', line 24

def all(&block)
  proxy = AllProxy.new(self)
  if block
    proxy.each(&block)
  else
    return proxy
  end
end

#eachObject



18
19
20
21
22
# File 'lib/rakuten_web_service/search_result.rb', line 18

def each
  response.each do |resource|
    yield resource
  end
end

#has_next_page?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rakuten_web_service/search_result.rb', line 65

def has_next_page?
  response.has_next_page?
end

#next_pageObject



69
70
71
# File 'lib/rakuten_web_service/search_result.rb', line 69

def next_page
  search(:page => response.page + 1)
end

#order(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rakuten_web_service/search_result.rb', line 37

def order(options)
  new_params = params.dup
  if options.is_a? Hash
    key, sort_order = *(options.to_a.last)
    key = camelize(key.to_s)
    new_params[:sort] = case sort_order.to_s.downcase
                     when 'desc'
                       "-#{key}"
                     when 'asc'
                       "+#{key}"
                     end
  elsif options.to_s == 'standard'
    new_params[:sort] = 'standard' 
  else 
    raise ArgumentError, "Invalid Sort Option: #{options.inspect}"
  end
  self.class.new(new_params, @resource_class)
end

#page(num) ⇒ Object



73
74
75
# File 'lib/rakuten_web_service/search_result.rb', line 73

def page(num)
  search(:page => num)
end

#paramsObject



33
34
35
# File 'lib/rakuten_web_service/search_result.rb', line 33

def params
  @params ||= {}
end

#queryObject Also known as: fetch_result



56
57
58
# File 'lib/rakuten_web_service/search_result.rb', line 56

def query
  ensure_retries { @client.get(params) }
end

#responseObject



61
62
63
# File 'lib/rakuten_web_service/search_result.rb', line 61

def response
  @response ||= query
end

#search(params) ⇒ Object Also known as: with



13
14
15
# File 'lib/rakuten_web_service/search_result.rb', line 13

def search(params)
  SearchResult.new(self.params.dup.merge!(params), @resource_class)
end