snoop 0.0.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +143 -8
- data/lib/snoop/version.rb +1 -1
- data/snoop.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e402f8be7361f82aa03e369c4dd3a2479e930c99
|
4
|
+
data.tar.gz: f03d974b6a042f46071073792787d568fe78f9b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32e12e8737830b2414f437b126cbe5c9a6ca3496f1e799572d75575741b47ca2727cfa6a13361ac1101e84e9fb3a74330b9bb3341112716bcd785bbb2691171a
|
7
|
+
data.tar.gz: d5a95a8b02e38f49d48146932d901253fe13b416e0df69a1e14d1571ee5d2ea685a1a5bb7be139816d91091a558640a3cdc13dee71e63b4e2bf540c90255689c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,148 @@
|
|
1
|
-
# Snoop
|
2
|
-
|
1
|
+
# Snoop
|
2
|
+
Snoop on content, be notified when it changes.
|
3
3
|
|
4
|
-
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
Want to know when the next version of JRuby is released? Me too! Let's `Snoop`
|
7
|
+
the [JRuby homepage](http://jruby.org) and print to the terminal when a new
|
8
|
+
version has been posted. In this example, we'll check
|
9
|
+
[jruby.org](http://jruby.org) every 5 minutes for a new version.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'snoop'
|
13
|
+
|
14
|
+
snoop = Snoop::Http.new(
|
15
|
+
url: 'http://jruby.org',
|
16
|
+
css: '#latest_release strong'
|
17
|
+
)
|
18
|
+
|
19
|
+
snoop.notify while: -> { true }, delay: 300 do |version|
|
20
|
+
puts "New JRuby Version! #{version}"
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
### Mac OS Notifications
|
25
|
+
|
26
|
+
`Snoop` works really well with Mac OS X notifications. Install
|
27
|
+
[terminal-notifier](https://github.com/alloy/terminal-notifier) and use it in
|
28
|
+
your notify callback.
|
29
|
+
|
30
|
+
```bash
|
31
|
+
$ gem install terminal-notifier
|
32
|
+
```
|
33
|
+
|
34
|
+
Let's send Mac OS X notifications when people start watching our video on
|
35
|
+
[Confreaks](http://www.confreaks.com). We'll use `Snoop` to check for updates
|
36
|
+
every 2 minutes and send a notification if we get more views. In this example,
|
37
|
+
the `Snoop` will run until the video has reached 2000 views, then stop.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'snoop'
|
41
|
+
|
42
|
+
video = '2291-larubyconf2013-impressive-ruby-productivity-with-vim-and-tmux'
|
43
|
+
|
44
|
+
snoop = Snoop::Http.new(
|
45
|
+
url: "http://www.confreaks.com/videos/#{video}",
|
46
|
+
css: '.video-rating'
|
47
|
+
)
|
48
|
+
|
49
|
+
view_count = 0
|
50
|
+
|
51
|
+
snoop.notify until: -> { view_count >= 2000 }, delay: 120 do |video_rating|
|
52
|
+
current_view_count = video_rating.gsub(/\D/, '').to_i
|
53
|
+
new_view_count = current_view_count - view_count
|
54
|
+
view_count = current_view_count
|
55
|
+
|
56
|
+
message = "#{current_view_count} views (#{new_view_count} new) on your video!"
|
57
|
+
|
58
|
+
puts "Sending notification: #{message}"
|
59
|
+
`terminal-notifier -message "#{message}"`
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Options
|
64
|
+
|
65
|
+
### CSS Selectors
|
66
|
+
|
67
|
+
Each `Snoop` requires a URL, but you can also provide a css selector if you're
|
68
|
+
only interested in part of the page's content. The css selector you provide is
|
69
|
+
handed directly to [Nokogiri](http://nokogiri.org), so the same syntax is
|
70
|
+
required.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
require 'snoop'
|
5
74
|
|
6
|
-
|
75
|
+
# Receive notifications if any part of the page changes
|
76
|
+
snoop = Snoop::Http.new(
|
77
|
+
url: 'http://jruby.org'
|
78
|
+
)
|
79
|
+
|
80
|
+
# Receive notifications if just the latest JRuby release changes
|
81
|
+
snoop = Snoop::Http.new(
|
82
|
+
url: 'http://jruby.org',
|
83
|
+
css: '#latest_release strong'
|
84
|
+
)
|
85
|
+
```
|
86
|
+
|
87
|
+
### Delay and Count
|
88
|
+
|
89
|
+
If you'd like to have your `Snoop` check for new content more than once, you
|
90
|
+
can provided a `count`. Alternatively, you can use [Conditional
|
91
|
+
Snooping](#conditional-snooping).
|
92
|
+
|
93
|
+
The `count` option is most useful for timeboxing a `Snoop`.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
require 'snoop'
|
97
|
+
snoop = Snoop::Http.new(url: 'http://jruby.org')
|
98
|
+
|
99
|
+
# Check JRuby for updates, every minute for 10 minutes
|
100
|
+
snoop.notify count: 10, delay: 60 do |content|
|
101
|
+
puts content
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
### Conditional Snooping
|
106
|
+
|
107
|
+
By default, a `Snoop` will only check once and return immediately. This is almost
|
108
|
+
useless since we are interested in change over time. Conditional Snooping is
|
109
|
+
possible with the `while` and `until` arguments. It is almost *always*
|
110
|
+
recommended to provide a `delay` when using conditional Snooping unless you are
|
111
|
+
trying to [DDoS](http://en.wikipedia.org/wiki/Denial-of-service_attack)
|
112
|
+
someone.
|
113
|
+
|
114
|
+
Here's an example of a daemon `Snoop` that runs forever, checking the JRuby
|
115
|
+
homepage every minute for changes.
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
require 'snoop'
|
119
|
+
|
120
|
+
snoop = Snoop::Http.new(url: 'http://jruby.org')
|
121
|
+
|
122
|
+
snoop.notify while: -> { true }, delay: 60 do |content|
|
123
|
+
puts content
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
Something else we might want to do is check our
|
128
|
+
[Twitter](https://twitter.com/chrishunt) follower count. Here's an example that
|
129
|
+
checks twitter every 3 minutes for changes. If the content changes, then we
|
130
|
+
print our new follower count to the terminal. When we've reached 500 followers,
|
131
|
+
the `Snoop` will stop checking.
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
snoop = Snoop::Http.new(
|
135
|
+
url: 'https://twitter.com/chrishunt',
|
136
|
+
css: '[data-element-term="follower_stats"]'
|
137
|
+
)
|
138
|
+
|
139
|
+
follower_count = 0
|
140
|
+
|
141
|
+
snoop.notify until: -> { follower_count >= 500 }, delay: 180 do |content|
|
142
|
+
follower_count = content.gsub(/\D/, '').to_i
|
143
|
+
puts "You have #{follower_count} followers!"
|
144
|
+
end
|
145
|
+
```
|
7
146
|
|
8
147
|
## Installation
|
9
148
|
|
@@ -25,10 +164,6 @@ Or install it yourself as:
|
|
25
164
|
$ gem install snoop
|
26
165
|
```
|
27
166
|
|
28
|
-
## Usage
|
29
|
-
|
30
|
-
`wip`
|
31
|
-
|
32
167
|
## Contributing
|
33
168
|
|
34
169
|
1. Fork it
|
data/lib/snoop/version.rb
CHANGED
data/snoop.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Snoop::VERSION
|
9
9
|
spec.authors = ['Chris Hunt']
|
10
10
|
spec.email = ['c@chrishunt.co']
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
11
|
+
spec.description = %q{Snoop on content, be notified when it changes.}
|
12
|
+
spec.summary = %q{Snoop on content, be notified when it changes.}
|
13
13
|
spec.homepage = 'https://github.com/chrishunt/snoop'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snoop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hunt
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description: Snoop on content, be notified when it changes.
|
112
112
|
email:
|
113
113
|
- c@chrishunt.co
|
114
114
|
executables: []
|
@@ -151,7 +151,7 @@ rubyforge_project:
|
|
151
151
|
rubygems_version: 2.0.3
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
|
-
summary:
|
154
|
+
summary: Snoop on content, be notified when it changes.
|
155
155
|
test_files:
|
156
156
|
- spec/acceptance/http_spec.rb
|
157
157
|
- spec/support/http_server.rb
|