proxypoke 1.0.0 → 1.1.0

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/proxypoke +12 -1
  3. data/lib/proxypoke.rb +12 -2
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bcfdb353da832f2c35c0077d975d93d616b4a2de6f11aab45bba230e08046f4
4
- data.tar.gz: 25f095917480f0397e0c25a049b7377123ab99f5b090e4f9068db8d3966dd5df
3
+ metadata.gz: 789526d03668f81ca290b0b9ca78925d5ff311a0a62619e9f7926653dce07b16
4
+ data.tar.gz: 13c36c04811c0006aa9dbb2bde5bba947a8755735423f266a3381fcd4ebca211
5
5
  SHA512:
6
- metadata.gz: 0d3d1c6ec7579a355f26cc54bd2906cc94f9839550f1a6243f9da7992b59d9a4399d1029ead19929a0873d08e36052d6e5c6b5d045e290aec99acfafba1a8911
7
- data.tar.gz: 6f829549fc74d76f5e95512dac096e28b5a3ef5512b64bfe632986b9d4d1df9c7613c07144cd7c7d3980a617f6d5a7651c07a5f7821f5d50c47a5db4b3865de4
6
+ metadata.gz: '067985b0d908000211c181d8ea3858b8d4a9ac3088b6296f1abe036af1cf2c8eae6c349955cddfe165eb00711789b9dc8d9d10f7e1bfd5f4036e93437fc9beba'
7
+ data.tar.gz: 4eaf942f69a4172a19111a2919ef477ec6a81c4d393a9a92d143965db9ec0c778fc246917a13da102fc84b4b5f253b1e08d3fe86b47d821a0bf2deb7c8889983
data/bin/proxypoke CHANGED
@@ -10,6 +10,7 @@ options = {
10
10
  proxy_host: "localhost",
11
11
  proxy_port: 3128,
12
12
  read_timeout: 3,
13
+ search_string: ""
13
14
  }
14
15
 
15
16
 
@@ -32,6 +33,10 @@ options_parser = OptionParser.new do |parser|
32
33
  options[:read_timeout] = v
33
34
  end
34
35
 
36
+ parser.on("-s", "--string STRING", "Search for a specific string in the response body") do |v|
37
+ options[:search_string] = v
38
+ end
39
+
35
40
  parser.on("-h", "--help", "Prints this help.") do
36
41
  puts parser
37
42
  exit
@@ -46,7 +51,13 @@ if not options.keys.include? :url
46
51
  exit(false)
47
52
  end
48
53
 
49
- result, message = ProxyPoke.poke(options[:url], options[:proxy_host], options[:proxy_port], options[:read_timeout])
54
+ result, message = ProxyPoke.poke(
55
+ options[:url],
56
+ options[:proxy_host],
57
+ options[:proxy_port],
58
+ options[:read_timeout],
59
+ options[:search_string]
60
+ )
50
61
 
51
62
  puts "#{result}: #{message}"
52
63
  result == "Success" ? exit : exit(1)
data/lib/proxypoke.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "net/http"
2
2
 
3
3
  module ProxyPoke
4
- def self.poke(url, proxy_host, proxy_port, read_timeout)
4
+ def self.poke(url, proxy_host, proxy_port, read_timeout, search_string)
5
5
  uri = URI(url)
6
6
 
7
7
  client = Net::HTTP.new(
@@ -16,11 +16,21 @@ module ProxyPoke
16
16
 
17
17
  begin
18
18
  response = client.get(url)
19
- result, message = "Success", "#{proxy_host}:#{proxy_port} is working"
20
19
  rescue Net::ReadTimeout
21
20
  result, message = "Error", "connection timed out after #{client.read_timeout} seconds"
22
21
  rescue Errno::ECONNREFUSED
23
22
  result, message = "Error", "could not connect to proxy #{proxy_host} on port #{proxy_port}"
23
+ else
24
+ response_body = response.read_body
25
+
26
+ if search_string == ""
27
+ result, message = "Success", "#{proxy_host}:#{proxy_port} is working"
28
+ elsif response_body.include? search_string
29
+ result, message = "Success", "#{proxy_host}:#{proxy_port} is working and the search string was found"
30
+ else
31
+ result, message = "Error", "#{proxy_host}:#{proxy_port} is working but the search string was not found"
32
+ end
33
+
24
34
  end
25
35
 
26
36
  return result, message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxypoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Jennings
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-06 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: david@chillidoor.com
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  requirements: []
41
- rubygems_version: 3.3.20
41
+ rubygems_version: 3.3.7
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Makes an HTTP request to check if a web proxy is working