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:

“‘ruby

# List all records in a given set
client = OAI::Client.new 'http://my-oai-provider.example.com/oai'
response = client.list_records :set => 'my_set_name'
while response.entries.count > 0
  response.entries.each { |entry|
    puts entry.header.identifier
  }
  token = response.resumption_token
  # Note: You do not need to pass the options hash again, just the verb and the resumption token
  response = client.list_records :resumption_token => token if token
end

“‘

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XPath

#get_attribute, #xpath, #xpath_all, #xpath_first

Constructor Details

#initialize(doc, &resumption_block) ⇒ Response

Returns a new instance of Response.



23
24
25
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
# File 'lib/oai/client/response.rb', line 23

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

  # 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.for(message: message, code: code)
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



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

def doc
  @doc
end

#resumption_blockObject (readonly)

Returns the value of attribute resumption_block.



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

def resumption_block
  @resumption_block
end

#resumption_tokenObject (readonly)

Returns the value of attribute resumption_token.



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

def resumption_token
  @resumption_token
end