Class: Exlibris::Aleph::RestAPI

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/exlibris/aleph/rest_api.rb

Direct Known Subclasses

Patron, Record

Instance Method Summary (collapse)

Constructor Details

- (RestAPI) initialize(uri)



6
7
8
9
# File 'lib/exlibris/aleph/rest_api.rb', line 6

def initialize(uri)
  @uri = uri
  raise "Initialization error in #{self.class}. Missing URI." if @uri.nil?
end

Instance Method Details

- (Object) error



10
11
12
13
# File 'lib/exlibris/aleph/rest_api.rb', line 10

def error
  return nil if reply_code == "0000" 
  return "#{reply_text}"
end

- (Object) reply_code



14
15
16
17
18
19
20
# File 'lib/exlibris/aleph/rest_api.rb', line 14

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

- (Object) reply_text



21
22
23
24
25
26
27
# File 'lib/exlibris/aleph/rest_api.rb', line 21

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