Class: ApiBucket::Yahooauction::Response

Inherits:
Base::Response show all
Defined in:
lib/api_bucket/yahooauction/response.rb

Instance Attribute Summary

Attributes inherited from Base::Response

#count, #page

Instance Method Summary collapse

Methods inherited from Base::Response

#doc, #dump

Constructor Details

#initialize(xml) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/api_bucket/yahooauction/response.rb', line 6

def initialize(xml)
  @doc = xml
end

Instance Method Details

#first_itemObject



20
21
22
# File 'lib/api_bucket/yahooauction/response.rb', line 20

def first_item
  @items[0]
end

#item_pageObject

Return current page no if :item_page option is when initiating the request.



25
26
27
# File 'lib/api_bucket/yahooauction/response.rb', line 25

def item_page
  @item_page ||= @doc[:page].to_i
end

#itemsObject



10
11
12
13
14
15
16
17
18
# File 'lib/api_bucket/yahooauction/response.rb', line 10

def items
  return [] if @doc.nil?

  if @doc['ResultSet']['Result']['Item']
    @items ||= @doc['ResultSet']['Result']['Item'].map {|item| ApiBucket::Yahooauction::Item.new(item) }
  else
    @items = [ApiBucket::Yahooauction::Item.new(@doc['ResultSet']['Result'])]
  end
end

#total_pagesObject

Return total pages.



35
36
37
# File 'lib/api_bucket/yahooauction/response.rb', line 35

def total_pages
  @total_pages ||= @doc[:totalResultsAvailable].to_i / @doc[:totalResultsAvailable]
end

#total_resultsObject

Return total results.



30
31
32
# File 'lib/api_bucket/yahooauction/response.rb', line 30

def total_results
  @total_results ||= @doc[:totalResultsReturned].to_i
end