hatebu_watcher 0.0.1
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 +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/hatebu_watcher +7 -0
- data/hatebu_watcher.gemspec +27 -0
- data/lib/hatebu_watcher.rb +12 -0
- data/lib/hatebu_watcher/base.rb +18 -0
- data/lib/hatebu_watcher/command.rb +12 -0
- data/lib/hatebu_watcher/counter.rb +35 -0
- data/lib/hatebu_watcher/observers/counter_observer.rb +23 -0
- data/lib/hatebu_watcher/parameters.rb +28 -0
- data/lib/hatebu_watcher/version.rb +3 -0
- data/spec/hatebu_watcher_spec.rb +33 -0
- data/spec/spec_helper.rb +3 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95c4f028aa1a5deba6bf522c80413eaa6b38427c
|
4
|
+
data.tar.gz: 9fee7c95e4bb89b2efa38d64389a1a929ee1dbb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e9a9858def9cdfe18f16b01916ee23f214603fea286292da513b70a2ee1c7d16ba3a9b517719658b54f1a9ae6ca28fe9fd93a7b012e6ba654e6c1ca5e56082c
|
7
|
+
data.tar.gz: 3d0959a39b41c0a29e85a8d2a56648899a63f243107b598ab866c1d7c57a80e08961936793e7c082de4f50934612eb1a87fae139c3d0209572ec74826e63982e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 kami
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# HatebuWatcher
|
2
|
+
|
3
|
+
HatebuWatcher is a utility to watch Hatena Bookmark count on console.
|
4
|
+
Output count on console and notify using Growl when the value is changed.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'hatebu_watcher'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install hatebu_watcher
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You can use `hatebu_watcher` command as follows:
|
25
|
+
|
26
|
+
```
|
27
|
+
$ hatebu_watcher {url} {interval}
|
28
|
+
```
|
29
|
+
|
30
|
+
Arguments are:
|
31
|
+
|
32
|
+
- `url`: URL where you want to watch the count
|
33
|
+
- `interval`: Refresh interval (second)
|
34
|
+
|
35
|
+
Example:
|
36
|
+
|
37
|
+
```
|
38
|
+
$ hatebu_watcher http://www.example.com/ 10
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/kami30k/hatebu_watcher/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/hatebu_watcher
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'hatebu_watcher/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'hatebu_watcher'
|
9
|
+
spec.version = HatebuWatcher::VERSION
|
10
|
+
spec.authors = ['kami']
|
11
|
+
spec.email = ['kami30k@gmail.com']
|
12
|
+
spec.summary = %q{Watch Hatena Bookmark count on console.}
|
13
|
+
spec.description = %q{Watch Hatena Bookmark count on console.}
|
14
|
+
spec.homepage = 'https://github.com/kami30k/hatebu_watcher'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'ruby-growl'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'hatebu_watcher/version'
|
2
|
+
|
3
|
+
module HatebuWatcher
|
4
|
+
autoload :Base, 'hatebu_watcher/base'
|
5
|
+
autoload :Parameters, 'hatebu_watcher/parameters'
|
6
|
+
autoload :Counter, 'hatebu_watcher/counter'
|
7
|
+
autoload :Command, 'hatebu_watcher/command'
|
8
|
+
|
9
|
+
module Observers
|
10
|
+
autoload :CounterObserver, 'hatebu_watcher/observers/counter_observer'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module HatebuWatcher
|
2
|
+
class Base
|
3
|
+
def initialize(url, interval)
|
4
|
+
@interval = interval
|
5
|
+
|
6
|
+
@counter = Counter.new(url)
|
7
|
+
@counter.add_observer(Observers::CounterObserver.new)
|
8
|
+
end
|
9
|
+
|
10
|
+
def watch
|
11
|
+
loop do
|
12
|
+
puts @counter.reload.count
|
13
|
+
|
14
|
+
sleep @interval
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'observer'
|
4
|
+
|
5
|
+
module HatebuWatcher
|
6
|
+
class Counter
|
7
|
+
include Observable
|
8
|
+
|
9
|
+
ENDPOINT = 'http://b.hatena.ne.jp/entry/jsonlite/?url='
|
10
|
+
|
11
|
+
attr_reader :count
|
12
|
+
|
13
|
+
def initialize(url)
|
14
|
+
@url = url
|
15
|
+
end
|
16
|
+
|
17
|
+
def reload
|
18
|
+
@prev_count = @count
|
19
|
+
@count = JSON.parse(json.read)['count'].to_i
|
20
|
+
|
21
|
+
unless @count == @prev_count
|
22
|
+
changed
|
23
|
+
notify_observers(@count)
|
24
|
+
end
|
25
|
+
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def json
|
32
|
+
open("#{ENDPOINT}#{@url}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ruby-growl'
|
2
|
+
|
3
|
+
module HatebuWatcher
|
4
|
+
module Observers
|
5
|
+
class CounterObserver
|
6
|
+
def update(count)
|
7
|
+
growl = Growl.new('localhost', 'HatebuWatcher')
|
8
|
+
growl.add_notification('changed')
|
9
|
+
growl.notify('changed', 'HatebuWatcher', text(count))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def text(count)
|
15
|
+
"Count: #{count} (#{time})"
|
16
|
+
end
|
17
|
+
|
18
|
+
def time
|
19
|
+
Time.now.strftime('%T')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module HatebuWatcher
|
4
|
+
class Parameters
|
5
|
+
attr_reader :url, :interval
|
6
|
+
|
7
|
+
def initialize(params)
|
8
|
+
@url = params[0]
|
9
|
+
@interval = params[1].to_i
|
10
|
+
|
11
|
+
raise ArgumentError unless valid?
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def valid?
|
17
|
+
valid_url? && valid_interval?
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid_url?
|
21
|
+
@url =~ URI::regexp
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_interval?
|
25
|
+
@interval > 0
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HatebuWatcher do
|
4
|
+
let(:url) { 'http://www.example.com/' }
|
5
|
+
let(:interval) { 10 }
|
6
|
+
|
7
|
+
describe HatebuWatcher::Parameters do
|
8
|
+
context 'when receive valid parameters' do
|
9
|
+
let(:params) { HatebuWatcher::Parameters.new([url, interval]) }
|
10
|
+
|
11
|
+
it 'should return correct value' do
|
12
|
+
expect(params.url).to eq url
|
13
|
+
expect(params.interval).to eq interval
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when receive invalid parameters' do
|
18
|
+
let(:params) { HatebuWatcher::Parameters.new(['www.example.com']) }
|
19
|
+
|
20
|
+
it 'should raise error' do
|
21
|
+
expect { params } .to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe HatebuWatcher::Counter do
|
27
|
+
let(:count) { HatebuWatcher::Counter.new(url).reload.count }
|
28
|
+
|
29
|
+
it 'should return correct value' do
|
30
|
+
expect(count).to be > 100
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hatebu_watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kami
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-growl
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Watch Hatena Bookmark count on console.
|
70
|
+
email:
|
71
|
+
- kami30k@gmail.com
|
72
|
+
executables:
|
73
|
+
- hatebu_watcher
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/hatebu_watcher
|
85
|
+
- hatebu_watcher.gemspec
|
86
|
+
- lib/hatebu_watcher.rb
|
87
|
+
- lib/hatebu_watcher/base.rb
|
88
|
+
- lib/hatebu_watcher/command.rb
|
89
|
+
- lib/hatebu_watcher/counter.rb
|
90
|
+
- lib/hatebu_watcher/observers/counter_observer.rb
|
91
|
+
- lib/hatebu_watcher/parameters.rb
|
92
|
+
- lib/hatebu_watcher/version.rb
|
93
|
+
- spec/hatebu_watcher_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
homepage: https://github.com/kami30k/hatebu_watcher
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.2.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Watch Hatena Bookmark count on console.
|
119
|
+
test_files:
|
120
|
+
- spec/hatebu_watcher_spec.rb
|
121
|
+
- spec/spec_helper.rb
|