peeping_tom 0.4 → 0.5

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.
Files changed (2) hide show
  1. data/lib/peeping_tom/dsl.rb +13 -10
  2. metadata +2 -2
@@ -4,12 +4,15 @@ require 'uri'
4
4
 
5
5
  module PeepingTom
6
6
  module DSL
7
- def ping(site)
7
+ def ping(site, method = :head)
8
+ method = method.to_s.downcase
9
+ raise ArgumentError, "only accepts head or get" unless ['head', 'get'].include?(method)
10
+
8
11
  Timeout::timeout(site.timeout) do
9
12
  url = URI.parse(site.url)
10
13
  res = Net::HTTP.start(url.host, url.port) do |http|
11
14
  file = "/" + url.to_s.sub(/http:\/\/.*?\//, '')
12
- http.head(file)
15
+ http.send(method, file)
13
16
  end
14
17
  return res.code.to_i >= 200 && res.code.to_i < 400
15
18
  end
@@ -17,11 +20,11 @@ module PeepingTom
17
20
  rescue Timeout::Error, Errno::ECONNREFUSED, SocketError
18
21
  return error!
19
22
  end
20
-
23
+
21
24
  def channels
22
25
  @channels
23
26
  end
24
-
27
+
25
28
  def watch(name)
26
29
  PeepingTom.peeper(name).sites.each_value do |site|
27
30
  @error = false
@@ -32,29 +35,29 @@ module PeepingTom
32
35
  end
33
36
  end
34
37
  end
35
-
38
+
36
39
  def errors
37
40
  return unless @errors
38
41
  yield
39
42
  end
40
-
43
+
41
44
  def no_errors
42
45
  return if @errors
43
46
  yield
44
47
  end
45
-
48
+
46
49
  def error!
47
50
  @error = true
48
51
  @errors = true
49
52
  return false
50
53
  end
51
-
54
+
52
55
  def group(name, &block)
53
56
  PeepingTom.set_peeper(name)
54
57
  yield
55
58
  PeepingTom.reset_peeper
56
59
  end
57
-
60
+
58
61
  def channel(type, *opts)
59
62
  if type == :irc
60
63
  require File.join(File.dirname(__FILE__), "notifier", "irc")
@@ -68,7 +71,7 @@ module PeepingTom
68
71
  @channels ||= []
69
72
  @channels << channel
70
73
  end
71
-
74
+
72
75
  def site(name, site, opts = {})
73
76
  PeepingTom.peeper.register(name, site, opts)
74
77
  end
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- version: "0.4"
7
+ - 5
8
+ version: "0.5"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Terry Heath