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
- #genre_information ⇒ 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.
8 9 10 11 12 |
# File 'lib/rakuten_web_service/search_result.rb', line 8 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
25 26 27 28 29 30 31 32 |
# File 'lib/rakuten_web_service/search_result.rb', line 25 def all(&block) proxy = AllProxy.new(self) if block proxy.each(&block) else return proxy end end |
#each ⇒ Object
19 20 21 22 23 |
# File 'lib/rakuten_web_service/search_result.rb', line 19 def each response.each do |resource| yield resource end end |
#genre_information ⇒ Object
78 79 80 |
# File 'lib/rakuten_web_service/search_result.rb', line 78 def genre_information response.genre_information end |
#has_next_page? ⇒ Boolean
66 67 68 |
# File 'lib/rakuten_web_service/search_result.rb', line 66 def has_next_page? response.has_next_page? end |
#next_page ⇒ Object
70 71 72 |
# File 'lib/rakuten_web_service/search_result.rb', line 70 def next_page search(:page => response.page + 1) end |
#order(options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rakuten_web_service/search_result.rb', line 38 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
74 75 76 |
# File 'lib/rakuten_web_service/search_result.rb', line 74 def page(num) search(:page => num) end |
#params ⇒ Object
34 35 36 |
# File 'lib/rakuten_web_service/search_result.rb', line 34 def params @params ||= {} end |
#query ⇒ Object Also known as: fetch_result
57 58 59 |
# File 'lib/rakuten_web_service/search_result.rb', line 57 def query ensure_retries { @client.get(params) } end |
#response ⇒ Object
62 63 64 |
# File 'lib/rakuten_web_service/search_result.rb', line 62 def response @response ||= query end |
#search(params) ⇒ Object Also known as: with
14 15 16 |
# File 'lib/rakuten_web_service/search_result.rb', line 14 def search(params) SearchResult.new(self.params.dup.merge!(params), @resource_class) end |