Class: Exlibris::Primo::WebService::WebServiceBase

Inherits:
Object
  • Object
show all
Defined in:
lib/exlibris/primo/web_service.rb

Overview

WebServiceBase is the base class for all Primo Web Services It can be extended but is not intended for use by itself To call a PrimoWebService implementing classes must explicity call the method make_call.

Direct Known Subclasses

EShelf, Search

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



17
18
19
# File 'lib/exlibris/primo/web_service.rb', line 17

def error
  @error
end

#responseObject (readonly)

Returns the value of attribute response.



17
18
19
# File 'lib/exlibris/primo/web_service.rb', line 17

def response
  @response
end

Instance Method Details

#make_call(base_url, service, method_name, param_name, input) ⇒ Object

Call to web service is made through make_call Raise a method not found exception if the method name is not valid



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/exlibris/primo/web_service.rb', line 21

def make_call(base_url, service, method_name, param_name, input)
  require 'soap/rpc/driver'
  endpoint_url = base_url + "/PrimoWebServices/services/primo/" + service
  soap_client = SOAP::RPC::Driver.new(endpoint_url, "http://www.exlibris.com/primo/xsd/wsRequest", "")
  soap_client.add_method(method_name, param_name) unless (respond_to? method_name)
  @response = Nokogiri::XML(soap_client.method(method_name).call(input.to_s))
  raise "Error making call to Primo web service.  Response from web service is #{@response}." if @response.nil?
  @error = []
  response.search("ERROR").each do |e|
    # Primo Web Service calls will return an <ERROR MESSAGE="{MESSAGE}" CODE="{CODE}" />
    # tag even when it succeeds. Key off CODE == 0 which is a successful call.
    #debugger
    @error.push(e.attributes["MESSAGE"]) unless e.nil? or e.attributes["CODE"].value.to_i == 0
  end
  raise "Error making call to Primo web service.  #{@error.inspect}" unless @error.empty?
end