Class: BestbuyApi::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/bestbuy_api/response.rb

Constant Summary collapse

PAGE_VARS =
%w[totalPages total currentPage].freeze

Instance Method Summary collapse

Constructor Details

#initialize(result, path) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/bestbuy_api/response.rb', line 5

def initialize(result, path)
  @result = result
  @path = path
end

Instance Method Details

#itemsObject



10
11
12
# File 'lib/bestbuy_api/response.rb', line 10

def items
  @result[@path] if @result.key?(@path)
end

#paginationObject



14
15
16
# File 'lib/bestbuy_api/response.rb', line 14

def pagination
  @result.select { |key| PAGE_VARS.include?(key) }
end

#urlObject



18
19
20
# File 'lib/bestbuy_api/response.rb', line 18

def url
  @result.request.last_uri.to_s
end