Class: Exlibris::Aleph::Patron
- Inherits:
-
Rest::Base
- Object
- Rest::Base
- Exlibris::Aleph::Patron
- Defined in:
- lib/exlibris/aleph/patron.rb
Overview
Overview
Provides access to the Aleph Patron REST API.
Instance Attribute Summary collapse
-
#patron_id ⇒ Object
Returns the value of attribute patron_id.
Attributes inherited from Rest::Base
Instance Method Summary collapse
-
#address ⇒ Object
Returns a Hash representing the patron’s address information.
-
#error ⇒ Object
Returns the error associated with the request.
-
#loans ⇒ Object
Returns an Array of institutions.
-
#note ⇒ Object
Returns the note associated with the request.
-
#place_hold(adm_library, bib_library, bib_id, item_id, params) ⇒ Object
Place a hold on the specificed item.
-
#renew_loans(item_id = "") ⇒ Object
Renew the specified item.
Methods inherited from Rest::Base
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
#patron_id ⇒ Object
Returns the value of attribute patron_id.
6 7 8 |
# File 'lib/exlibris/aleph/patron.rb', line 6 def patron_id @patron_id end |
Instance Method Details
#address ⇒ Object
Returns a Hash representing the patron’s address information. Every method call refreshes the data from the underlying API. Raises an exception if the response is not valid XML or there are errors.
23 24 25 26 27 28 29 |
# File 'lib/exlibris/aleph/patron.rb', line 23 def address self.response = self.class.get("#{patron_url}/patronInformation/address") raise_error_if("Error getting patron address through Aleph REST APIs.") { (response.parsed_response["get_pat_adrs"].nil? or response.parsed_response["get_pat_adrs"]["address_information"].nil?) } response.parsed_response["get_pat_adrs"]["address_information"] end |
#error ⇒ Object
Returns the error associated with the request. Returns nil if no error.
63 64 65 66 |
# File 'lib/exlibris/aleph/patron.rb', line 63 def error return nil if reply_code == "0000" return "#{reply_text}#{note}" end |
#loans ⇒ Object
Returns an Array of institutions. Each institution is a Hash containing an array of loans for that institution. Every method call refreshes the data from the underlying API. Raises an exception if the response is not valid XML or there are errors.
35 36 37 38 39 40 41 |
# File 'lib/exlibris/aleph/patron.rb', line 35 def loans self.response = self.class.get("#{patron_url}/circulationActions/loans?view=full") raise_error_if("Error getting loans through Aleph REST APIs.") { (response.parsed_response["pat_loan_list"].nil? or response.parsed_response["pat_loan_list"]["loans"].nil?) } [response.parsed_response["pat_loan_list"]["loans"]["institution"]].flatten end |
#note ⇒ Object
Returns the note associated with the request.
57 58 59 |
# File 'lib/exlibris/aleph/patron.rb', line 57 def note return (not response.first.last.kind_of?(Hash) or response.first.last["create_hold"].nil?) ? "" : ": #{response.first.last["create_hold"]["note"]["__content__"]}" if response.instance_of?(Hash) end |
#place_hold(adm_library, bib_library, bib_id, item_id, params) ⇒ Object
Place a hold on the specificed item. Returns a Hash, including the “note” returned from the underlying API. Raises an exception if the response is not valid XML or there are errors.
11 12 13 14 15 16 17 18 |
# File 'lib/exlibris/aleph/patron.rb', line 11 def place_hold(adm_library, bib_library, bib_id, item_id, params) = { :body => "post_xml=#{place_hold_xml(params)}"} self.response = self.class.put("#{patron_url}/record/#{bib_library}#{bib_id}/items/#{item_id}/hold", ) raise_error_if("Error placing hold through Aleph REST APIs. #{error}") { (response.parsed_response["put_item_hold"].nil? or response.parsed_response["put_item_hold"]["create_hold"].nil?) } response.parsed_response["put_item_hold"]["create_hold"] end |
#renew_loans(item_id = "") ⇒ Object
Renew the specified item. Will renew all if item not specified. Returns an Array of institutions. Each institution is a Hash containing an array of loan renewals for that institution. Raises an exception if the response is not valid XML or there are errors.
48 49 50 51 52 53 54 |
# File 'lib/exlibris/aleph/patron.rb', line 48 def renew_loans(item_id="") self.response = self.class.post("#{patron_url}/circulationActions/loans/#{item_id}") raise_error_if("Error renewing loans through Aleph REST APIs.") { (response.parsed_response["renew_loan"].nil? or response.parsed_response["renew_loan"]["renewals"].nil?) } [response.parsed_response["renew_loan"]["renewals"]["institution"]].flatten end |