Class: Hip3::HTTPSession
- Inherits:
-
Net::HTTP
- Object
- Net::HTTP
- Hip3::HTTPSession
- Defined in:
- app/models/hip3/bib_searcher.rb
Constant Summary collapse
- @@timeout =
5
Class Method Summary collapse
- .create(a_host, a_port = 80) ⇒ Object
-
.safe_get(httpObj, path, headers = nil) ⇒ Object
Does a get whether or not the connection is already open, if it wasn’t already open, will make sure to leave it closed again.
Instance Method Summary collapse
Class Method Details
.create(a_host, a_port = 80) ⇒ Object
245 246 247 248 249 250 |
# File 'app/models/hip3/bib_searcher.rb', line 245 def HTTPSession.create(a_host, a_port = 80) http = HTTPSession.new(a_host, a_port) http.read_timeout = @@timeout http.open_timeout = @@timeout return http end |
.safe_get(httpObj, path, headers = nil) ⇒ Object
Does a get whether or not the connection is already open, if it wasn’t already open, will make sure to leave it closed again.
278 279 280 281 282 283 284 285 |
# File 'app/models/hip3/bib_searcher.rb', line 278 def self.safe_get(httpObj, path, headers=nil) if httpObj.started? return httpObj.get(path, headers) else # With a block, will close the connection when we're done. return httpObj.start { |h| h.get(path, headers) } end end |
Instance Method Details
#get(path, headers = nil, &block) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'app/models/hip3/bib_searcher.rb', line 253 def get(path, headers=nil, &block) limit = 6 tries = 0 response = nil while (response == nil || response.kind_of?(Net::HTTPRedirection) && tries < limit) # follow redirects if response.kind_of?( Net::HTTPRedirection ) response = Net::HTTP.get_response(URI.parse(response['location'])) else response = super(path, headers, block) end tries = tries + 1 end #This method raises if not 2xx response status. #No idea why such a method is called 'value' response.value return response end |