Class: Barato

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#httpObject

Returns the value of attribute http.



7
8
9
# File 'lib/barato.rb', line 7

def http
  @http
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/barato.rb', line 7

def response
  @response
end

#uriObject

Returns the value of attribute uri.



7
8
9
# File 'lib/barato.rb', line 7

def uri
  @uri
end

Instance Method Details

#runObject



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

Returns:

  • (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