class Ezid::Response
A response from the EZID service.
@api private
Constants
- ERROR
Error
response status- SUCCESS
Success response status
Public Class Methods
new(http_response)
click to toggle source
Calls superclass method
# File lib/ezid/responses/response.rb, line 17 def initialize(http_response) super unless status_line =~ /^(#{SUCCESS}|#{ERROR}): / raise UnexpectedResponseError, __getobj__.body end end
Public Instance Methods
content()
click to toggle source
The body of the response split into: status line and rest of body @return [Array] status line, rest of body
# File lib/ezid/responses/response.rb, line 39 def content @content ||= body.split(/\r?\n/, 2) end
error?()
click to toggle source
Whether the outcome was an error @return [Boolean]
# File lib/ezid/responses/response.rb, line 57 def error? outcome == ERROR end
error_class()
click to toggle source
# File lib/ezid/responses/response.rb, line 79 def error_class case message when /no such identifier/ IdentifierNotFoundError when /identifier status does not support deletion/ DeletionError else Error end end
exception()
click to toggle source
Returns an exception instance if there was an error @return [Ezid::Error] the exception
# File lib/ezid/responses/response.rb, line 69 def exception error_class.new(message) if error? end
message()
click to toggle source
The EZID status message @return [String] the message
# File lib/ezid/responses/response.rb, line 51 def message status.last end
outcome()
click to toggle source
The outcome of the request - “success” or “error” @return [String] the outcome
# File lib/ezid/responses/response.rb, line 45 def outcome status.first end
status()
click to toggle source
The response status – “success” or “error” @return [String] the status
# File lib/ezid/responses/response.rb, line 27 def status @status ||= status_line.split(/: /) end
status_line()
click to toggle source
The status line of the response @return [String] the status line
# File lib/ezid/responses/response.rb, line 33 def status_line content[0] end
success?()
click to toggle source
Whether the outcome was a success @return [Boolean]
# File lib/ezid/responses/response.rb, line 63 def success? outcome == SUCCESS end
uri_path()
click to toggle source
The URI path of the request @return [String] the path
# File lib/ezid/responses/response.rb, line 75 def uri_path __getobj__.uri.path end