Class: AddressFinder::HTTP
- Inherits:
-
Object
- Object
- AddressFinder::HTTP
- Defined in:
- lib/addressfinder/http.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ HTTP
constructor
A new instance of HTTP.
- #request(request_uri) ⇒ Object
- #start(&block) ⇒ Object
Constructor Details
#initialize(config) ⇒ HTTP
Returns a new instance of HTTP.
7 8 9 10 |
# File 'lib/addressfinder/http.rb', line 7 def initialize(config) @config = config @connection_is_bad = false end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/addressfinder/http.rb', line 5 def config @config end |
Instance Method Details
#request(request_uri) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/addressfinder/http.rb', line 18 def request(request_uri) retries = 0 begin re_establish_connection if @connection_is_bad uri = build_uri(request_uri) request = Net::HTTP::Get.new(uri) net_http.request(request) rescue Net::ReadTimeout, Net::OpenTimeout, SocketError => error if retries < config.retries retries += 1 sleep(config.retry_delay) @connection_is_bad = true if net_http.started? retry else raise error end end end |
#start(&block) ⇒ Object
12 13 14 15 16 |
# File 'lib/addressfinder/http.rb', line 12 def start(&block) net_http.start do block.call(self) end end |