class Exlibris::Aleph::API::Client::Base
Constants
- DEFAULT_REQUEST_METHOD
- VALID_VIEWS
Attributes
query[R]
Public Class Methods
new(query={})
click to toggle source
# 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
Public Instance Methods
error?()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 26 def error? reply_code != '0000' end
reply_code()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 30 def reply_code @reply_code ||= root['reply_code'] end
reply_text()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 34 def reply_text @reply_text ||= root['reply_text'] end
root()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 38 def root @root ||= to_h[root_key] end
to_h()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 42 def to_h @hash ||= MultiXml.parse(to_xml) end
to_xml()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 46 def to_xml @xml ||= body.to_s end
Protected Instance Methods
path()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 51 def path @path ||= '/rest-dlf' end
Private Instance Methods
body()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 60 def body @body ||= response.body end
connection()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 76 def connection @connection ||= Faraday.new(url: rest_url) end
get()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 68 def get connection.get("#{path}?#{query}") end
request_method()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 72 def request_method @request_method ||= DEFAULT_REQUEST_METHOD end
response()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 64 def response @response ||= send(request_method) end
rest_url()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 79 def rest_url @rest_url ||= Config.rest_url end
root_key()
click to toggle source
# File lib/exlibris/aleph/api/client/base.rb, line 56 def root_key @root_key ||= to_h.keys.first end