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.
164 165 166 |
# File 'lib/ebsco-discovery-service-api.rb', line 164 def initialize(max_retries = 2) @max_retries = max_retries end |
Instance Attribute Details
#max_retries ⇒ Object
Returns the value of attribute max_retries.
162 163 164 |
# File 'lib/ebsco-discovery-service-api.rb', line 162 def max_retries @max_retries end |
#session_token ⇒ Object
Returns the value of attribute session_token.
163 164 165 |
# File 'lib/ebsco-discovery-service-api.rb', line 163 def session_token @session_token end |
Instance Method Details
#create_session(auth_token = @auth_token, format = :xml) ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ebsco-discovery-service-api.rb', line 173 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
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/ebsco-discovery-service-api.rb', line 237 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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ebsco-discovery-service-api.rb', line 263 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
183 184 185 186 187 188 189 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 |
# File 'lib/ebsco-discovery-service-api.rb', line 183 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?) if (.index('&pagenumber=') && (.index('&pagenumber=') > 0)) beginSubstring = .index('&pagenumber=') + 12 currentpage = [beginSubstring..-1] newOptions = [0..beginSubstring-1] endSubstring = currentpage.index('&') - 1 currentpageInt = currentpage[0..endSubstring] newOptionsEnd = currentpage[endSubstring+1..-1] if Integer(currentpageInt) > 249 = newOptions + "1" + newOptionsEnd end 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
170 171 172 |
# File 'lib/ebsco-discovery-service-api.rb', line 170 def show_auth_token return @auth_token end |
#show_session_token ⇒ Object
167 168 169 |
# File 'lib/ebsco-discovery-service-api.rb', line 167 def show_session_token return @session_token end |