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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fd5c1237486ef935e48c655df057e062a2f73da
4
- data.tar.gz: cab236fa1b0af6d51125a36d8955c8727e4cf22c
3
+ metadata.gz: e402f8be7361f82aa03e369c4dd3a2479e930c99
4
+ data.tar.gz: f03d974b6a042f46071073792787d568fe78f9b3
5
5
  SHA512:
6
- metadata.gz: 1afd73ec6e6fff288053c02213c68d14a20ae2f04706036a9a8ce81d30c5ad2694415dc00cba2d1d417cf3f554c6dbc985a44e1ac43e8a81e96b326ea03dba09
7
- data.tar.gz: b3aa4b4d891f75a31a1ca9bafeea0e603f7600fcc7a753cfddd83e15ef066833b1b9a1bf597c2dc3ef77669e113a3a538818ff3a7030776caa2037d366594982
6
+ metadata.gz: 32e12e8737830b2414f437b126cbe5c9a6ca3496f1e799572d75575741b47ca2727cfa6a13361ac1101e84e9fb3a74330b9bb3341112716bcd785bbb2691171a
7
+ data.tar.gz: d5a95a8b02e38f49d48146932d901253fe13b416e0df69a1e14d1571ee5d2ea685a1a5bb7be139816d91091a558640a3cdc13dee71e63b4e2bf540c90255689c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snoop (0.0.4)
4
+ snoop (0.8.0)
5
5
  httparty
6
6
  nokogiri
7
7
 
data/README.md CHANGED
@@ -1,9 +1,148 @@
1
- # Snoop `wip`
2
- Be notified when content changes.
1
+ # Snoop
2
+ Snoop on content, be notified when it changes.
3
3
 
4
- Supported snoops:
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
- - `HTTP`
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
@@ -1,3 +1,3 @@
1
1
  module Snoop
2
- VERSION = '0.0.4'
2
+ VERSION = '0.8.0'
3
3
  end
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{Monitor content for changes}
12
- spec.summary = %q{Monitor content for changes and be notified}
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
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: Monitor content for changes
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: Monitor content for changes and be notified
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