web_update_checker 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a1ad7ce5402c738c3085ff43a47f4a9a832d198
4
+ data.tar.gz: 12939a88848de01cdf26aaa863d7530a323ad804
5
+ SHA512:
6
+ metadata.gz: f0a8c4fa6b72967bdf1cbd145549688b0a910e493abe74b18540f62dab3b446edbc5295e67a61f5597aaf7caf2ae1919444b474e92e6078c0e9b334c03ed51fc
7
+ data.tar.gz: a9c3b7be79ab0a9a32125a46563befb61bdb076aa12db9465bb1dcc6e6df7b8a6b68e60de175b2b380259dfd74c6cf280d0577aa4f2a03cd876d53f20b790912
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Checker.rb ADDED
@@ -0,0 +1,24 @@
1
+
2
+ url = 'http://hot-buzz.o-ta-su-ke.net/'
3
+
4
+ regex = /<h1>(.*)<\/h1>/
5
+
6
+ mail = Mail.new do
7
+ from 'matsubokkuri@gmail.com'
8
+ to 'matsubokkuri@gmail.com'
9
+ subject 'Web site is updated!'
10
+ body url
11
+ end
12
+
13
+ mail.delivery_method :smtp, {
14
+ address: 'smtp.gmail.com',
15
+ port: 587,
16
+ user_name: 'matsubokkuri',
17
+ password:'hogehoge1',
18
+ authentication: 'plain',
19
+ enable_starttls_auto: true
20
+ }
21
+
22
+ Checker.new(url, regex, mail).execute
23
+
24
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in web_update_checker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuki Matsukura
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,59 @@
1
+ # WebUpdateChecker
2
+
3
+ This library polls an URL and notifies if the contents is changed.
4
+ This is useful if you want to be notified as soon as a web site contents is changed.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'web_update_checker'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install web_update_checker
19
+
20
+ ## Usage
21
+
22
+
23
+ main.rb
24
+ ```
25
+ url = 'http://matsu.teraren.com/blog/'
26
+
27
+ regex = /<h1>(.*)<\/h1>/
28
+
29
+ mail = Mail.new do
30
+ from 'TODO@example.com'
31
+ to 'TODO@example.com'
32
+ subject 'Web site is updated!'
33
+ body @url
34
+ end
35
+
36
+ mail.delivery_method :smtp, {
37
+ address: 'localhost',
38
+ port: 25,
39
+ }
40
+
41
+
42
+ url = 'http://example.com/'
43
+ WebUpdateChecker::Checker.new(url, regex, mail).execute
44
+ ```
45
+
46
+
47
+ Execute like a following CLI
48
+ ```
49
+ % while [ true ]; do; ruby main.rb; sleep 30; done
50
+ ```
51
+
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( http://github.com/<my-github-username>/web_update_checker/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module WebUpdateChecker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,95 @@
1
+ require "web_update_checker/version"
2
+
3
+ # ruby standard
4
+ require "net/http"
5
+ require "uri"
6
+ require 'fileutils'
7
+
8
+ # gem
9
+ require 'mail'
10
+
11
+ module WebUpdateChecker
12
+
13
+ class Checker
14
+
15
+ #
16
+ # @param [String] url to Checker
17
+ # @param [Regex] Regex of to match comparing text
18
+ # @param [Mail] instance of Mail
19
+ #
20
+ def initialize(url, regex = nil, mail = nil)
21
+ @url = url
22
+ @regex = regex
23
+ @mail = mail
24
+ @tmp_file_last = '/tmp/site_last.txt'
25
+ @tmp_file_current = '/tmp/site_current.txt'
26
+ end
27
+
28
+
29
+ #
30
+ # @param [Bool] true if changed, false if no change, nil if first time.
31
+ #
32
+ def execute
33
+
34
+ uri = URI.parse(@url)
35
+
36
+
37
+ uri = URI(@url)
38
+ req = Net::HTTP::Get.new(uri.path)
39
+
40
+ response = Net::HTTP.start(
41
+ uri.host, uri.port,
42
+ :use_ssl => uri.scheme == 'https',
43
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
44
+ https.request(req)
45
+ end
46
+
47
+
48
+
49
+ matched_body = nil
50
+ if @regex
51
+ match = @regex.match(response.body)
52
+ if match.nil?
53
+ raise "Regex does not match"
54
+ end
55
+ matched_body = match[1]
56
+ else
57
+ matched_body = response.body
58
+ end
59
+
60
+
61
+ unless File.exist?(@tmp_file_last)
62
+ # first time
63
+ File.write(@tmp_file_last, matched_body)
64
+ File.write(@tmp_file_current, matched_body)
65
+ return nil
66
+ else
67
+ # 2nd time
68
+ File.write(@tmp_file_current, matched_body)
69
+ end
70
+
71
+
72
+ result = nil
73
+ unless FileUtils.compare_file(@tmp_file_last, @tmp_file_current)
74
+ @mail.deliver! if @mail
75
+ result = true
76
+ else
77
+ result = false
78
+ end
79
+
80
+ File.write(@tmp_file_last, matched_body)
81
+
82
+ return result
83
+
84
+ end
85
+
86
+
87
+ def cleanup
88
+ File.unlink(@tmp_file_last) if File.exists?(@tmp_file_last)
89
+ File.unlink(@tmp_file_current) if File.exists?(@tmp_file_current)
90
+ end
91
+
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'web_update_checker'
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe WebUpdateChecker do
4
+
5
+ before(:all) do
6
+ @url = 'http://example.com/'
7
+ WebUpdateChecker::Checker.new(@url).cleanup
8
+ end
9
+
10
+ before(:each) do
11
+
12
+ @regex = /<h1>(.*)<\/h1>/
13
+
14
+ @mail = Mail.new do
15
+ from 'TODO@example.com'
16
+ to 'TODO@example.com'
17
+ subject 'Web site is updated!'
18
+ body @url
19
+ end
20
+
21
+ @mail.delivery_method :smtp, {
22
+ address: 'localhost',
23
+ port: 25,
24
+
25
+ # address: 'smtp.gmail.com',
26
+ # port: 587,
27
+ # user_name: '<TODO>',
28
+ # password: '<TODO>',
29
+ # authentication: 'plain',
30
+ # enable_starttls_auto: true
31
+ }
32
+
33
+
34
+
35
+ end
36
+
37
+ it 'should have a version number' do
38
+ WebUpdateChecker::VERSION.should_not be_nil
39
+ end
40
+
41
+ it 'should initialize temporary file' do
42
+
43
+ WebUpdateChecker::Checker.new(@url).execute.should be_nil
44
+
45
+ end
46
+
47
+
48
+ it 'should be return as same contents' do
49
+
50
+ WebUpdateChecker::Checker.new(@url).execute.should be_false
51
+
52
+ end
53
+
54
+
55
+ it 'should be return as different contents' do
56
+
57
+ url = 'http://www.yahoo.co.jp/'
58
+ WebUpdateChecker::Checker.new(url).execute.should be_true
59
+
60
+ end
61
+
62
+
63
+ it 'should be send a notification mail' do
64
+
65
+ WebUpdateChecker::Checker.new(@url, @regex, @mail).execute.should be_true
66
+
67
+ end
68
+
69
+
70
+ after(:all) do
71
+ end
72
+
73
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'web_update_checker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "web_update_checker"
8
+ spec.version = WebUpdateChecker::VERSION
9
+ spec.authors = ["Yuki Matsukura"]
10
+ spec.email = ["matsubokkuri@gmail.com"]
11
+ spec.summary = %q{Check the web page is changed comparing to the previous time.}
12
+ spec.description = %q{First time of execution, this library get the specifified URL and preserve the result. After the 2nd time, compare the current page contents and previous contents. }
13
+ spec.homepage = "http://github.com/matsubo/web_update_checker"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 0.9"
23
+ spec.add_development_dependency "rspec", "~> 2.0"
24
+ spec.add_development_dependency "mail", "~> 2.3"
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_update_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuki Matsukura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mail
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ description: 'First time of execution, this library get the specifified URL and preserve
70
+ the result. After the 2nd time, compare the current page contents and previous contents. '
71
+ email:
72
+ - matsubokkuri@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Checker.rb
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - lib/web_update_checker.rb
86
+ - lib/web_update_checker/version.rb
87
+ - spec/spec_helper.rb
88
+ - spec/web_update_checker_spec.rb
89
+ - web_update_checker.gemspec
90
+ homepage: http://github.com/matsubo/web_update_checker
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Check the web page is changed comparing to the previous time.
114
+ test_files:
115
+ - spec/spec_helper.rb
116
+ - spec/web_update_checker_spec.rb
117
+ has_rdoc: