Class: Ezid::Response Private
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ezid::Response
- Defined in:
- lib/ezid/responses/response.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A response from the EZID service.
Direct Known Subclasses
BatchDownloadResponse, IdentifierResponse, LoginResponse, LogoutResponse, ServerStatusResponse
Constant Summary collapse
- SUCCESS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Success response status
"success".freeze
- ERROR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Error response status
"error".freeze
Instance Method Summary collapse
-
#content ⇒ Array
private
The body of the response split into: status line and rest of body.
-
#error? ⇒ Boolean
private
Whether the outcome was an error.
- #error_class ⇒ Object private
-
#exception ⇒ Ezid::Error
private
Returns an exception instance if there was an error.
-
#initialize(http_response) ⇒ Response
constructor
private
A new instance of Response.
-
#message ⇒ String
private
The EZID status message.
-
#outcome ⇒ String
private
The outcome of the request - “success” or “error”.
-
#status ⇒ String
private
The response status – “success” or “error”.
-
#status_line ⇒ String
private
The status line of the response.
-
#success? ⇒ Boolean
private
Whether the outcome was a success.
-
#uri_path ⇒ String
private
The URI path of the request.
Constructor Details
#initialize(http_response) ⇒ Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Response.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ezid/responses/response.rb', line 17 def initialize(http_response) super unless __getobj__.code =~ /2\d\d/ raise Error, "HTTP response error: %s %s" % [ __getobj__.code, __getobj__. ] end unless status_line =~ /^(#{SUCCESS}|#{ERROR}): / raise UnexpectedResponseError, __getobj__.body end end |
Instance Method Details
#content ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The body of the response split into: status line and rest of body
44 45 46 |
# File 'lib/ezid/responses/response.rb', line 44 def content @content ||= body.split(/\r?\n/, 2) end |
#error? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the outcome was an error
62 63 64 |
# File 'lib/ezid/responses/response.rb', line 62 def error? outcome == ERROR end |
#error_class ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ezid/responses/response.rb', line 84 def error_class case when /no such identifier/ IdentifierNotFoundError when /identifier status does not support deletion/ DeletionError else Error end end |
#exception ⇒ Ezid::Error
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an exception instance if there was an error
74 75 76 |
# File 'lib/ezid/responses/response.rb', line 74 def exception error_class.new() if error? end |
#message ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The EZID status message
56 57 58 |
# File 'lib/ezid/responses/response.rb', line 56 def status.last end |
#outcome ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The outcome of the request - “success” or “error”
50 51 52 |
# File 'lib/ezid/responses/response.rb', line 50 def outcome status.first end |
#status ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The response status – “success” or “error”
32 33 34 |
# File 'lib/ezid/responses/response.rb', line 32 def status @status ||= status_line.split(/: /) end |
#status_line ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The status line of the response
38 39 40 |
# File 'lib/ezid/responses/response.rb', line 38 def status_line content[0] end |
#success? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the outcome was a success
68 69 70 |
# File 'lib/ezid/responses/response.rb', line 68 def success? outcome == SUCCESS end |
#uri_path ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The URI path of the request
80 81 82 |
# File 'lib/ezid/responses/response.rb', line 80 def uri_path __getobj__.uri.path end |