Class: RakutenWebService::SearchResult
- Inherits:
-
Object
- Object
- RakutenWebService::SearchResult
- Includes:
- Enumerable
- Defined in:
- lib/rakuten_web_service/search_result.rb
Instance Method Summary collapse
- #all(&block) ⇒ Object
- #each ⇒ Object
- #has_next_page? ⇒ Boolean
-
#initialize(params, resource_class) ⇒ SearchResult
constructor
A new instance of SearchResult.
- #next_page ⇒ Object
- #order(options) ⇒ Object
- #page(num) ⇒ Object
- #params ⇒ Object
- #query ⇒ Object (also: #fetch_result)
- #response ⇒ Object
- #search(params) ⇒ Object (also: #with)
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 |
#each ⇒ Object
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
65 66 67 |
# File 'lib/rakuten_web_service/search_result.rb', line 65 def has_next_page? response.has_next_page? end |
#next_page ⇒ Object
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() new_params = params.dup if .is_a? Hash key, sort_order = *(.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 .to_s == 'standard' new_params[:sort] = 'standard' else raise ArgumentError, "Invalid Sort Option: #{.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 |
#params ⇒ Object
33 34 35 |
# File 'lib/rakuten_web_service/search_result.rb', line 33 def params @params ||= {} end |
#query ⇒ Object 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 |
#response ⇒ Object
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 |