Class: Exlibris::Aleph::Record
- Inherits:
-
Exlibris::Aleph::Rest::Base
- Object
- Exlibris::Aleph::Rest::Base
- Exlibris::Aleph::Record
- Defined in:
- lib/exlibris/aleph/record.rb
Overview
Overview
Provides access to the Aleph Record REST API.
Instance Attribute Summary collapse
-
#bib_library ⇒ Object
Returns the value of attribute bib_library.
-
#record_id ⇒ Object
Returns the value of attribute record_id.
Attributes inherited from Exlibris::Aleph::Rest::Base
Instance Method Summary collapse
-
#bib ⇒ Object
Returns a MARC::Record that contains the bib data Every method call refreshes the data from the underlying API.
-
#holdings ⇒ Object
Returns an array of holdings.
-
#initialize(*args) ⇒ Record
constructor
A new instance of Record.
-
#items ⇒ Object
Returns an array of items.
Methods inherited from Exlibris::Aleph::Rest::Base
#error, #reply_code, #reply_text
Methods included from WriteAttributes
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
Constructor Details
#initialize(*args) ⇒ Record
Returns a new instance of Record.
9 10 11 |
# File 'lib/exlibris/aleph/record.rb', line 9 def initialize(*args) super end |
Instance Attribute Details
#bib_library ⇒ Object
Returns the value of attribute bib_library.
7 8 9 |
# File 'lib/exlibris/aleph/record.rb', line 7 def bib_library @bib_library end |
#record_id ⇒ Object
Returns the value of attribute record_id.
7 8 9 |
# File 'lib/exlibris/aleph/record.rb', line 7 def record_id @record_id end |
Instance Method Details
#bib ⇒ Object
Returns a MARC::Record that contains the bib data Every method call refreshes the data from the underlying API. Raises an exception if the response is not valid XML or there are errors.
16 17 18 19 20 21 22 |
# File 'lib/exlibris/aleph/record.rb', line 16 def bib self.response = self.class.get("#{record_url}?view=full") raise_error_if("Error getting bib from Aleph REST APIs.") { (response.parsed_response["get_record"].nil? or response.parsed_response["get_record"]["record"].nil?) } MARC::XMLReader.new(StringIO.new(xml(xml: response.body).at_xpath("get-record/record").to_xml().strip)).first end |
#holdings ⇒ Object
Returns an array of holdings. Each holding is represented as a MARC::Record. Every method call refreshes the data from the underlying API. Raises an exception if there are errors.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/exlibris/aleph/record.rb', line 40 def holdings self.response = self.class.get("#{record_url}/holdings?view=full") raise_error_if("Error getting holdings from Aleph REST APIs.") { (response.parsed_response["get_hol_list"].nil? or response.parsed_response["get_hol_list"]["holdings"].nil?) } xml(xml: response.body).xpath("get-hol-list/holdings/holding").collect{ |holding| # Change the tag name to record so that the MARC::XMLReader can parse it. holding.name = "record" MARC::XMLReader.new(StringIO.new(holding.to_xml().strip)).first } end |
#items ⇒ Object
Returns an array of items. Each item is represented as a Hash. Every method call refreshes the data from the underlying API. Raises an exception if the response is not valid XML or there are errors.
27 28 29 30 31 32 33 34 35 |
# File 'lib/exlibris/aleph/record.rb', line 27 def items # Since we're parsing xml, this will raise an error # if the response isn't xml. self.response = self.class.get("#{record_url}/items?view=full") raise_error_if("Error getting items from Aleph REST APIs.") { (response.parsed_response["get_item_list"].nil? or response.parsed_response["get_item_list"]["items"].nil?) } [response.parsed_response["get_item_list"]["items"]["item"]].flatten end |