Class: Ezid::Response Private

Inherits:
SimpleDelegator
  • Object
show all
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.

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

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
# File 'lib/ezid/responses/response.rb', line 17

def initialize(http_response)
  http_response.value # raises Net::HTTPServerException

  super

  unless status_line =~ /^(#{SUCCESS}|#{ERROR}): /
    raise UnexpectedResponseError, __getobj__.body
  end
end

Instance Method Details

#contentArray

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

Returns:

  • (Array)

    status line, rest of body



41
42
43
# File 'lib/ezid/responses/response.rb', line 41

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

Returns:

  • (Boolean)


59
60
61
# File 'lib/ezid/responses/response.rb', line 59

def error?
  outcome == ERROR
end

#error_classObject

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.



81
82
83
84
85
86
87
88
89
90
# File 'lib/ezid/responses/response.rb', line 81

def error_class
  case message
  when /no such identifier/
    IdentifierNotFoundError
  when /identifier status does not support deletion/
    DeletionError
  else
    Error
  end
end

#exceptionEzid::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

Returns:



71
72
73
# File 'lib/ezid/responses/response.rb', line 71

def exception
  error_class.new(message) if error?
end

#messageString

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

Returns:

  • (String)

    the message



53
54
55
# File 'lib/ezid/responses/response.rb', line 53

def message
  status.last
end

#outcomeString

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”

Returns:

  • (String)

    the outcome



47
48
49
# File 'lib/ezid/responses/response.rb', line 47

def outcome
  status.first
end

#statusString

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”

Returns:

  • (String)

    the status



29
30
31
# File 'lib/ezid/responses/response.rb', line 29

def status
  @status ||= status_line.split(/: /)
end

#status_lineString

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

Returns:

  • (String)

    the status line



35
36
37
# File 'lib/ezid/responses/response.rb', line 35

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

Returns:

  • (Boolean)


65
66
67
# File 'lib/ezid/responses/response.rb', line 65

def success?
  outcome == SUCCESS
end

#uri_pathString

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

Returns:

  • (String)

    the path



77
78
79
# File 'lib/ezid/responses/response.rb', line 77

def uri_path
  __getobj__.uri.path
end