snoop 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snoop/http.rb +17 -6
- data/lib/snoop/version.rb +1 -1
- data/spec/acceptance/http_spec.rb +2 -2
- data/spec/unit/http_spec.rb +4 -4
- 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: 0fd5c1237486ef935e48c655df057e062a2f73da
|
4
|
+
data.tar.gz: cab236fa1b0af6d51125a36d8955c8727e4cf22c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1afd73ec6e6fff288053c02213c68d14a20ae2f04706036a9a8ce81d30c5ad2694415dc00cba2d1d417cf3f554c6dbc985a44e1ac43e8a81e96b326ea03dba09
|
7
|
+
data.tar.gz: b3aa4b4d891f75a31a1ca9bafeea0e603f7600fcc7a753cfddd83e15ef066833b1b9a1bf597c2dc3ef77669e113a3a538818ff3a7030776caa2037d366594982
|
data/lib/snoop/http.rb
CHANGED
@@ -5,7 +5,14 @@ module Snoop
|
|
5
5
|
class Http
|
6
6
|
UrlRequiredException = Class.new(StandardError)
|
7
7
|
|
8
|
-
|
8
|
+
DEFAULT_OPTIONS = {
|
9
|
+
delay: 0,
|
10
|
+
count: 1,
|
11
|
+
while: -> { false },
|
12
|
+
until: -> { true }
|
13
|
+
}
|
14
|
+
|
15
|
+
attr_reader :url, :css, :http_client
|
9
16
|
attr_accessor :content
|
10
17
|
|
11
18
|
def initialize(url: nil, css: nil, http_client: HTTParty)
|
@@ -16,12 +23,16 @@ module Snoop
|
|
16
23
|
@http_client = http_client
|
17
24
|
end
|
18
25
|
|
19
|
-
def notify(
|
20
|
-
|
21
|
-
|
22
|
-
while (
|
26
|
+
def notify(options = {})
|
27
|
+
options = DEFAULT_OPTIONS.merge(options)
|
28
|
+
|
29
|
+
while (
|
30
|
+
(options[:count] -= 1 ) >= 0 ||
|
31
|
+
options[:while].call ||
|
32
|
+
!options[:until].call
|
33
|
+
)
|
23
34
|
yield content if content_changed?
|
24
|
-
sleep delay
|
35
|
+
sleep options[:delay]
|
25
36
|
end
|
26
37
|
end
|
27
38
|
|
data/lib/snoop/version.rb
CHANGED
@@ -8,7 +8,7 @@ describe Snoop::Http do
|
|
8
8
|
|
9
9
|
notification_count = 0
|
10
10
|
|
11
|
-
snoop.notify
|
11
|
+
snoop.notify count: 2 do
|
12
12
|
notification_count += 1
|
13
13
|
end
|
14
14
|
|
@@ -20,7 +20,7 @@ describe Snoop::Http do
|
|
20
20
|
|
21
21
|
notification_count = 0
|
22
22
|
|
23
|
-
snoop.notify
|
23
|
+
snoop.notify count: 2 do
|
24
24
|
notification_count += 1
|
25
25
|
end
|
26
26
|
|
data/spec/unit/http_spec.rb
CHANGED
@@ -44,7 +44,7 @@ describe Snoop::Http do
|
|
44
44
|
it 'notifies the requested number of times' do
|
45
45
|
notification_count = 0
|
46
46
|
|
47
|
-
subject.notify
|
47
|
+
subject.notify count: 5 do
|
48
48
|
notification_count += 1
|
49
49
|
end
|
50
50
|
|
@@ -54,17 +54,17 @@ describe Snoop::Http do
|
|
54
54
|
it 'notifies while an expression is true' do
|
55
55
|
notification_count = 0
|
56
56
|
|
57
|
-
subject.notify
|
57
|
+
subject.notify while: -> { notification_count < 3 } do
|
58
58
|
notification_count += 1
|
59
59
|
end
|
60
60
|
|
61
61
|
expect(notification_count).to eq 3
|
62
62
|
end
|
63
63
|
|
64
|
-
it 'notifies
|
64
|
+
it 'notifies until an expression is true' do
|
65
65
|
notification_count = 0
|
66
66
|
|
67
|
-
subject.notify
|
67
|
+
subject.notify until: -> { notification_count > 2 } do
|
68
68
|
notification_count += 1
|
69
69
|
end
|
70
70
|
|