|
| 1 | +require 'rest-open-uri' |
| 2 | +require 'nokogiri' |
| 3 | +require 'rest-client' |
| 4 | +require 'json' |
| 5 | + |
| 6 | +module RubyEDS |
| 7 | + |
| 8 | + def authenticate_user(username, password) |
| 9 | + auth_json = {"UserId"=>"#{username}","Password"=>"#{password}","InterfaceId"=>"WSapi"}.to_json |
| 10 | + response = open('https://eds-api.ebscohost.com/authservice/rest/UIDAuth', :method=>:post, :body => auth_json, 'Content-Type' => 'application/json') |
| 11 | + doc = Nokogiri::XML(response.read) |
| 12 | + doc.remove_namespaces! |
| 13 | + auth_token = doc.xpath("//AuthToken").inner_text |
| 14 | + end |
| 15 | + |
| 16 | + def open_session(profile, guest, auth_token) |
| 17 | + response = RestClient.get "http://eds-api.ebscohost.com/edsapi/rest/CreateSession", {:params=>{"profile"=>profile, "guest"=>guest}, :content_type=>:json, "x-authenticationToken"=>auth_token} |
| 18 | + doc = Nokogiri::XML(response) |
| 19 | + doc.remove_namespaces! |
| 20 | + session_token = doc.xpath("//SessionToken").inner_text |
| 21 | + end |
| 22 | + |
| 23 | + def close_session(session_token, auth_token) |
| 24 | + response = RestClient.get "http://eds-api.ebscohost.com/edsapi/rest/endsession", {:params=>{"sessiontoken"=>session_token}, :content_type=>:json, "x-authenticationToken"=>auth_token, "x-sessionToken"=>session_token} |
| 25 | + doc = Nokogiri::XML(response) |
| 26 | + doc.remove_namespaces! |
| 27 | + success = doc.xpath("//IsSuccessful").inner_text |
| 28 | + end |
| 29 | + |
| 30 | + def get_info(session_token, auth_token, return_type="xml") |
| 31 | + response = RestClient.get "http://eds-api.ebscohost.com/edsapi/rest/info", "x-authenticationToken"=>auth_token, "x-sessionToken"=>session_token, :accept=>return_type |
| 32 | + end |
| 33 | + |
| 34 | + def basic_search(query, session_token, auth_token, view='brief', offset=1, limit=10, order='relevance', return_type="xml") |
| 35 | + response = RestClient.get "http://eds-api.ebscohost.com/edsapi/rest/Search", {:params=>{"query-1"=>query}, "x-authenticationToken"=>auth_token, "x-sessionToken"=>session_token, :accept=>return_type} |
| 36 | + end |
| 37 | + |
| 38 | + def advanced_search(search_json, return_type="xml") |
| 39 | + end |
| 40 | + |
| 41 | +end |
0 commit comments