Class: CollegiateLink::Response

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

Overview

Container for the XML gunk returned from CollegiateLink

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Response

Create the response.

Parameters:

  • document - The Nokogiri document of the returned XML

Raises:



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

def initialize(document)
  raise UnknownException unless document.xpath('//results/page')

  @document = document
  @page_size   = document.xpath('//results/page/pageSize').inner_html.to_i
  @page_number = document.xpath('//results/page/pageNumber').inner_html.to_i
  @total_items = document.xpath('//results/page/totalItems').inner_html.to_i
  @total_pages = document.xpath('//results/page/totalPages').inner_html.to_i
end

Instance Method Details

#has_next_page?Boolean

Utility method to determine if the request has another page to retrieve.

Returns:

  • (Boolean)


26
27
28
# File 'lib/collegiatelink/response.rb', line 26

def has_next_page?
  @page_number < @total_pages
end

#itemsObject

Extract the items from the response. Returns a Nokogiri NodeSet.



21
22
23
# File 'lib/collegiatelink/response.rb', line 21

def items
  @document.xpath('//results/page/items/*')
end