Class: Alma::Response
- Inherits:
-
Object
- Object
- Alma::Response
- Extended by:
- Forwardable
- Defined in:
- lib/alma/response.rb
Defined Under Namespace
Classes: StandardError
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#errors ⇒ Object
Returns an array of errors.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #loggable ⇒ Object
- #managed_by_library ⇒ Object
- #managed_by_library_code ⇒ Object
- #request_id ⇒ Object
- #validate(response) ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
15 16 17 18 19 |
# File 'lib/alma/response.rb', line 15 def initialize(response) @raw_response = response @response = response.parsed_response validate(response) end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
12 13 14 |
# File 'lib/alma/response.rb', line 12 def raw_response @raw_response end |
Instance Method Details
#errors ⇒ Object
Returns an array of errors
53 54 55 |
# File 'lib/alma/response.rb', line 53 def errors @response&.dig("errorList", "error") || [] end |
#loggable ⇒ Object
21 22 23 24 |
# File 'lib/alma/response.rb', line 21 def loggable { uri: @raw_response&.request&.uri.to_s }.select { |k, v| !(v.nil? || v.empty?) } end |
#managed_by_library ⇒ Object
44 45 46 |
# File 'lib/alma/response.rb', line 44 def managed_by_library @response.fetch("managed_by_library", "") end |
#managed_by_library_code ⇒ Object
48 49 50 |
# File 'lib/alma/response.rb', line 48 def managed_by_library_code @response.fetch("managed_by_library_code", "") end |
#request_id ⇒ Object
40 41 42 |
# File 'lib/alma/response.rb', line 40 def request_id @response.fetch("request_id", "") end |
#validate(response) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/alma/response.rb', line 26 def validate(response) if errors.first&.dig("errorCode") == "401136" = "The requested item already exists." log = loggable.merge(response.parsed_response) raise Alma::BibRequest::ItemAlreadyExists.new(, log) end if response.code != 200 log = loggable.merge(response.parsed_response) raise StandardError.new("Invalid Response.", log) end end |