Class: EDSApi::ConnectionHandler
- Inherits:
-
Connection
- Object
- Connection
- EDSApi::ConnectionHandler
- Defined in:
- lib/ebsco-discovery-service-api.rb
Overview
Handles connections - retries failed connections, passes commands along
Instance Attribute Summary collapse
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#session_token ⇒ Object
Returns the value of attribute session_token.
Attributes inherited from Connection
#auth_token, #guest, #password, #userid
Instance Method Summary collapse
- #create_session(auth_token = @auth_token, format = :xml) ⇒ Object
- #info(session_token, auth_token, format = :xml) ⇒ Object
-
#initialize(max_retries = 2) ⇒ ConnectionHandler
constructor
A new instance of ConnectionHandler.
- #retrieve(dbid, an, highlightterms, ebookpreferredformat, session_token, auth_token, format = :xml) ⇒ Object
- #search(options, session_token, auth_token, format = :xml) ⇒ Object
- #show_auth_token ⇒ Object
- #show_session_token ⇒ Object
Methods inherited from Connection
#end_session, #ip_authenticate, #ip_init, #uid_authenticate, #uid_init
Constructor Details
#initialize(max_retries = 2) ⇒ ConnectionHandler
Returns a new instance of ConnectionHandler.
171 172 173 |
# File 'lib/ebsco-discovery-service-api.rb', line 171 def initialize(max_retries = 2) @max_retries = max_retries end |
Instance Attribute Details
#max_retries ⇒ Object
Returns the value of attribute max_retries.
169 170 171 |
# File 'lib/ebsco-discovery-service-api.rb', line 169 def max_retries @max_retries end |
#session_token ⇒ Object
Returns the value of attribute session_token.
170 171 172 |
# File 'lib/ebsco-discovery-service-api.rb', line 170 def session_token @session_token end |
Instance Method Details
#create_session(auth_token = @auth_token, format = :xml) ⇒ Object
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/ebsco-discovery-service-api.rb', line 180 def create_session(auth_token = @auth_token, format = :xml) @auth_token = auth_token result = JSON.parse(super()) if result.has_key?('ErrorNumber') return result.to_s else @session_token = result['SessionToken'] return result['SessionToken'] end end |
#info(session_token, auth_token, format = :xml) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/ebsco-discovery-service-api.rb', line 241 def info (session_token, auth_token, format= :xml) attempts = 0 @auth_token = auth_token @session_token = session_token loop do result = JSON.parse(super(format)) # JSON Parse if result.has_key?('ErrorNumber') case result['ErrorNumber'] when "108" @session_token = self.create_session when "109" @session_token = self.create_session when "104" self.uid_authenticate(:json) when "107" self.uid_authenticate(:json) end attempts += 1 if attempts >= @max_retries return result end else return result end end end |
#retrieve(dbid, an, highlightterms, ebookpreferredformat, session_token, auth_token, format = :xml) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/ebsco-discovery-service-api.rb', line 267 def retrieve(dbid, an, highlightterms, ebookpreferredformat, session_token, auth_token, format = :xml) attempts = 0 @session_token = session_token @auth_token = auth_token loop do result = JSON.parse(super(dbid, an, highlightterms, ebookpreferredformat, format)) if result.has_key?('ErrorNumber') case result['ErrorNumber'] when "108" @session_token = self.create_session when "109" @session_token = self.create_session when "104" self.uid_authenticate(:json) when "107" self.uid_authenticate(:json) end attempts += 1 if attempts >= @max_retries return result end else return result end end end |
#search(options, session_token, auth_token, format = :xml) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/ebsco-discovery-service-api.rb', line 190 def search(, session_token, auth_token, format = :xml) # temporary fix while API SI resolves # catches case where user navigates past result page 250 and applies facet/limiter if (.index('&action=') && (.index('&action=') > 0)) if (.index('&action=GoToPage(').nil? && .index('&action=SetView(').nil?) if (.index('&pagenumber=') && (.index('&pagenumber=') > 0)) beginSubstring = .index('&pagenumber=') + 12 currentpage = [beginSubstring..-1] newOptions = [0..beginSubstring-1] endSubstring = currentpage.index('&') - 1 newOptionsEnd = currentpage[endSubstring+1..-1] = newOptions + "1" + newOptionsEnd end end end attempts = 0 @session_token = session_token @auth_token = auth_token loop do result = JSON.parse(super(, format)) if result.has_key?('ErrorNumber') case result['ErrorNumber'] when "108" @session_token = self.create_session result = JSON.parse(super(, format)) when "109" @session_token = self.create_session result = JSON.parse(super(, format)) when "104" self.uid_authenticate(:json) result = JSON.parse(super(, format)) when "107" self.uid_authenticate(:json) result = JSON.parse(super(, format)) else return result end unless result.has_key?('ErrorNumber') return result end attempts += 1 if attempts >= @max_retries return result end else return result end end end |
#show_auth_token ⇒ Object
177 178 179 |
# File 'lib/ebsco-discovery-service-api.rb', line 177 def show_auth_token return @auth_token end |
#show_session_token ⇒ Object
174 175 176 |
# File 'lib/ebsco-discovery-service-api.rb', line 174 def show_session_token return @session_token end |