Class: Exlibris::Aleph::Rest::Base

Inherits:
Object
  • Object
show all
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

Patron, Exlibris::Aleph::Record

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#responseObject

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

Parameters:

  • value

    the value to set the attribute rest_url to.


18
19
20
# File 'lib/exlibris/aleph/rest/base.rb', line 18

def rest_url=(value)
  @rest_url = value
end

Instance Method Details

#errorObject

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_codeObject

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_textObject

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