snoop 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -1
- data/lib/snoop/{http_monitor.rb → http.rb} +10 -18
- data/lib/snoop/version.rb +1 -1
- data/lib/snoop.rb +1 -1
- data/spec/acceptance/http_spec.rb +30 -0
- data/spec/unit/{http_monitor_spec.rb → http_spec.rb} +47 -14
- metadata +7 -7
- data/spec/acceptance/http_monitor_spec.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cd732ffdcde8dc20c8859e3206b5d3b860e7865
|
4
|
+
data.tar.gz: 5ef83ae68a60de3e5ad236b9c6f4bbb757218769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50552b68abf7e15d0c19b7b5a38e6fd46c13404ba2a79c2833ecec87dd58f761349e0be0c4cf8873c6bcddae31fd5bd0e2c1af42716a6cfc27751432011bd9e4
|
7
|
+
data.tar.gz: 1a04911d8ed62afb356a253c87b0b36d6299c073798130042ad3c35f7dc31fcf86efbe98cdd4e460e050a16149692ea04789fdae168496dfec30ad485dd25b40
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,33 +1,28 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
3
|
module Snoop
|
4
|
-
class
|
4
|
+
class Http
|
5
5
|
UrlRequiredException = Class.new(StandardError)
|
6
6
|
|
7
|
-
attr_reader :url, :
|
7
|
+
attr_reader :url, :http_client, :interval, :content
|
8
8
|
attr_accessor :content
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
url: nil, http_client: HTTParty, notifier: MacOSNotifier.new, interval: 1
|
12
|
-
)
|
10
|
+
def initialize(url: nil, http_client: HTTParty)
|
13
11
|
raise UrlRequiredException if url.nil?
|
12
|
+
|
14
13
|
@url = url
|
15
14
|
@http_client = http_client
|
16
|
-
@notifier = notifier
|
17
|
-
@interval = interval
|
18
15
|
end
|
19
16
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def notify(
|
18
|
+
delay: 0, times: 1, while_true: -> { false }, while_false: -> { true }
|
19
|
+
)
|
20
|
+
while (times -= 1) >= 0 || while_true.call || !while_false.call
|
21
|
+
yield content if content_changed?
|
22
|
+
sleep delay
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
|
-
def notify
|
28
|
-
notifier.notify if content_changed?
|
29
|
-
end
|
30
|
-
|
31
26
|
def content_changed?
|
32
27
|
old_content = @content
|
33
28
|
@content = fetch_content
|
@@ -38,7 +33,4 @@ module Snoop
|
|
38
33
|
http_client.get(url).body
|
39
34
|
end
|
40
35
|
end
|
41
|
-
|
42
|
-
class MacOSNotifier
|
43
|
-
end
|
44
36
|
end
|
data/lib/snoop/version.rb
CHANGED
data/lib/snoop.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'snoop/version'
|
2
|
-
require 'snoop/
|
2
|
+
require 'snoop/http'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'snoop/http'
|
2
|
+
require 'support/http_server'
|
3
|
+
|
4
|
+
describe Snoop::Http do
|
5
|
+
with_http_server do |url|
|
6
|
+
it 'notifies when content has changed' do
|
7
|
+
snoop = described_class.new(url: "#{url}/dynamic-content")
|
8
|
+
|
9
|
+
notification_count = 0
|
10
|
+
|
11
|
+
snoop.notify times: 2 do
|
12
|
+
notification_count += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
expect(notification_count).to eq 2
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'does not notify when content has not changed' do
|
19
|
+
snoop = described_class.new(url: "#{url}/static-content")
|
20
|
+
|
21
|
+
notification_count = 0
|
22
|
+
|
23
|
+
snoop.notify times: 2 do
|
24
|
+
notification_count += 1
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(notification_count).to eq 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'snoop/
|
1
|
+
require 'snoop/http'
|
2
2
|
|
3
|
-
describe Snoop::
|
3
|
+
describe Snoop::Http do
|
4
4
|
subject { described_class.new(url: url) }
|
5
5
|
|
6
6
|
let(:url) { 'http://example.com' }
|
@@ -16,36 +16,69 @@ describe Snoop::HttpMonitor do
|
|
16
16
|
it 'raises an exception' do
|
17
17
|
expect {
|
18
18
|
subject
|
19
|
-
}.to raise_error Snoop::
|
19
|
+
}.to raise_error Snoop::Http::UrlRequiredException
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '#notify' do
|
25
|
-
let(:
|
25
|
+
let(:content) { 'abc123' }
|
26
|
+
let(:content_changed?) { true }
|
26
27
|
|
27
28
|
before do
|
28
29
|
subject.stub(
|
29
|
-
|
30
|
-
|
30
|
+
content: content,
|
31
|
+
content_changed?: content_changed?
|
31
32
|
)
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
it 'notifies the requested number of times' do
|
36
|
+
notification_count = 0
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
subject.notify
|
38
|
+
subject.notify times: 5 do
|
39
|
+
notification_count += 1
|
40
40
|
end
|
41
|
+
|
42
|
+
expect(notification_count).to eq 5
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'notifies while an expression is true' do
|
46
|
+
notification_count = 0
|
47
|
+
|
48
|
+
subject.notify while_true: -> { notification_count < 3 } do
|
49
|
+
notification_count += 1
|
50
|
+
end
|
51
|
+
|
52
|
+
expect(notification_count).to eq 3
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'notifies while an expression is false' do
|
56
|
+
notification_count = 0
|
57
|
+
|
58
|
+
subject.notify while_false: -> { notification_count > 2 } do
|
59
|
+
notification_count += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
expect(notification_count).to eq 3
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'yields the content to the notification block' do
|
66
|
+
yielded_content = nil
|
67
|
+
|
68
|
+
subject.notify { |content| yielded_content = content }
|
69
|
+
|
70
|
+
expect(yielded_content).to eq content
|
41
71
|
end
|
42
72
|
|
43
73
|
context 'when the content does not change' do
|
44
74
|
let(:content_changed?) { false }
|
45
75
|
|
46
|
-
it 'does not
|
47
|
-
|
48
|
-
|
76
|
+
it 'does not yield the notification block' do
|
77
|
+
yielded = false
|
78
|
+
|
79
|
+
subject.notify { yielded = true }
|
80
|
+
|
81
|
+
expect(yielded).to be_false
|
49
82
|
end
|
50
83
|
end
|
51
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snoop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,12 +108,12 @@ files:
|
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
110
|
- lib/snoop.rb
|
111
|
-
- lib/snoop/
|
111
|
+
- lib/snoop/http.rb
|
112
112
|
- lib/snoop/version.rb
|
113
113
|
- snoop.gemspec
|
114
|
-
- spec/acceptance/
|
114
|
+
- spec/acceptance/http_spec.rb
|
115
115
|
- spec/support/http_server.rb
|
116
|
-
- spec/unit/
|
116
|
+
- spec/unit/http_spec.rb
|
117
117
|
homepage: https://github.com/chrishunt/snoop
|
118
118
|
licenses:
|
119
119
|
- MIT
|
@@ -139,6 +139,6 @@ signing_key:
|
|
139
139
|
specification_version: 4
|
140
140
|
summary: Monitor content for changes and be notified
|
141
141
|
test_files:
|
142
|
-
- spec/acceptance/
|
142
|
+
- spec/acceptance/http_spec.rb
|
143
143
|
- spec/support/http_server.rb
|
144
|
-
- spec/unit/
|
144
|
+
- spec/unit/http_spec.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'snoop/http_monitor'
|
2
|
-
require 'support/http_server'
|
3
|
-
|
4
|
-
describe Snoop::HttpMonitor do
|
5
|
-
class TestNotifier
|
6
|
-
attr_reader :notification_count
|
7
|
-
|
8
|
-
def initialize(notification_count = 0)
|
9
|
-
@notification_count = notification_count
|
10
|
-
end
|
11
|
-
|
12
|
-
def notify
|
13
|
-
@notification_count += 1
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:notifier) { TestNotifier.new }
|
18
|
-
|
19
|
-
with_http_server do |url|
|
20
|
-
it 'notifies when http content has changed' do
|
21
|
-
monitor = described_class.new(
|
22
|
-
url: "#{url}/dynamic-content",
|
23
|
-
notifier: notifier
|
24
|
-
)
|
25
|
-
|
26
|
-
2.times { monitor.notify }
|
27
|
-
expect(notifier.notification_count).to eq 2
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'does not notify when http content has not changed' do
|
31
|
-
monitor = described_class.new(
|
32
|
-
url: "#{url}/static-content",
|
33
|
-
notifier: notifier
|
34
|
-
)
|
35
|
-
|
36
|
-
2.times { monitor.notify }
|
37
|
-
expect(notifier.notification_count).to eq 1
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|