Class: Exlibris::Aleph::Patron

Inherits:
Rest::Base show all
Defined in:
lib/exlibris/aleph/patron.rb

Overview

Overview

Provides access to the Aleph Patron REST API.

Instance Attribute Summary collapse

Attributes inherited from Rest::Base

#response, #rest_url

Instance Method Summary collapse

Methods inherited from Rest::Base

#reply_code, #reply_text

Methods included from WriteAttributes

#initialize, #write_attributes

Methods included from XmlUtil

included, #to_xml

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

included, #initialize

Instance Attribute Details

#patron_idObject

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

#addressObject

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

#errorObject

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

#loansObject

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

#noteObject

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)
  options = { :body => "post_xml=#{place_hold_xml(params)}"}
  self.response = self.class.put("#{patron_url}/record/#{bib_library}#{bib_id}/items/#{item_id}/hold", options)
  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