Class: Ezid::Response Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ezid/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"
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"
IDENTIFIER_RE =

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.

/^(doi|ark|urn):[^\s]+/
SHADOW_ARK_RE =

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.

/\| (ark:[^\s]+)/

Instance Method Summary collapse

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



45
46
47
# File 'lib/ezid/response.rb', line 45

def content
  @content ||= body.split(/\r?\n/, 2)
end

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.



85
86
87
# File 'lib/ezid/response.rb', line 85

def cookie
  self["Set-Cookie"].split(";").first rescue nil
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)


63
64
65
# File 'lib/ezid/response.rb', line 63

def error?
  outcome == ERROR
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:



75
76
77
# File 'lib/ezid/response.rb', line 75

def exception
  @exception ||= (error? && Error.new(message))
end

#idObject

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.



19
20
21
# File 'lib/ezid/response.rb', line 19

def id
  @id ||= IDENTIFIER_RE.match(message)[0]
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



57
58
59
# File 'lib/ezid/response.rb', line 57

def message
  status.last
end

#metadataObject

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.



27
28
29
# File 'lib/ezid/response.rb', line 27

def 
  content[1]
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



51
52
53
# File 'lib/ezid/response.rb', line 51

def outcome
  status.first
end

#shadow_arkObject

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.



23
24
25
# File 'lib/ezid/response.rb', line 23

def shadow_ark
  @shadow_ark ||= SHADOW_ARK_RE.match(message)[1]
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



33
34
35
# File 'lib/ezid/response.rb', line 33

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



39
40
41
# File 'lib/ezid/response.rb', line 39

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)


69
70
71
# File 'lib/ezid/response.rb', line 69

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



81
82
83
# File 'lib/ezid/response.rb', line 81

def uri_path
  __getobj__.uri.path
end