Class: OAI::Response

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

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:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oai/client/response.rb', line 6

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.



4
5
6
# File 'lib/oai/client/response.rb', line 4

def doc
  @doc
end

#resumption_tokenObject (readonly)

Returns the value of attribute resumption_token.



4
5
6
# File 'lib/oai/client/response.rb', line 4

def resumption_token
  @resumption_token
end