site_watcher 1.1.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: cfa1a2dfba58f7bc84fbcba7db6a696b160688f7f1fe975f69186b7dd026a1c2
4
- data.tar.gz: 3480fda5101368505953fba89458fb56d04cb3c78ebabd43ce5387ed89fd02cc
3
+ metadata.gz: df65a9d8f51bcde0117e6202caa4bc5053e6559c24967dfff33fb6b1542d54b3
4
+ data.tar.gz: 675de476412013dbadd3d75cead811433f913e6be1c79ae037798621f651078e
5
5
  SHA512:
6
- metadata.gz: 03aada920765c224b9776d357f8edebcd00e0a299af52cd91eb7ab4802a3918ac58f26ceee361f006d5af51d40f9580ee3d501ca9a9a50a0882460a774b5b657
7
- data.tar.gz: b2930dc82e888aba5764ab8bbf4cb29c82ce7ab7eaf044904e8c4d5ee8528ef06c04af58a86f9ee6550af42a8a622cacfb4ece5705234ffb2ce6395043452012
6
+ metadata.gz: 28f0382fae6c8c7cf69f579dd7f0dadc27b86dac5f0b562ff4cca1bf9a80822afffb22b53e8a0cabc3a5d712168dc39d2b2de5050a28585231b8b5c6d94afe54
7
+ data.tar.gz: d92430b4dc7fa2de6dabf1df4fa77899ca60d8cc7206fe435279397d0be1f2709c5aa35f6acda4813f1de10ee17fcce56257c5f53b53886b5cbb8bd8e629f3c3
@@ -1,3 +1,3 @@
1
1
  class SiteWatcher
2
- VERSION = "1.1.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/site_watcher.rb CHANGED
@@ -8,29 +8,30 @@ require "rspec/expectations"
8
8
 
9
9
  class SiteWatcher
10
10
  def self.watch(opts={}, &block)
11
- trap(:SIGINT) { abort(?\n) }
12
-
13
11
  dsl = DSL::Top.new
14
12
  dsl.instance_eval(&block)
15
13
 
16
14
  delay = opts.fetch(:every, 5)
17
- logger = opts.fetch(:logger, ::Logger.new($stderr))
15
+ logger = opts.fetch(:logger, ::Logger.new($stderr, level: :warn))
16
+ timeout = opts.fetch(:timeout, {connect: 3, read: 10})
18
17
 
19
18
  new(
20
19
  dsl.__sw_before_hooks,
21
20
  dsl.__sw_pages,
22
21
  dsl.__sw_after_hooks,
23
22
  delay,
24
- logger
23
+ logger,
24
+ timeout,
25
25
  ).watch
26
26
  end
27
27
 
28
- def initialize(before_hooks, pages, after_hooks, delay, logger)
28
+ def initialize(before_hooks, pages, after_hooks, delay, logger, timeout)
29
29
  @before_hooks = before_hooks
30
30
  @pages = pages
31
31
  @after_hooks = after_hooks
32
32
  @delay = delay
33
33
  @logger = logger
34
+ @timeout = timeout
34
35
  @force = false
35
36
  end
36
37
 
@@ -44,7 +45,7 @@ class SiteWatcher
44
45
 
45
46
  @pages.each do |page|
46
47
  begin
47
- page.__sw_run!(force)
48
+ page.__sw_run!(force, @logger, @timeout)
48
49
  @pages.delete(page) if page.__sw_remove_on_fulfillment
49
50
  rescue ::RSpec::Expectations::ExpectationNotMetError
50
51
  rescue => e
@@ -115,6 +116,7 @@ class SiteWatcher
115
116
  @__sw_headers = headers
116
117
  @__sw_http_opts = opts
117
118
  @__sw_fulfilled = nil
119
+ @__sw_fetch = nil
118
120
  @__sw_remove_on_fulfillment = true
119
121
  end
120
122
 
@@ -126,6 +128,10 @@ class SiteWatcher
126
128
  @__sw_fulfilled = block
127
129
  end
128
130
 
131
+ def fetch(&block)
132
+ @__sw_fetch = block
133
+ end
134
+
129
135
  def headers(hash)
130
136
  @__sw_headers = hash
131
137
  end
@@ -134,6 +140,7 @@ class SiteWatcher
134
140
  @__sw_http_method = http_method
135
141
  end
136
142
 
143
+ # FIXME this isn't even used?
137
144
  def body(body)
138
145
  @__sw_body = body
139
146
  end
@@ -142,20 +149,27 @@ class SiteWatcher
142
149
  @__sw_remove_on_fulfillment = !!bool
143
150
  end
144
151
 
145
- def __sw_run!(force=false)
146
- response = ::HTTP
152
+ def __sw_run!(force, logger, timeout)
153
+ client = ::HTTP
154
+ .use(logging: {logger: logger})
155
+ .timeout(timeout)
147
156
  .headers(@__sw_headers)
148
- .request(@__sw_method, @__sw_url, **@__sw_http_opts)
149
157
 
150
- case response.content_type.mime_type
151
- when /json/i
152
- page = ::JSON.parse(response.to_s)
158
+ if @__sw_fetch
159
+ response = @__sw_fetch.call(@__sw_url, client)
153
160
  else
154
- page = ::Capybara::Node::Simple.new(response.to_s)
161
+ response = client.request(@__sw_method, @__sw_url, **@__sw_http_opts)
162
+
163
+ case response.content_type.mime_type
164
+ when /json/i
165
+ response = ::JSON.parse(response.to_s)
166
+ else
167
+ response = ::Capybara::Node::Simple.new(response.to_s)
168
+ end
155
169
  end
156
170
 
157
171
  begin
158
- @__sw_tests.each { |test| test.call(page) }
172
+ @__sw_tests.each { |test| test.call(response) }
159
173
  rescue ::RSpec::Expectations::ExpectationNotMetError => err
160
174
  __sw_fulfilled! if force
161
175
  raise(err)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Genco
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
11
+ date: 2022-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.7'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.7'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - alexgenco@gmail.com
114
114
  executables: []
@@ -123,7 +123,7 @@ homepage: https://github.com/alexgenco/site_watcher
123
123
  licenses:
124
124
  - MIT
125
125
  metadata: {}
126
- post_install_message:
126
+ post_install_message:
127
127
  rdoc_options: []
128
128
  require_paths:
129
129
  - lib
@@ -138,9 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.7.6
143
- signing_key:
141
+ rubygems_version: 3.3.7
142
+ signing_key:
144
143
  specification_version: 4
145
144
  summary: Periodically monitor a website
146
145
  test_files: []