Class: OAI::Response

Inherits:
Object
  • Object
show all
Includes:
XPath
Defined in:
lib/oai/client/response.rb

Overview

An OAI::Response contains entries and a resumption token. If a resumption token is present, then you must use it to fetch the rest of the entries for your query. For example:

# List all records
i = 1
begin 
  response = client.list_records
  while response.entries.size > 0    
    response.entries.each { |entry|
      puts "<b>#{i}</b> #{entry.header.identifier}<br/>"
      i +=1
    }
    token = response.resumption_token
    response = client.list_records :resumption_token => token if token
  end
rescue OAI::Exception => e
  puts 'No records to process'
end
puts "Done processing #{i} records"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XPath

#get_attribute, #xpath, #xpath_all, #xpath_first

Constructor Details

#initialize(doc) ⇒ Response

Returns a new instance of Response.

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/oai/client/response.rb', line 26

def initialize(doc)
  @doc = doc
  @resumption_token = xpath(doc, './/resumptionToken')

  # throw an exception if there was an error
  error = xpath_first(doc, './/error')
  return unless error

  case error.class.to_s
    when 'REXML::Element'
      message = error.text
      code = error.attributes['code']
    when 'LibXML::XML::Node'
      message = error.content
      code = ""
      if defined?(error.property) == nil
          code = error.attributes['code']
       else
   begin
	 	code = error["code"]
   rescue
            code = error.property('code')
   end
       end
  end
  raise OAI::Exception.new(message, code)
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



24
25
26
# File 'lib/oai/client/response.rb', line 24

def doc
  @doc
end

#resumption_tokenObject (readonly)

Returns the value of attribute resumption_token.



24
25
26
# File 'lib/oai/client/response.rb', line 24

def resumption_token
  @resumption_token
end