Class: OAI::Response
- Inherits:
-
Object
- Object
- OAI::Response
- 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
“‘
Direct Known Subclasses
GetRecordResponse, IdentifyResponse, ListIdentifiersResponse, ListMetadataFormatsResponse, ListRecordsResponse, ListSetsResponse
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#resumption_block ⇒ Object
readonly
Returns the value of attribute resumption_block.
-
#resumption_token ⇒ Object
readonly
Returns the value of attribute resumption_token.
Instance Method Summary collapse
-
#initialize(doc, &resumption_block) ⇒ Response
constructor
A new instance of Response.
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' = error.text code = error.attributes['code'] when 'LibXML::XML::Node' = 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(, code) end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
21 22 23 |
# File 'lib/oai/client/response.rb', line 21 def doc @doc end |
#resumption_block ⇒ Object (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_token ⇒ Object (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 |