waithook 0.4.2 → 0.4.4
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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -3
- data/lib/waithook/version.rb +1 -1
- data/lib/waithook.rb +29 -11
- data/tests/server_test.rb +8 -6
- data/tests/waithook_test.rb +14 -0
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b1713a71f7f6f0af1e0c8a9201553bbc64100d0031b504ed124e314ca36b4d5
|
4
|
+
data.tar.gz: 8864b3ecd7c86acb2f85cd969df9571cfd22160588e41a888db22baeae720931
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a2936f26693ddb36a68e42f49bc551d191e2f21c95264d0a5dd2038db5c19a407ce88e51f81814e27fcc8ce4129eb96e56a07bb9f7c7fec8ba083d3919f75f6
|
7
|
+
data.tar.gz: 0bbdb879ed861b5ca6f8be53c7448b2b464afc389c6ed4e7a708cd893af9763d87ae8afbc13aaf052ebc80387d1447ffe6c78bf9250406bbaeb89fe222ae6ad1
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
waithook (0.4.
|
4
|
+
waithook (0.4.4)
|
5
5
|
websocket (~> 1.2)
|
6
6
|
|
7
7
|
GEM
|
@@ -11,8 +11,11 @@ GEM
|
|
11
11
|
public_suffix (>= 2.0.2, < 7.0)
|
12
12
|
ansi (1.5.0)
|
13
13
|
builder (3.3.0)
|
14
|
-
|
15
|
-
|
14
|
+
coderay (1.1.3)
|
15
|
+
excon (1.2.5)
|
16
|
+
logger
|
17
|
+
logger (1.7.0)
|
18
|
+
minitest (5.25.5)
|
16
19
|
minitest-reporters (1.7.1)
|
17
20
|
ansi
|
18
21
|
builder
|
@@ -28,6 +31,7 @@ PLATFORMS
|
|
28
31
|
|
29
32
|
DEPENDENCIES
|
30
33
|
addressable
|
34
|
+
coderay
|
31
35
|
excon
|
32
36
|
minitest-reporters
|
33
37
|
rake
|
data/lib/waithook/version.rb
CHANGED
data/lib/waithook.rb
CHANGED
@@ -150,7 +150,12 @@ class Waithook
|
|
150
150
|
Timeout.timeout(timeout) do
|
151
151
|
while true
|
152
152
|
_, data = @client.wait_message
|
153
|
-
webhook = Webhook.new(
|
153
|
+
webhook = Webhook.new(
|
154
|
+
data,
|
155
|
+
logger: logger,
|
156
|
+
forward_options: (options[:forward_options] || {}).merge(@options[:forward_options] || {}),
|
157
|
+
enable_colors: options.key?(:enable_colors) ? options.key?(:enable_colors) : true
|
158
|
+
)
|
154
159
|
if @filter && @filter.call(webhook) || !@filter
|
155
160
|
@messages << webhook
|
156
161
|
return webhook
|
@@ -184,7 +189,7 @@ class Waithook
|
|
184
189
|
# Raw message from waithook server
|
185
190
|
attr_reader :message
|
186
191
|
|
187
|
-
def initialize(payload, logger
|
192
|
+
def initialize(payload, logger: nil, forward_options: {}, enable_colors: true)
|
188
193
|
@message = payload
|
189
194
|
data = JSON.parse(@message)
|
190
195
|
@url = data['url']
|
@@ -192,9 +197,18 @@ class Waithook
|
|
192
197
|
@body = data['body']
|
193
198
|
@method = data['method']
|
194
199
|
@logger = logger
|
200
|
+
@forward_options = forward_options
|
201
|
+
@enable_colors = enable_colors
|
195
202
|
end
|
196
203
|
|
197
|
-
def pretty_print
|
204
|
+
def pretty_print(pp_arg = nil, *args)
|
205
|
+
return super if pp_arg && defined?(super) # method from 'pp' library has same name
|
206
|
+
|
207
|
+
if !@body
|
208
|
+
@logger&.debug("Error: Waithook::Webhook has no @body")
|
209
|
+
return @message
|
210
|
+
end
|
211
|
+
|
198
212
|
if @body.start_with?('{') && @body.end_with?('}') || @body.start_with?('[') && @body.end_with?(']')
|
199
213
|
begin
|
200
214
|
body_data = JSON.parse(body)
|
@@ -202,19 +216,21 @@ class Waithook
|
|
202
216
|
data_without_body = JSON.parse(@message)
|
203
217
|
data_without_body.delete('body')
|
204
218
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
219
|
+
if @enable_colors
|
220
|
+
begin
|
221
|
+
require 'coderay'
|
222
|
+
pretty_body = CodeRay.scan(pretty_body, :json).term
|
223
|
+
rescue => error
|
224
|
+
@logger&.debug("Error while trying to use CodeRay: #{error.message}")
|
225
|
+
end
|
210
226
|
end
|
211
227
|
return "#{JSON.pretty_generate(data_without_body)}\nBody:\n#{pretty_body}"
|
212
228
|
rescue JSON::ParserError => error
|
213
|
-
logger&.debug("Error while parsing json body: #{error.message}")
|
229
|
+
@logger&.debug("Error while parsing json body: #{error.message}")
|
214
230
|
end
|
215
231
|
end
|
216
232
|
|
217
|
-
return message
|
233
|
+
return @message
|
218
234
|
end
|
219
235
|
|
220
236
|
# Returns Hash.
|
@@ -236,7 +252,8 @@ class Waithook
|
|
236
252
|
uri = URI.parse(url)
|
237
253
|
response = nil
|
238
254
|
|
239
|
-
|
255
|
+
http_options = {use_ssl: uri.scheme == 'https'}.merge(@forward_options || {})
|
256
|
+
Net::HTTP.start(uri.host, uri.port, http_options) do |http|
|
240
257
|
http_klass = case method
|
241
258
|
when "GET" then Net::HTTP::Get
|
242
259
|
when "POST" then Net::HTTP::Post
|
@@ -267,3 +284,4 @@ class Waithook
|
|
267
284
|
end
|
268
285
|
end
|
269
286
|
end
|
287
|
+
|
data/tests/server_test.rb
CHANGED
@@ -71,9 +71,10 @@ describe "Server" do
|
|
71
71
|
|
72
72
|
assert_includes(response.body, "<html lang='en'>")
|
73
73
|
assert_equal({
|
74
|
-
"
|
75
|
-
"
|
76
|
-
"Content-
|
74
|
+
"Content-Encoding" => "",
|
75
|
+
"Connection" => "close",
|
76
|
+
"Content-Length" => response.headers["Content-Length"],
|
77
|
+
"Content-Type" => "text/html"
|
77
78
|
}, response.headers)
|
78
79
|
end
|
79
80
|
|
@@ -82,9 +83,10 @@ describe "Server" do
|
|
82
83
|
|
83
84
|
assert_includes(response.body, "function")
|
84
85
|
assert_equal({
|
85
|
-
"
|
86
|
-
"
|
87
|
-
"Content-
|
86
|
+
"Content-Encoding" => "",
|
87
|
+
"Connection" => "close",
|
88
|
+
"Content-Length" => response.headers["Content-Length"],
|
89
|
+
"Content-Type" => "application/javascript; charset=utf-8"
|
88
90
|
}, response.headers)
|
89
91
|
end
|
90
92
|
|
data/tests/waithook_test.rb
CHANGED
@@ -55,6 +55,20 @@ describe "Waithook" do
|
|
55
55
|
assert_equal("POST", webhook.method)
|
56
56
|
end
|
57
57
|
|
58
|
+
it "should use forward_options in request" do
|
59
|
+
waithook = default_client(forward_options: {write_timeout: :aaa, local_host: "--11"})
|
60
|
+
|
61
|
+
message = {'my_data' => true}
|
62
|
+
|
63
|
+
Excon.post("http://#{HOST}:#{PORT}/my-super-test", body: JSON.generate(message))
|
64
|
+
|
65
|
+
forward_error = begin
|
66
|
+
waithook.forward_to("http://#{HOST}:#{PORT}/my-super-test2")
|
67
|
+
rescue => e; e end
|
68
|
+
assert_equal(forward_error.class, Socket::ResolutionError)
|
69
|
+
assert_includes(forward_error.message, "getaddrinfo: nodename nor servname provided, or not known")
|
70
|
+
end
|
71
|
+
|
58
72
|
it "should have trace log level" do
|
59
73
|
out, err = capture_io do
|
60
74
|
default_client(logger_level: :trace, logger: true)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waithook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Evstigneev
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-04-05 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: websocket
|
@@ -55,7 +54,6 @@ homepage: https://github.com/paxa/waithook-ruby
|
|
55
54
|
licenses:
|
56
55
|
- MIT
|
57
56
|
metadata: {}
|
58
|
-
post_install_message:
|
59
57
|
rdoc_options: []
|
60
58
|
require_paths:
|
61
59
|
- lib
|
@@ -70,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
68
|
- !ruby/object:Gem::Version
|
71
69
|
version: '0'
|
72
70
|
requirements: []
|
73
|
-
rubygems_version: 3.5
|
74
|
-
signing_key:
|
71
|
+
rubygems_version: 3.6.5
|
75
72
|
specification_version: 4
|
76
73
|
summary: HTTP to WebSocket transmitting client
|
77
74
|
test_files: []
|