Class: Exlibris::Aleph::Rest
- Inherits:
-
Object
- Object
- Exlibris::Aleph::Rest
- Includes:
- HTTParty
- Defined in:
- lib/exlibris/aleph/rest.rb
Overview
Overview
Base implementation for Aleph REST APIs.
Not intended for use on its own, but should instead be extended by implementing classes.
Instance Method Summary collapse
-
#error ⇒ Object
Returns the error associated with the request.
-
#initialize(uri) ⇒ Rest
constructor
Create and instance of Exlibris::Aleph::Rest for the given Aleph URI.
-
#reply_code ⇒ Object
Returns the reply code associate with the request.
-
#reply_text ⇒ Object
Returns the reply text associate with the request.
Constructor Details
#initialize(uri) ⇒ Rest
Create and instance of Exlibris::Aleph::Rest for the given Aleph URI.
12 13 14 15 |
# File 'lib/exlibris/aleph/rest.rb', line 12 def initialize(uri) @uri = uri raise "Initialization error in #{self.class}. Missing URI." if @uri.nil? end |
Instance Method Details
#error ⇒ Object
Returns the error associated with the request. Returns nil if no error.
19 20 21 22 |
# File 'lib/exlibris/aleph/rest.rb', line 19 def error return nil if reply_code == "0000" return "#{reply_text}" end |
#reply_code ⇒ Object
Returns the reply code associate with the request.
25 26 27 28 29 30 31 |
# File 'lib/exlibris/aleph/rest.rb', line 25 def reply_code return "No response." if @response.nil? return (not @response.first.last.kind_of?(Hash) or @response.first.last["reply_code"].nil?) ? "Unexpected response hash." : @response.first.last["reply_code"] if @response.instance_of?(Hash) response_match = @response.match(/\<reply-code\>(.+)\<\/reply-code\>/) if @response.instance_of?(String) return (response_match.nil?) ? "Unexpected response string." : response_match[1] if @response.instance_of?(String) return "Unexpected response type." end |
#reply_text ⇒ Object
Returns the reply text associate with the request.
34 35 36 37 38 39 40 |
# File 'lib/exlibris/aleph/rest.rb', line 34 def reply_text return "No response." if @response.nil? return (not @response.first.last.kind_of?(Hash) or @response.first.last["reply_text"].nil?) ? "Unexpected response hash." : @response.first.last["reply_text"] if @response.instance_of?(Hash) response_match = @response.match(/\<reply-text\>(.+)\<\/reply-text\>/) if @response.instance_of?(String) return (response_match.nil?) ? "Unexpected response string." : response_match[1] if @response.instance_of?(String) return "Unexpected response type." end |