waithook 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/Gemfile.lock +12 -12
- data/bin/waithook +4 -0
- data/lib/waithook/cli.rb +1 -1
- data/lib/waithook/version.rb +1 -1
- data/lib/waithook/websocket_client.rb +11 -0
- data/lib/waithook.rb +44 -6
- data/tests/waithook_test.rb +1 -1
- data/waithook.gemspec +1 -1
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 587f43be470d0045276f76af9a9518cde2c4c0fda3a48894a09bc8a4c053b78d
|
4
|
+
data.tar.gz: bb935b3ba35498e9250f4df4f7f750939defd5c08eb6bbf6501bbfdec97dca74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e43d129c6ba5043ce3b5aa1f279f3c16e104392f4d54ae6f3cb3a21b788037705933bbd037315477c7f29e919d0233b83d7c7fc2ced9de1dcbf670c20e06f2
|
7
|
+
data.tar.gz: 62a00aa0dd68c73d4e1ed57cc941e1797f8c6e43df03ccb8d5d84001728925ff043100dbb72c98790cf1a61dcbe20e32b62c0141755a0113e1f84668070a7cca
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
waithook (0.
|
4
|
+
waithook (0.4.0)
|
5
5
|
websocket (~> 1.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
public_suffix (>= 2.0.2, <
|
10
|
+
addressable (2.8.7)
|
11
|
+
public_suffix (>= 2.0.2, < 7.0)
|
12
12
|
ansi (1.5.0)
|
13
|
-
builder (3.
|
14
|
-
excon (0.
|
15
|
-
minitest (5.
|
16
|
-
minitest-reporters (1.1
|
13
|
+
builder (3.3.0)
|
14
|
+
excon (0.112.0)
|
15
|
+
minitest (5.25.1)
|
16
|
+
minitest-reporters (1.7.1)
|
17
17
|
ansi
|
18
18
|
builder
|
19
19
|
minitest (>= 5.0)
|
20
20
|
ruby-progressbar
|
21
|
-
public_suffix (
|
22
|
-
rake (
|
23
|
-
ruby-progressbar (1.
|
24
|
-
websocket (1.2.
|
21
|
+
public_suffix (6.0.1)
|
22
|
+
rake (13.2.1)
|
23
|
+
ruby-progressbar (1.13.0)
|
24
|
+
websocket (1.2.11)
|
25
25
|
|
26
26
|
PLATFORMS
|
27
27
|
ruby
|
@@ -34,4 +34,4 @@ DEPENDENCIES
|
|
34
34
|
waithook!
|
35
35
|
|
36
36
|
BUNDLED WITH
|
37
|
-
|
37
|
+
2.5.11
|
data/bin/waithook
CHANGED
@@ -23,6 +23,10 @@ begin
|
|
23
23
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
24
24
|
options[:verbose] = v
|
25
25
|
end
|
26
|
+
opts.on("--[no-]debug", "Run verbosely") do |v|
|
27
|
+
options[:verbose] = v
|
28
|
+
end
|
29
|
+
|
26
30
|
opts.on("-f URL", "--forward URL", "Forward to HTTP server") do |value|
|
27
31
|
options[:forward] = value
|
28
32
|
end
|
data/lib/waithook/cli.rb
CHANGED
data/lib/waithook/version.rb
CHANGED
@@ -199,6 +199,10 @@ class Waithook
|
|
199
199
|
def _process_frame(message)
|
200
200
|
logger.trace "Received :#{message.type} #{message.data ? "DATA: #{message.data}" : "(no data)"}"
|
201
201
|
|
202
|
+
if message.type == :pong
|
203
|
+
logger.debug "Got pong"
|
204
|
+
end
|
205
|
+
|
202
206
|
if message.type == :ping
|
203
207
|
send_pong!
|
204
208
|
end
|
@@ -208,6 +212,13 @@ class Waithook
|
|
208
212
|
end
|
209
213
|
end
|
210
214
|
|
215
|
+
def ping_sender(interval = 60)
|
216
|
+
while @is_open
|
217
|
+
send_ping!
|
218
|
+
sleep interval
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
211
222
|
def _wait_frames!
|
212
223
|
while char = @socket.getc
|
213
224
|
@frame_parser << char
|
data/lib/waithook.rb
CHANGED
@@ -47,7 +47,7 @@ class Waithook
|
|
47
47
|
|
48
48
|
# Filter (Proc), can be used to to filter incoming messages
|
49
49
|
attr_accessor :filter
|
50
|
-
# Array of all
|
50
|
+
# Array of all received messages
|
51
51
|
attr_accessor :messages
|
52
52
|
# Websocket client, instance of Waithook::WebsocketClient
|
53
53
|
attr_reader :client
|
@@ -106,9 +106,23 @@ class Waithook
|
|
106
106
|
raise "Waithook connection already started" if @started
|
107
107
|
@started = true
|
108
108
|
@client.connect!.wait_handshake!
|
109
|
+
start_pinger_thread!
|
110
|
+
|
109
111
|
self
|
110
112
|
end
|
111
113
|
|
114
|
+
def start_pinger_thread!
|
115
|
+
Thread.new do
|
116
|
+
begin
|
117
|
+
logger.debug("Sending ping every 60 seconds")
|
118
|
+
client.ping_sender
|
119
|
+
logger.debug("Exit ping sender thread")
|
120
|
+
rescue => error
|
121
|
+
logger.warn("Error in ping sender thread: #{error.message} (#{error.class})\n#{error.backtrace.join("\n")}")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
112
126
|
# Whenever connected to server or not
|
113
127
|
def started?
|
114
128
|
!!@started
|
@@ -116,7 +130,7 @@ class Waithook
|
|
116
130
|
|
117
131
|
# Send all incoming webhook requests to running HTTP server
|
118
132
|
#
|
119
|
-
# webhook = Waithook.subscribe(path: 'my-
|
133
|
+
# webhook = Waithook.subscribe(path: 'my-webhooks').forward_to('http://localhost:3000/notification')
|
120
134
|
#
|
121
135
|
def forward_to(url, options = {})
|
122
136
|
webhook = wait_message(options)
|
@@ -132,7 +146,7 @@ class Waithook
|
|
132
146
|
Timeout.timeout(timeout) do
|
133
147
|
while true
|
134
148
|
_, data = @client.wait_message
|
135
|
-
webhook = Webhook.new(data)
|
149
|
+
webhook = Webhook.new(data, logger)
|
136
150
|
if @filter && @filter.call(webhook) || !@filter
|
137
151
|
@messages << webhook
|
138
152
|
return webhook
|
@@ -140,7 +154,7 @@ class Waithook
|
|
140
154
|
end
|
141
155
|
end
|
142
156
|
rescue Timeout::Error => error
|
143
|
-
time_diff = (Time.now.to_f - start_time).round(3)
|
157
|
+
time_diff = (Time.now.to_f - start_time.to_i).round(3)
|
144
158
|
logger.error "#{error.class}: #{error.message} (after #{time_diff} seconds)"
|
145
159
|
raise error if raise_timeout_error
|
146
160
|
return nil
|
@@ -166,13 +180,37 @@ class Waithook
|
|
166
180
|
# Raw message from waithook server
|
167
181
|
attr_reader :message
|
168
182
|
|
169
|
-
def initialize(payload)
|
183
|
+
def initialize(payload, logger = nil)
|
170
184
|
@message = payload
|
171
185
|
data = JSON.parse(@message)
|
172
186
|
@url = data['url']
|
173
187
|
@headers = data['headers']
|
174
188
|
@body = data['body']
|
175
189
|
@method = data['method']
|
190
|
+
@logger = logger
|
191
|
+
end
|
192
|
+
|
193
|
+
def pretty_print
|
194
|
+
if @body.start_with?('{') && @body.end_with?('}') || @body.start_with?('[') && @body.end_with?(']')
|
195
|
+
begin
|
196
|
+
body_data = JSON.parse(body)
|
197
|
+
pretty_body = JSON.pretty_generate(body_data)
|
198
|
+
data_without_body = JSON.parse(@message)
|
199
|
+
data_without_body.delete('body')
|
200
|
+
|
201
|
+
begin
|
202
|
+
require 'coderay'
|
203
|
+
pretty_body = CodeRay.scan(pretty_body, :json).term
|
204
|
+
rescue => error
|
205
|
+
logger&.debug("Error while trying to use CodeRay: #{error.message}")
|
206
|
+
end
|
207
|
+
return "#{JSON.pretty_generate(data_without_body)}\nBody:\n#{pretty_body}"
|
208
|
+
rescue JSON::ParserError => error
|
209
|
+
logger&.debug("Error while parsing json body: #{error.message}")
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
return message
|
176
214
|
end
|
177
215
|
|
178
216
|
# Returns Hash.
|
@@ -185,7 +223,7 @@ class Waithook
|
|
185
223
|
|
186
224
|
# Send webhook information to other HTTP server
|
187
225
|
#
|
188
|
-
# webhook = Waithook.subscribe(path: 'my-
|
226
|
+
# webhook = Waithook.subscribe(path: 'my-webhooks').wait_message
|
189
227
|
# webhook.send_to('http://localhost:3000/notification')
|
190
228
|
#
|
191
229
|
def send_to(url)
|
data/tests/waithook_test.rb
CHANGED
@@ -79,7 +79,7 @@ describe "Waithook" do
|
|
79
79
|
|
80
80
|
it "wait_message should return nil after timeout" do
|
81
81
|
waithook = default_client
|
82
|
-
|
82
|
+
assert_nil(waithook.wait_message(timeout: 0.1, raise_on_timeout: false))
|
83
83
|
end
|
84
84
|
|
85
85
|
it "forward_to should raise exception after timeout" do
|
data/waithook.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = %q{HTTP to WebSocket transmitting client}
|
10
10
|
s.description = "Waithook gem is client lib for waithook service http://waithook.com"
|
11
11
|
s.license = 'MIT'
|
12
|
-
s.required_ruby_version = '~> 2.0'
|
12
|
+
# s.required_ruby_version = '~> 2.0'
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waithook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Evstigneev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|
@@ -55,24 +55,23 @@ homepage: https://github.com/paxa/waithook-ruby
|
|
55
55
|
licenses:
|
56
56
|
- MIT
|
57
57
|
metadata: {}
|
58
|
-
post_install_message:
|
58
|
+
post_install_message:
|
59
59
|
rdoc_options: []
|
60
60
|
require_paths:
|
61
61
|
- lib
|
62
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- - "
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '0'
|
67
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
|
74
|
-
|
75
|
-
signing_key:
|
73
|
+
rubygems_version: 3.5.11
|
74
|
+
signing_key:
|
76
75
|
specification_version: 4
|
77
76
|
summary: HTTP to WebSocket transmitting client
|
78
77
|
test_files: []
|