barato 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/barato.rb +3 -2
- data/spec/tests.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c55a198cca4b86943d45269ad605254aafabe53
|
4
|
+
data.tar.gz: ce671f05a670af9801f2e23c9461720237a2e329
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f7809e81341be01080995f3e892b1a4ec866b2e2a339f35f17c9c653a9d9bccaea16083ee6dbcb4f503619f8fc8623a5a39f2f7aaea9541e5ecfdf3cb9eae8
|
7
|
+
data.tar.gz: 035c514b42f628b9f471db50986836f1974385e980c5eec16ce0544bdd43019888343c3c8c55f7b892209c92c264474b24cca7a58cf8b282a5802735c567ed01
|
data/lib/barato.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'net/http/persistent'
|
2
2
|
require 'uri'
|
3
3
|
|
4
|
-
# This class simply takes in a URL and has the ability to parse it for information (headers, etc per the Net::HTTP::Persistent module)
|
4
|
+
# 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.
|
5
5
|
|
6
6
|
class Barato
|
7
7
|
attr_accessor :response, :http, :uri
|
@@ -9,6 +9,7 @@ attr_accessor :response, :http, :uri
|
|
9
9
|
def initialize(url)
|
10
10
|
@uri = URI("#{url}")
|
11
11
|
@http = Net::HTTP::Persistent.new(uri)
|
12
|
+
@response = http.request(@uri)
|
12
13
|
end
|
13
14
|
|
14
15
|
def working_response?
|
@@ -21,7 +22,7 @@ attr_accessor :response, :http, :uri
|
|
21
22
|
|
22
23
|
def run
|
23
24
|
Thread.new do
|
24
|
-
while true
|
25
|
+
while self.working_response? == true
|
25
26
|
@response = http.request(@uri)
|
26
27
|
sleep 1200
|
27
28
|
end
|
data/spec/tests.rb
CHANGED
@@ -7,6 +7,10 @@ describe 'initial setup' do
|
|
7
7
|
@test_subject = Barato.new('http://www.google.com')
|
8
8
|
end
|
9
9
|
|
10
|
+
it 'should have a 200 OK http response' do
|
11
|
+
expect(@test_subject.working_response?).to be_true
|
12
|
+
end
|
13
|
+
|
10
14
|
it 'should have a url' do
|
11
15
|
@test_subject.http.name.host.eql?("www.google.com")
|
12
16
|
end
|