Class: Fieldhand::ResponseParser
- Inherits:
-
Object
- Object
- Fieldhand::ResponseParser
- Defined in:
- lib/fieldhand/response_parser.rb
Overview
A parser for elements common to all OAI-PMH HTTP responses.
See www.openarchives.org/OAI/openarchivesprotocol.html#HTTPResponseFormat
Constant Summary collapse
- ERROR_CODES =
{ 'badArgument' => BadArgumentError, 'badResumptionToken' => BadResumptionTokenError, 'badVerb' => BadVerbError, 'cannotDisseminateFormat' => CannotDisseminateFormatError, 'idDoesNotExist' => IdDoesNotExistError, 'noRecordsMatch' => NoRecordsMatchError, 'noMetadataFormats' => NoMetadataFormatsError, 'noSetHierarchy' => NoSetHierarchyError }.freeze
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#errors ⇒ Object
Return any errors found in the response as ‘ProtocolError`s.
-
#initialize(response) ⇒ ResponseParser
constructor
Return a new parser for the given response body.
-
#response_date ⇒ Object
Return the response date as a ‘Date` or `Time` depending on the granularity of the repository.
-
#resumption_token ⇒ Object
Return the resumption token from the response, if present.
-
#root ⇒ Object
Return the root element of the parsed document.
Constructor Details
#initialize(response) ⇒ ResponseParser
Return a new parser for the given response body.
35 36 37 |
# File 'lib/fieldhand/response_parser.rb', line 35 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
32 33 34 |
# File 'lib/fieldhand/response_parser.rb', line 32 def response @response end |
Instance Method Details
#errors ⇒ Object
Return any errors found in the response as ‘ProtocolError`s.
Note that this does not raise the errors but simply returns them.
47 48 49 |
# File 'lib/fieldhand/response_parser.rb', line 47 def errors @errors ||= root.locate('error').map { |error| convert_error(error) } end |
#response_date ⇒ Object
Return the response date as a ‘Date` or `Time` depending on the granularity of the repository.
40 41 42 |
# 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 ⇒ Object
Return the resumption token from the response, if present.
52 53 54 |
# File 'lib/fieldhand/response_parser.rb', line 52 def resumption_token @resumption_token ||= root.locate('?/resumptionToken[0]/^String').first end |