Class: YahooShoppingSearch::Responses::Item
- Inherits:
-
Base
- Object
- Base
- YahooShoppingSearch::Responses::Item
show all
- Defined in:
- lib/yahoo_shopping_search/responses/item.rb
Constant Summary
collapse
- MAX_RESULTS_COUNT =
start + results sum’s mixium is 1000
1000
- DEFAULT_RESULTS_COUNT =
20
Instance Method Summary
collapse
Methods inherited from Base
#[], #body, #each, #items, #last, #params
Constructor Details
#initialize(body, params = {}) ⇒ Item
Returns a new instance of Item.
13
14
15
16
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 13
def initialize(body, params = {})
@body = JSON.parse(body)
@params = params
end
|
Instance Method Details
#client_class ⇒ ClassName
#has_next_page? ⇒ Boolean
19
20
21
22
23
24
25
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 19
def has_next_page?
if total_results_count >= MAX_RESULTS_COUNT
MAX_RESULTS_COUNT >= start_position + results_count
else
total_results_count - start_position - results_count > 0
end
end
|
28
29
30
31
32
33
34
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 28
def next_page!
raise NextPageNotFound.new('Next page not found') unless has_next_page?
@body = client_class.search(next_search_condition).body
@params = next_search_condition
items
end
|
#next_search_condition ⇒ Hash
57
58
59
60
61
62
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 57
def next_search_condition
condition = search_condition
condition['start'] = start_position + (condition['results'] || DEFAULT_RESULTS_COUNT)
condition
end
|
#resource_class ⇒ ClassName
#results_count ⇒ Integer
42
43
44
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 42
def results_count
@body['totalResultsReturned']
end
|
#search_condition ⇒ Hash
52
53
54
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 52
def search_condition
params
end
|
#sources ⇒ Array<Hash>
65
66
67
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 65
def sources
body['hits']
end
|
#start_position ⇒ Integer
37
38
39
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 37
def start_position
@body['firstResultsPosition']
end
|
#total_results_count ⇒ Integer
47
48
49
|
# File 'lib/yahoo_shopping_search/responses/item.rb', line 47
def total_results_count
@body['totalResultsAvailable']
end
|