poller 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,20 @@
|
|
1
|
-
# This class expects a
|
2
|
-
#
|
1
|
+
# This class expects a search_term in its constructor which can be
|
2
|
+
# either a String or a Regexp
|
3
|
+
#
|
4
|
+
# The matches? method takes a Net::HTTPResponse object and will apply
|
5
|
+
# the search_term to the HTTPResponse.body
|
3
6
|
|
4
7
|
module Matchers
|
5
8
|
module HTTP
|
6
9
|
|
7
10
|
class ResponseBodyContains
|
8
11
|
|
12
|
+
# @param search_term [String | Regexp] - the search term
|
9
13
|
def initialize(search_term)
|
10
14
|
@search_term = search_term
|
11
15
|
end
|
12
16
|
|
17
|
+
# @param http_response [Net::HTTPResponse object] - the http response
|
13
18
|
def matches?(http_response)
|
14
19
|
return @search_term.match(http_response.body) if @search_term.class == Regexp
|
15
20
|
http_response.body.include?(@search_term)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This class expects a String holding an XPath expression and an optional
|
2
|
+
# number of occurrences of the XPath to be found in the document.
|
3
|
+
#
|
4
|
+
# The matches? method takes a Net::HTTPResponse object and will apply
|
5
|
+
# the search_term to the result of the XPath querying the HTTPResponse.body
|
6
|
+
#
|
7
|
+
# = Examples
|
8
|
+
# dcx = DocumentContainsXPath.new('//ElementA/ElementB')
|
9
|
+
#
|
10
|
+
# dcx = DocumentContainsXPath.new('//ElementA/ElementB', 3)
|
11
|
+
#
|
12
|
+
|
13
|
+
require 'rexml/document'
|
14
|
+
|
15
|
+
module Matchers
|
16
|
+
module XML
|
17
|
+
|
18
|
+
class DocumentContainsXPath
|
19
|
+
|
20
|
+
# @param xpath_expr_s [String] - the XPath expression
|
21
|
+
# @param optional occurences [Integer] - the number of occurences expected in document
|
22
|
+
def initialize(xpath_expr_s, occurrences = 1)
|
23
|
+
@xpath_expr_s = xpath_expr_s
|
24
|
+
@occurrences = occurrences
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param http_response [Net::HTTPResponse object] - the http response
|
28
|
+
def matches?(http_response)
|
29
|
+
xml_doc = REXML::Document.new(http_response.body)
|
30
|
+
nodes = REXML::XPath.match(xml_doc, @xpath_expr_s)
|
31
|
+
nodes.count >= @occurrences
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# This class expects a String holding an XPath expression and a search_term
|
2
|
+
# in its constructor which can be either a String or a Regexp
|
3
|
+
#
|
4
|
+
# The matches? method takes a Net::HTTPResponse object and will apply
|
5
|
+
# the search_term to the result of the XPath querying the HTTPResponse.body
|
6
|
+
#
|
7
|
+
# = Example
|
8
|
+
# xct = XPathContainsText.new('//ElementA/ElementB', 'Text that I expect')
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'rexml/document'
|
12
|
+
|
13
|
+
module Matchers
|
14
|
+
module XML
|
15
|
+
|
16
|
+
class XPathContainsText
|
17
|
+
|
18
|
+
# @param xpath_expr_s [String] - the XPath expression
|
19
|
+
# @param search_term [String | Regexp] - the search term
|
20
|
+
def initialize(xpath_expr_s, search_term)
|
21
|
+
@xpath_expr_s = xpath_expr_s
|
22
|
+
@search_term = search_term
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param http_response [Net::HTTPResponse object] - the http response
|
26
|
+
def matches?(http_response)
|
27
|
+
xml_doc = REXML::Document.new(http_response.body)
|
28
|
+
xpath = REXML::XPath.first(xml_doc, @xpath_expr_s)
|
29
|
+
return @search_term.match(xpath.text) if @search_term.class == Regexp
|
30
|
+
xpath.text.include?(@search_term)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/poller.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# The HttpProbe class is built on top of the Ruby built-in net/http library.
|
2
|
-
# Proxy support is provided. Please note that the Net::HTTP::Proxy
|
3
|
-
# return a Net::HTTP object if no proxy information is given (ie proxy_hostname
|
2
|
+
# Proxy support is provided. Please note that the Net::HTTP::Proxy method will
|
3
|
+
# return a Net::HTTP object if no proxy information is given (ie if proxy_hostname
|
4
|
+
# is nil).
|
4
5
|
#
|
5
6
|
# The 'sample' method will wrap any Exception it may catch into a RuntimeError.
|
6
7
|
#
|
7
|
-
# Equally, any HTTP Response other than Net::
|
8
|
+
# Equally, any HTTP Response other than Net::HTTPOK will also get wrapped
|
8
9
|
# into a RuntimeError as this class expects a GET request to return 200|OK or
|
9
|
-
#
|
10
|
+
# in its current implementation. Redirects will therefore be regarded as a failure.
|
10
11
|
#
|
11
12
|
# HttpProbe also expects a matcher to be passed in. The matcher must return
|
12
13
|
# either 'true or 'false' when given the http_response for evaluation via
|
@@ -14,7 +15,7 @@
|
|
14
15
|
#
|
15
16
|
# SSL is supported but certificates are not verified.
|
16
17
|
#
|
17
|
-
# Basic Auth is also supported in case userinfo appears in URL.
|
18
|
+
# Basic Auth is also supported in case userinfo appears in the passed in URL.
|
18
19
|
|
19
20
|
require 'uri'
|
20
21
|
require 'net/http'
|
data/lib/poller/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 2.
|
21
|
+
version: 2.13.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
29
|
+
version: 2.13.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: simplecov
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,8 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- lib/matchers/http/response_body_contains.rb
|
55
|
+
- lib/matchers/xml/document_contains_xpath.rb
|
56
|
+
- lib/matchers/xml/xpath_contains_text.rb
|
55
57
|
- lib/poller/http/http_poller.rb
|
56
58
|
- lib/poller/http/http_probe.rb
|
57
59
|
- lib/poller/poller.rb
|
@@ -59,7 +61,8 @@ files:
|
|
59
61
|
- lib/poller/version.rb
|
60
62
|
- lib/poller.rb
|
61
63
|
homepage: https://github.com/mkrogemann/poller
|
62
|
-
licenses:
|
64
|
+
licenses:
|
65
|
+
- MIT
|
63
66
|
post_install_message:
|
64
67
|
rdoc_options: []
|
65
68
|
require_paths:
|
@@ -78,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
81
|
version: '0'
|
79
82
|
requirements: []
|
80
83
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.25
|
82
85
|
signing_key:
|
83
86
|
specification_version: 3
|
84
87
|
summary: Pollers and Probes
|