Class: EDSApi::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/eds-alpha.rb

Overview

Connection object. Does what it says. ConnectionHandler is what is usually desired and wraps auto-reonnect features, etc.

Direct Known Subclasses

ConnectionHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



15
16
17
# File 'lib/eds-alpha.rb', line 15

def auth_token
  @auth_token
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



16
17
18
# File 'lib/eds-alpha.rb', line 16

def password=(value)
  @password = value
end

#userid=(value) ⇒ Object (writeonly)

Sets the attribute userid

Parameters:

  • value

    the value to set the attribute userid to.



16
17
18
# File 'lib/eds-alpha.rb', line 16

def userid=(value)
  @userid = value
end

Instance Method Details

#create_sessionObject

Create the session



58
59
60
61
62
63
64
65
66
67
# File 'lib/eds-alpha.rb', line 58

def create_session
	uri = URI "#{API_URL}edsapi/rest/createsession?profile=#{@profile}"
	req = Net::HTTP::Get.new(uri.request_uri)
	req['x-authenticationToken'] = @auth_token
	req['Accept'] = "application/json"
	Net::HTTP.start(uri.hostname, uri.port) { |http|
			doc = JSON.parse(http.request(req).body)
		return doc['SessionToken']
	}
end

#end_session(session_token) ⇒ Object

End the session



69
70
71
72
73
74
75
76
77
# File 'lib/eds-alpha.rb', line 69

def end_session(session_token)
	uri = URI "#{API_URL}edsapi/rest/endsession?sessiontoken=#{CGI::escape(session_token)}"
	req = Net::HTTP::Get.new(uri.request_uri)
	req['x-authenticationToken'] = @auth_token
	Net::HTTP.start(uri.hostname, uri.port) { |http|
			http.request(req)
	}
	return true
end

#info(session_token, format = :xml) ⇒ Object

Info method



102
103
104
105
106
107
108
109
110
111
# File 'lib/eds-alpha.rb', line 102

def info(session_token, format = :xml)
	uri = URI "#{API_URL}edsapi/rest/Info"
	req = Net::HTTP::Get.new(uri.request_uri)
	req['x-authenticationToken'] = @auth_token
	req['x-sessionToken'] = session_token
	req['Accept'] = 'application/json' #if format == :json
	Net::HTTP.start(uri.hostname, uri.port) { |http|
			return http.request(req).body
	}
end

#ip_authenticate(format = :xml) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/eds-alpha.rb', line 47

def ip_authenticate(format = :xml)
	uri = URI "#{API_URL_S}authservice/rest/ipauth"
	req = Net::Http:Post.new(uri.request_uri)
	req["Accept"] = "application/json" #if format == :json
	https = Net::HTTP.new(uri.hostname, uri.port)
	https.use_ssl = true
	https.verify_mode = OpenSSL::SSL::VERIFY_NONE
	doc = JSON.parse(https.request(req).body)
	@auth_token = doc['AuthToken']
end

#ip_init(profile) ⇒ Object



25
26
27
28
# File 'lib/eds-alpha.rb', line 25

def ip_init(profile)
	@profile = profile
	return self
end

#retrieve(dbid, an, session_token, format = :xml) ⇒ Object

Retrieve specific information



91
92
93
94
95
96
97
98
99
100
# File 'lib/eds-alpha.rb', line 91

def retrieve(dbid, an, session_token, format = :xml)
	uri = URI "#{API_URL}edsapi/rest/retrieve?dbid=#{dbid}&an=#{an}"
	req = Net::HTTP::Get.new(uri.request_uri)
	req['x-authenticationToken'] = @auth_token
	req['x-sessionToken'] = session_token
	req['Accept'] = 'application/json' #if format == :json
	Net::HTTP.start(uri.hostname, uri.port) { |http|
			return http.request(req).body
	}
end

#search(options, session_token, format = :xml) ⇒ Object

Run a search query, XML results are returned



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/eds-alpha.rb', line 79

def search(options, session_token, format = :xml)
			uri = URI "#{API_URL}edsapi/rest/Search?#{options}"
			#return uri.request_uri
			req = Net::HTTP::Get.new(uri.request_uri)
			req['x-authenticationToken'] = @auth_token
			req['x-sessionToken'] = session_token
			req['Accept'] = 'application/json' #if format == :json
			Net::HTTP.start(uri.hostname, uri.port) { |http|
  			return http.request(req).body
			}
end

#uid_authenticate(format = :xml) ⇒ Object

Auth with the server. Currently only uid auth is supported.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/eds-alpha.rb', line 30

def uid_authenticate(format = :xml)
	xml = "<UIDAuthRequestMessage xmlns='http://www.ebscohost.com/services/public/AuthService/Response/2012/06/01'><UserId>#{@userid}</UserId><Password>#{@password}</Password></UIDAuthRequestMessage>"
	uri = URI "#{API_URL_S}authservice/rest/uidauth"
	req = Net::HTTP::Post.new(uri.request_uri)
	req["Content-Type"] = "application/xml"
	req["Accept"] = "application/json" #if format == :json
	req.body = xml
	https = Net::HTTP.new(uri.hostname, uri.port)
	https.use_ssl = true
	https.verify_mode = OpenSSL::SSL::VERIFY_NONE
	doc = JSON.parse(https.request(req).body)
	if doc.has_key?('ErrorNumber')
	   abort "Bad response from server - error code #{result['ErrorNumber']}"
	else
	   @auth_token = doc['AuthToken']
	end			
end

#uid_init(userid, password, profile) ⇒ Object

Init the object with userid and pass.



19
20
21
22
23
24
# File 'lib/eds-alpha.rb', line 19

def uid_init(userid, password, profile)
	@userid = userid
	@password = password
	@profile = profile
	return self
end