class Authpds::Exlibris::Pds::GetAttribute

Makes a call to the PDS get-attribute API. Defaults attribute equal to “bor_info”. Raises an exception on if it encounters errors.

Attributes

error[R]
response[R]

Public Class Methods

new(pds_url, calling_system, pds_handle, attribute) click to toggle source

Call to the PDS API.

# File lib/authpds/exlibris/pds.rb, line 17
def initialize(pds_url, calling_system, pds_handle, attribute)
  raise ArgumentError.new("Argument Error in #{self.class}. :pds_url not specified in config.") if pds_url.nil?;
  raise ArgumentError.new("Argument Error in #{self.class}. :calling_system not specified in config.") if calling_system.nil?;
  raise ArgumentError.new("Argument Error in #{self.class}. :pds_handle is null.") if pds_handle.nil?;
  raise ArgumentError.new("Argument Error in #{self.class}. :attribute is null.") if pds_handle.nil?;
  pds_uri = URI.parse("#{pds_url}/pds?func=get-attribute&attribute=#{attribute}&calling_system=#{calling_system}&pds_handle=#{pds_handle}")
  http = Net::HTTP.new(pds_uri.host, pds_uri.port)
  # Set read timeout to 15 seconds.
  http.read_timeout = 15
  http.use_ssl = true if pds_uri.is_a?(URI::HTTPS)
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
  response = http.post(pds_uri.path, pds_uri.query)
  begin
    response.value
  rescue Exception => e
    raise "Error in #{self.class}. Invalid HTTP response status.\n#{e.message}"
  end
  # PDS returns as HTML content type, unfortunately.
  @response = Nokogiri.XML(response.body)
  @error = @response.at("//error").inner_text unless @response.at("//error").nil?
  # Don't raise an error, because user not found is reported as an error.
end