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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3df6454a557d19f38729b89f1874b43111ab2d367c9f6f018064ad012d3ff2a
4
- data.tar.gz: f933b2e75524e3301afbe50c8e56bbb525cea7a5503a15071cfad2ab4bd7ff59
3
+ metadata.gz: 4b1713a71f7f6f0af1e0c8a9201553bbc64100d0031b504ed124e314ca36b4d5
4
+ data.tar.gz: 8864b3ecd7c86acb2f85cd969df9571cfd22160588e41a888db22baeae720931
5
5
  SHA512:
6
- metadata.gz: 8f6403f65b5bf735376deea1d9eb4157b66d87428e1c13717c71b80045bfa898487863e15d9a206c59575652cfaa6003dc14885746f1dcd22a2f6ebec03eac1a
7
- data.tar.gz: b7f95a852f39039a4832f5a0f5889163e92fb855ade1b7e33a9c5b3ad5dbd0d587f393f8925156d5e8102f055eef0f7843e93be2f5122c1d9934bdbfca0ba70d
6
+ metadata.gz: 1a2936f26693ddb36a68e42f49bc551d191e2f21c95264d0a5dd2038db5c19a407ce88e51f81814e27fcc8ce4129eb96e56a07bb9f7c7fec8ba083d3919f75f6
7
+ data.tar.gz: 0bbdb879ed861b5ca6f8be53c7448b2b464afc389c6ed4e7a708cd893af9763d87ae8afbc13aaf052ebc80387d1447ffe6c78bf9250406bbaeb89fe222ae6ad1
data/Gemfile CHANGED
@@ -4,5 +4,6 @@ gem 'rake'
4
4
  gem 'minitest-reporters'
5
5
  gem 'excon'
6
6
  gem 'addressable'
7
+ gem 'coderay'
7
8
 
8
9
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waithook (0.4.2)
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
- excon (0.112.0)
15
- minitest (5.25.1)
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
@@ -1,3 +1,3 @@
1
1
  class Waithook
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.4"
3
3
  end
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(data, logger)
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 = nil)
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
- begin
206
- require 'coderay'
207
- pretty_body = CodeRay.scan(pretty_body, :json).term
208
- rescue => error
209
- logger&.debug("Error while trying to use CodeRay: #{error.message}")
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
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
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
- "Connection" => "close",
75
- "Content-Length" => response.headers["Content-Length"],
76
- "Content-Type" => "text/html"
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
- "Connection" => "close",
86
- "Content-Length" => response.headers["Content-Length"],
87
- "Content-Type" => "application/javascript; charset=utf-8"
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
 
@@ -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.2
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: 2024-10-29 00:00:00.000000000 Z
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.11
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: []