Class: Exlibris::Aleph::Rest::Base
- Inherits:
-
Object
- Object
- Exlibris::Aleph::Rest::Base
- Includes:
- Abstract, Config::Attributes, WriteAttributes, XmlUtil, HTTParty
- Defined in:
- lib/exlibris/aleph/rest/base.rb
Overview
Overview
Base implementation for Aleph REST APIs.
Not intended for use on its own, but should instead be extended by implementing classes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#rest_url ⇒ Object
writeonly
Sets the attribute rest_url.
Instance Method Summary collapse
-
#error ⇒ Object
Returns the error associated with the request.
-
#reply_code ⇒ Object
Returns the reply code associate with the request.
-
#reply_text ⇒ Object
Returns the reply text associate with the request.
Methods included from WriteAttributes
#initialize, #write_attributes
Methods included from XmlUtil
Methods included from Config::Attributes
#adms, #base_url, #config, #irrelevant_sub_libraries, #logger, #refresh_time, #rest_url, #tab_path, #yml_path
Methods included from Abstract
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
19 20 21 |
# File 'lib/exlibris/aleph/rest/base.rb', line 19 def response @response end |
#rest_url=(value) ⇒ Object (writeonly)
Sets the attribute rest_url
18 19 20 |
# File 'lib/exlibris/aleph/rest/base.rb', line 18 def rest_url=(value) @rest_url = value end |
Instance Method Details
#error ⇒ Object
Returns the error associated with the request. Returns nil if no error.
24 25 26 27 |
# File 'lib/exlibris/aleph/rest/base.rb', line 24 def error return nil if reply_code == "0000" return "#{reply_text}" end |
#reply_code ⇒ Object
Returns the reply code associate with the request.
30 31 32 33 34 35 36 |
# File 'lib/exlibris/aleph/rest/base.rb', line 30 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.
39 40 41 42 43 44 45 |
# File 'lib/exlibris/aleph/rest/base.rb', line 39 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 |