class YahooShoppingSearch::Responses::Item

Constants

DEFAULT_RESULTS_COUNT
MAX_RESULTS_COUNT

start + results sum's mixium is 1000

Public Class Methods

new(body, params = {}) click to toggle source

@param body [String] @param params [Hash]

# File lib/yahoo_shopping_search/responses/item.rb, line 13
def initialize(body, params = {})
  @body = JSON.parse(body)
  @params = params
end

Public Instance Methods

client_class() click to toggle source

@return [ClassName]

# File lib/yahoo_shopping_search/responses/item.rb, line 75
def client_class
  ::YahooShoppingSearch::Clients::Item
end
has_next_page?() click to toggle source

@return [Boolean]

# 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
next_page!() click to toggle source

@return [Array<YahooShoppingSearch::Resources::Item>]

# 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() click to toggle source

@return [Hash]

# 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() click to toggle source

@return [ClassName]

# File lib/yahoo_shopping_search/responses/item.rb, line 70
def resource_class
  ::YahooShoppingSearch::Resources::Item
end
results_count() click to toggle source

@return [Integer]

# File lib/yahoo_shopping_search/responses/item.rb, line 42
def results_count
  @body['totalResultsReturned']
end
search_condition() click to toggle source

@return [Hash]

# File lib/yahoo_shopping_search/responses/item.rb, line 52
def search_condition
  params
end
sources() click to toggle source

@return [Array<Hash>]

# File lib/yahoo_shopping_search/responses/item.rb, line 65
def sources
  body['hits']
end
start_position() click to toggle source

@return [Integer]

# File lib/yahoo_shopping_search/responses/item.rb, line 37
def start_position
  @body['firstResultsPosition']
end
total_results_count() click to toggle source

@return [Integer]

# File lib/yahoo_shopping_search/responses/item.rb, line 47
def total_results_count
  @body['totalResultsAvailable']
end