class Fieldhand::ResponseParser
A parser for elements common to all OAI-PMH HTTP responses.
See www.openarchives.org/OAI/openarchivesprotocol.html#HTTPResponseFormat
Constants
- ERROR_CODES
Attributes
response[R]
Public Class Methods
new(response)
click to toggle source
Return a new parser for the given response body.
# File lib/fieldhand/response_parser.rb, line 35 def initialize(response) @response = response end
Public Instance Methods
errors()
click to toggle source
Return any errors found in the response as `ProtocolError`s.
Note that this does not raise the errors but simply returns them.
# File lib/fieldhand/response_parser.rb, line 47 def errors @errors ||= root.locate('error').map { |error| convert_error(error) } end
response_date()
click to toggle source
Return the response date as a `Date` or `Time` depending on the granularity of the repository.
# File lib/fieldhand/response_parser.rb, line 40 def response_date @response_date ||= root.locate('responseDate[0]/^String').map { |date| Datestamp.parse(date) }.first end
resumption_token()
click to toggle source
Return the resumption token from the response, if present.
# File lib/fieldhand/response_parser.rb, line 52 def resumption_token @resumption_token ||= root.locate('?/resumptionToken[0]/^String').first end
root()
click to toggle source
Return the root element of the parsed document.
# File lib/fieldhand/response_parser.rb, line 57 def root @root ||= ::Ox.load(response, :strip_namespace => 'oai').root end
Private Instance Methods
convert_error(element)
click to toggle source
# File lib/fieldhand/response_parser.rb, line 63 def convert_error(element) return unless ERROR_CODES.key?(element['code']) ERROR_CODES.fetch(element['code']).new(element.text) end