-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoapwos.rb
More file actions
61 lines (55 loc) · 2.08 KB
/
soapwos.rb
File metadata and controls
61 lines (55 loc) · 2.08 KB
1
2
3
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'savon'
require 'pp'
class SoapWOS
def initialize(opts={})
@client = Savon::Client
@credentials = opts[:credentials] ||
["User", "Pass"]
@auth_url = opts[:auth_url] ||
"http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl"
@search_url = opts[:search_url] ||
"http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl"
@search_xml = opts[:search_xml] ||
<<-EOF
<queryParameters>
<databaseId>WOS</databaseId>
<userQuery>CU=chile</userQuery>
<editions>
<collection>WOS</collection>
<edition>SCI</edition>
</editions>
<timeSpan>
<begin>2000-01-01</begin>
<end>2017-12-31</end>
</timeSpan>
<queryLanguage>en</queryLanguage>
</queryParameters>
<retrieveParameters>
<firstRecord>1</firstRecord>
<count>10</count>
</retrieveParameters>
EOF
end
def authenticate(auth_url=@auth_url, credentials=@credentials)
@auth_client ||= @client.new(basic_auth: @credentials, wsdl: @auth_url)
response = @auth_client.call(:authenticate, soap_action: "")
@session_cookie = response.http.headers["set-cookie"]
end
def search(query=@search_xml)
self.authenticate if @session_cookie.nil?
@search_client ||= @client.new(wsdl: @search_url, headers: {"Cookie"=> @session_cookie})
@last_search = @search_client.call(:search, soap_action: "", message: query)
end
def destroy
@auth_client.call(:close_session, soap_action: "", headers: {"Cookie"=> @session_cookie})
@session_cookie = nil
@search_client = nil
end
end
# Savon
soap = SoapWOS.new({
:credentials => ["USER", "PASS"]
})
response = soap.search
pp response.to_xml
soap.destroy