Class: Barato
- Inherits:
-
Object
- Object
- Barato
- Defined in:
- lib/barato.rb
Overview
This class simply takes in a URL and has the ability to parse it for information (headers, etc per the Net::HTTP::Persistent module) and will make a new get request to the URL every 20 minutes to keep it ‘alive’. It will make an initial request when the object is initialized, then feed the object to the timer to be repeated every X seconds. It is set to 20 minutes by default.
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
-
#response ⇒ Object
Returns the value of attribute response.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(url) ⇒ Barato
constructor
A new instance of Barato.
- #run ⇒ Object
- #working_response? ⇒ Boolean
Constructor Details
#initialize(url) ⇒ Barato
Returns a new instance of Barato.
9 10 11 12 13 |
# File 'lib/barato.rb', line 9 def initialize(url) @uri = URI("#{url}") @http = Net::HTTP::Persistent.new(uri) @response = http.request(@uri) end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
7 8 9 |
# File 'lib/barato.rb', line 7 def http @http end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/barato.rb', line 7 def response @response end |
#uri ⇒ Object
Returns the value of attribute uri.
7 8 9 |
# File 'lib/barato.rb', line 7 def uri @uri end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/barato.rb', line 23 def run Thread.new do while self.working_response? == true @response = http.request(@uri) sleep 1200 end end end |
#working_response? ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/barato.rb', line 15 def working_response? if @response.msg.eql?("OK") return true else "Did not receive a 200 OK response" end end |