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.
33 34 35 |
# File 'lib/fieldhand/response_parser.rb', line 33 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
30 31 32 |
# File 'lib/fieldhand/response_parser.rb', line 30 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.
45 46 47 |
# File 'lib/fieldhand/response_parser.rb', line 45 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.
38 39 40 |
# File 'lib/fieldhand/response_parser.rb', line 38 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.
50 51 52 |
# File 'lib/fieldhand/response_parser.rb', line 50 def resumption_token @resumption_token ||= root.locate('?/resumptionToken[0]/^String').first end |