webhookdump 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/version.rb +1 -1
  3. data/lib/webhook_dump.rb +20 -5
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8059f6d3d71855659bc058943a450ac3b78a9d730f3f308b93c73d6caaf530cb
4
- data.tar.gz: 511b3a0ad1a0ed04711fd33195caf6b764ff29bd57878d65f70168c5e353c497
3
+ metadata.gz: 976fd8974e7388af85639b08f57d932998bf1127ebcc65858f34e67353e9647c
4
+ data.tar.gz: 146b4246ccfc22144b89f817677dcfa96334da61ec038fd5429bbe510f036bc0
5
5
  SHA512:
6
- metadata.gz: 2698835ace895a826fd7ec0a8ff97de918eff38f1fda0a582da350b1a9c12e231b3fd3b4d87fafe2a639ff2ac80843799c05052d93efe5bb1e0f5c25492931cc
7
- data.tar.gz: 9d43df9add8d623c99357f8569b08f3bebc3412e5fc6d2951d8ece22a718628c6376f7617befde4396ed32ff71ccf4a2876d8f5d01fc16528a5b19364afb2dd4
6
+ metadata.gz: 5fd044b73a0e0653c2a110b2b4d8244bc40796b79eab92819b922da5533d7a5b86222f03da7affc9d9a68b12ffcf828c34df9cb3c6cfb301d1b9fa9f97bc7476
7
+ data.tar.gz: 30c3dec40840ace2ca8a74ae5ddb6cda6a2163e8907c87b7d1c7dfc5688028ddd6793b49cdb414b17a81bd5a3fe4c28ca51d8be7e79f3f3705a783b19f97c29e
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module WebhookDump
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/webhook_dump.rb CHANGED
@@ -6,14 +6,16 @@ require 'faraday'
6
6
 
7
7
  module WebhookDump
8
8
  class CLI < Thor
9
- WEBSOCKET_URL = 'wss://webhookdump.link/cable'
10
- WEBSOCKET_URL_DEV = 'ws://localhost:3000/cable'
9
+ WEBSOCKET_HOST = 'webhookdump.link'
10
+ WEBSOCKET_HOST_DEV = 'localhost:3000'
11
11
 
12
12
  option :dev, type: :boolean, default: false, desc: 'Use development environment'
13
13
 
14
14
  desc "forward WEBHOOKDUMP_ID FORWARD_URL", "Forward events from WebhookDump to a target URL"
15
15
 
16
16
  def forward(webhookdump_id, forward_url)
17
+ validate_settings(webhookdump_id, forward_url)
18
+
17
19
  EM.run do
18
20
  puts "Start forwarding events from WebhookDump #{webhookdump_id} to #{forward_url}"
19
21
 
@@ -61,7 +63,7 @@ module WebhookDump
61
63
 
62
64
  def close_websocket_connection(ws)
63
65
  ws.on :close do |event|
64
- reason = event.reason != ' ' ? 'Probably invalid WebhookDump ID' : event.reason
66
+ reason = event.reason != ' ' ? 'Invalid WebhookDump ID' : event.reason
65
67
  puts "Connection closed, #{event.code}, #{reason}"
66
68
 
67
69
  EM.stop
@@ -69,11 +71,18 @@ module WebhookDump
69
71
  end
70
72
 
71
73
  def init_faye_websocket_connection(webhookdump_id)
72
- Faye::WebSocket::Client.new("#{WEBSOCKET_URL_DEV}?id=#{webhookdump_id}")
74
+ Faye::WebSocket::Client.new("#{websocket_url}?id=#{webhookdump_id}")
75
+ end
76
+
77
+ def websocket_host
78
+ options[:dev] ? WEBSOCKET_HOST_DEV : WEBSOCKET_HOST
73
79
  end
74
80
 
75
81
  def websocket_url
76
- options[:dev] ? WEBSOCKET_URL_DEV : WEBSOCKET_URL
82
+ protocol = 'wss'
83
+ protocol = 'ws' if options[:dev]
84
+
85
+ "#{protocol}://#{websocket_host}/cable"
77
86
  end
78
87
 
79
88
  def forward_message(forward_url, message)
@@ -114,6 +123,12 @@ module WebhookDump
114
123
 
115
124
  {}
116
125
  end
126
+
127
+ def validate_settings(webhookdump_id, forward_url)
128
+ if forward_url.include? "#{websocket_host}/#{webhookdump_id}"
129
+ puts "Error: Forward URL is the same as the incoming request URL. This would cause an infinite loop."
130
+ exit 1
131
+ end
117
132
  end
118
133
  end
119
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhookdump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Risal Hidayat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-05 00:00:00.000000000 Z
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor