4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/median/primo/search.rb', line 4
def search(search_request)
raise "the given parameter is not a valid search request" unless search_request.is_a?(SearchRequest)
wsdl_url = "#{Median.config.primo_base_url}/PrimoWebServices/services/searcher?wsdl"
wsdl_filename = File.join(Rails.root, 'tmp', 'cache', 'primo.wsdl.xml')
unless File.exists?(wsdl_filename)
File.open(wsdl_filename, 'wb') { |f| open(wsdl_url) { |u| f.write(u.read) } }
end
client = Savon::Client.new do |wsdl, http|
wsdl.document = wsdl_filename
end
begin
response = client.request(:search_brief) do |soap|
soap.body = {:query => search_request.to_xml.root.to_s}
end
rescue Exception => e
raise Median::ConnectionError.new(e)
end
payload = Nokogiri::XML(response.to_xml).content
SearchResult.new(payload, search_request)
end
|