webpage_update_checker 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8c2526d9cd437964c3c639911f5f67a47ac66864e6728ca16c5f3369b761bb0
4
- data.tar.gz: 18acb4cde3a66373d7ddea4b1175d89b696ca52dc08be62e39a327f535dcdb79
3
+ metadata.gz: b97df2904819fb7a9fc893107b6d9171a19584a079b7803166d6c2f20737f27e
4
+ data.tar.gz: ba5c7ef8f48c562bbdf80f2d6980b5afa4600fddc0eb9ae0c7ee94c2ed0f6143
5
5
  SHA512:
6
- metadata.gz: 261c561477dce557e7ea8dcb849ef598040dafa37533dd5ec9a48a77c9ea9039b92adce9cc6cc18429fde9d1b567e8424be76556ad50a820d08209704bdd049b
7
- data.tar.gz: eb0d9b21d0ec08687c1eb3b66944569ca01c146bbb26cab94352f5569195fd46c7fb037971078f79ce471d05bd5c0242553a3e619b962dc0b80ecf1c658d9c37
6
+ metadata.gz: 72d8c90dd835fdf796c9cf40e89acd4fb2e63b827f3b7eadfbab08cd8c337118063513b13a41e468aa467c9da39aca2ee03ac56dfd98d985a6580f0ff85688ec
7
+ data.tar.gz: 1a220e97a26cd354401c41cf8c74f0926222fbf4ad7894f5386f534628a7a9d523c077eca9dd209bd1beb7d7adb4b6f68bc618926d79cb0fee793795fbceafc0
@@ -1,13 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpage_update_checker (1.3.0)
4
+ webpage_update_checker (1.4.0)
5
+ activesupport
5
6
  mechanize
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  abstract_type (0.0.7)
12
+ activesupport (5.2.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
11
17
  adamantium (0.2.0)
12
18
  ice_nine (~> 0.11.0)
13
19
  memoizable (~> 0.4.0)
@@ -23,6 +29,7 @@ GEM
23
29
  concord (0.1.5)
24
30
  adamantium (~> 0.2.0)
25
31
  equalizer (~> 0.0.9)
32
+ concurrent-ruby (1.1.3)
26
33
  connection_pool (2.2.2)
27
34
  coveralls (0.8.19)
28
35
  json (>= 1.8, < 3)
@@ -42,6 +49,8 @@ GEM
42
49
  hashdiff (0.3.7)
43
50
  http-cookie (1.0.3)
44
51
  domain_name (~> 0.5)
52
+ i18n (1.1.1)
53
+ concurrent-ruby (~> 1.0)
45
54
  ice_nine (0.11.2)
46
55
  jaro_winkler (1.5.1)
47
56
  json (2.1.0)
@@ -61,10 +70,11 @@ GEM
61
70
  mime-types-data (~> 3.2015)
62
71
  mime-types-data (3.2018.0812)
63
72
  mini_portile2 (2.3.0)
73
+ minitest (5.11.3)
64
74
  net-http-digest_auth (1.4.1)
65
75
  net-http-persistent (3.0.0)
66
76
  connection_pool (~> 2.2)
67
- nokogiri (1.8.4)
77
+ nokogiri (1.8.5)
68
78
  mini_portile2 (~> 2.3.0)
69
79
  ntlm-http (0.1.1)
70
80
  parallel (1.12.1)
@@ -129,6 +139,8 @@ GEM
129
139
  thor (0.19.4)
130
140
  thread_safe (0.3.6)
131
141
  tins (1.19.0)
142
+ tzinfo (1.2.5)
143
+ thread_safe (~> 0.1)
132
144
  unf (0.1.4)
133
145
  unf_ext
134
146
  unf_ext (0.0.7.5)
data/README.md CHANGED
@@ -6,10 +6,14 @@
6
6
  [![CircleCI](https://circleci.com/gh/corselia/webpage-update-checker.svg?style=svg)](https://circleci.com/gh/corselia/webpage-update-checker)
7
7
 
8
8
  # Usage
9
+
10
+ ## Install gem
9
11
  ```
10
12
  $ vim Gemfile
13
+
11
14
  # Add a line
12
15
  # gem 'webpage_update_checker'
16
+
13
17
  $ bundle install
14
18
  ```
15
19
 
@@ -19,23 +23,68 @@ or
19
23
  $ gem install webpage_update_checker
20
24
  ```
21
25
 
26
+ ## Write your app
27
+
28
+ ### Obtain by MD5
22
29
  ```ruby
23
30
  require 'webpage_update_checker'
24
31
 
25
32
  checker = WebpageUpdateChecker::Client.new
26
- target_page_md5 = WebpageUpdateChecker::Methods::Md5.new(uri: 'http://www.ne.jp/asahi/pursuits/ootsuki/pc/X68k/x680x0.xhtml')
27
33
 
34
+ target_page_md5 = WebpageUpdateChecker::Methods::Md5.new(uri: 'http://www.ne.jp/asahi/pursuits/ootsuki/pc/X68k/x680x0.xhtml')
28
35
  checker.current_comparison_value(target_page_md5) #=> fb2eeb524e6b5637ef7fa4bed48f1d67
29
- checker.updated?(target_page_md5, previous_comparison_value: 'fb2eeb524e6b5637ef7fa4bed48f1d67') #=> false (not updated)
30
- checker.updated?(target_page_md5, previous_comparison_value: '12345678901234567890123456789012') #=> true (updated)
36
+ ```
37
+
38
+ ### Obtain Last-Modified
39
+ ```ruby
40
+ require 'webpage_update_checker'
41
+
42
+ checker = WebpageUpdateChecker::Client.new
31
43
 
32
44
  target_page_last_modified = WebpageUpdateChecker::Methods::LastModified.new(uri: 'http://www.ne.jp/asahi/pursuits/ootsuki/pc/X68k/x680x0.xhtml')
33
45
  checker.current_comparison_value(target_page_last_modified) #=> 2008-03-17 16:05:01 +0000
46
+ ```
47
+
48
+ ### Obtain HTTP Status Code
49
+ ```ruby
50
+ require 'webpage_update_checker'
51
+
52
+ checker = WebpageUpdateChecker::Client.new
34
53
 
35
54
  target_page_http_status_code = WebpageUpdateChecker::Methods::HttpStatusCode.new(uri: 'http://www.ne.jp/asahi/pursuits/ootsuki/pc/X68k/x680x0.xhtml')
36
55
  checker.current_comparison_value(target_page_http_status_code) #=> 200
37
56
  ```
38
57
 
58
+ ### Compare by MD5
59
+ ```ruby
60
+ require 'webpage_update_checker'
61
+
62
+ checker = WebpageUpdateChecker::Client.new
63
+
64
+ target_page_md5 = WebpageUpdateChecker::Methods::Md5.new(uri: 'http://www.ne.jp/asahi/pursuits/ootsuki/pc/X68k/x680x0.xhtml')
65
+
66
+ checker.current_comparison_value(target_page_md5) #=> fb2eeb524e6b5637ef7fa4bed48f1d67
67
+ checker.updated?(target_page_md5, previous_comparison_value: 'fb2eeb524e6b5637ef7fa4bed48f1d67') #=> false (not updated)
68
+ checker.updated?(target_page_md5, previous_comparison_value: '12345678901234567890123456789012') #=> true (updated)
69
+ ```
70
+
71
+ ### Compare by Last-Modified with Lazy Time
72
+ - `Lazy Time` comparision means to compare by not accurate datetime but ABOUT datetime
73
+ - For example, when latest `Last-Modified` is `2008-03-18 01:05:01 +0000` and `lazy_seconds` is set as '60 * 5', if now getting `Last-Modified` is `2008-03-18 01:07:01 +0000` it does NOT regard as 'Updated'
74
+ - if now getting `Last-Modified` is `2008-03-18 01:08:02 +0000` it DOES regard as 'Updated'
75
+
76
+ ```ruby
77
+ require 'webpage_update_checker'
78
+
79
+ checker = WebpageUpdateChecker::Client.new
80
+
81
+ current_time_object = WebpageUpdateChecker::Methods::LastModified.new(uri: 'http://www.ne.jp/asahi/pursuits/ootsuki/pc/X68k/x680x0.xhtml')
82
+ previous_comparision_value = '2008-03-18 01:00:01 +0900'
83
+ lazy_seconds = 60 * 5
84
+
85
+ checker.lazy_time_updated?(current_time_object, previous_comparison_value: previous_comparision_value, lazy_seconds: lazy_seconds) #=> false
86
+ ```
87
+
39
88
  # Methods
40
89
  You can use these `Methods`.
41
90
 
@@ -52,6 +101,8 @@ You can use these methods in each `Methods`.
52
101
 
53
102
  - `#updated?(checked_object, previous_comparison_value:)`
54
103
  - `#=> true or false`
104
+ - `#lazy_time_updated?(checked_object, previous_comparison_value:, lazy_seconds:)`
105
+ - `#=> true or false`
55
106
  - `#current_comparison_value(checked_object)`
56
107
  - `#=> object such as Time (LastModified), String (MD5, SHA512...) or Integer (HTTP status code)`
57
108
 
@@ -1,4 +1,6 @@
1
1
  require 'mechanize'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
2
4
  Dir[File.expand_path('methods', __dir__) << '/*.rb'].each { |file| require file }
3
5
 
4
6
  module WebpageUpdateChecker
@@ -12,6 +14,13 @@ module WebpageUpdateChecker
12
14
  end
13
15
  end
14
16
 
17
+ def lazy_time_updated?(checked_object, previous_comparison_value:, lazy_seconds:)
18
+ corrected_previous_comparison_value_time_class = (Time.parse(previous_comparison_value) + lazy_seconds.seconds).utc
19
+ checked_object_time_class = current_comparison_value(checked_object).utc
20
+
21
+ checked_object_time_class > corrected_previous_comparison_value_time_class
22
+ end
23
+
15
24
  def current_comparison_value(checked_object)
16
25
  checked_object.current_comparison_value
17
26
  end
@@ -8,6 +8,7 @@ module WebpageUpdateChecker
8
8
  @uri = uri
9
9
  end
10
10
 
11
+ # Return Time class object
11
12
  def current_comparison_value
12
13
  page = Mechanize.new.get(@uri)
13
14
  page.header['last-modified'] ? Time.parse(page.header['last-modified']) : nil
@@ -1,3 +1,3 @@
1
1
  module WebpageUpdateChecker
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_dependency 'mechanize'
25
+ spec.add_dependency 'activesupport'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.16'
27
28
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpage_update_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Osamu Takiya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-25 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement