Class: Exlibris::Aleph::API::Client::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/exlibris/aleph/api/client/base.rb

Constant Summary collapse

DEFAULT_REQUEST_METHOD =
:get
VALID_VIEWS =
['full', 'brief']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
# File 'lib/exlibris/aleph/api/client/base.rb', line 15

def initialize(query={})
  unless query.is_a?(Hash)
    raise ArgumentError.new("Expecting #{query} to be a Hash")
  end
  view = query[:view]
  unless view.nil? || VALID_VIEWS.include?(view)
    raise ArgumentError.new("Expecting #{view} to be one of #{VALID_VIEWS.join(', ')}")
  end
  @query ||= query.map { |key, value| "#{key}=#{value}"}.join('&')
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



13
14
15
# File 'lib/exlibris/aleph/api/client/base.rb', line 13

def query
  @query
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/exlibris/aleph/api/client/base.rb', line 26

def error?
  reply_code != '0000'
end

#reply_codeObject



30
31
32
# File 'lib/exlibris/aleph/api/client/base.rb', line 30

def reply_code
  @reply_code ||= root['reply_code']
end

#reply_textObject



34
35
36
# File 'lib/exlibris/aleph/api/client/base.rb', line 34

def reply_text
  @reply_text ||= root['reply_text']
end

#rootObject



38
39
40
# File 'lib/exlibris/aleph/api/client/base.rb', line 38

def root
  @root ||= to_h[root_key]
end

#to_hObject



42
43
44
# File 'lib/exlibris/aleph/api/client/base.rb', line 42

def to_h
  @hash ||= MultiXml.parse(to_xml)
end

#to_xmlObject



46
47
48
# File 'lib/exlibris/aleph/api/client/base.rb', line 46

def to_xml
  @xml ||= body.to_s
end