webhookdump 0.0.2 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f49b8299be7c721086315b6b1599bccbdf4f45d713626e2108995d1eecdfdb47
4
- data.tar.gz: a4d3442adeb9b99d5f8ad79061bff5eb97d2d6be607492e7614e2ad275940c58
3
+ metadata.gz: 976fd8974e7388af85639b08f57d932998bf1127ebcc65858f34e67353e9647c
4
+ data.tar.gz: 146b4246ccfc22144b89f817677dcfa96334da61ec038fd5429bbe510f036bc0
5
5
  SHA512:
6
- metadata.gz: 25b7318994daa111f9d33d500e3c636f597873a39ff722f3e36770546d60e7dcea1629a1e537c8c58dee545f5970a0475c6c4120ff396e4f4367760744c4d9a5
7
- data.tar.gz: 3a41012a76154f87b40e326b9d25cde3978f9da522b7ab1a091aa43dfc9509543a8c1a854b20768fb186f8fab09b39d64336ffd9c62f74866dd091a2a6e03190
6
+ metadata.gz: 5fd044b73a0e0653c2a110b2b4d8244bc40796b79eab92819b922da5533d7a5b86222f03da7affc9d9a68b12ffcf828c34df9cb3c6cfb301d1b9fa9f97bc7476
7
+ data.tar.gz: 30c3dec40840ace2ca8a74ae5ddb6cda6a2163e8907c87b7d1c7dfc5688028ddd6793b49cdb414b17a81bd5a3fe4c28ca51d8be7e79f3f3705a783b19f97c29e
data/bin/webhookdump CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require './lib/webhook_dump'
3
+ require 'webhook_dump'
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module WebhookDump
2
+ VERSION = '0.0.5'
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.2
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
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - bin/webhookdump
77
+ - lib/version.rb
77
78
  - lib/webhook_dump.rb
78
79
  homepage: https://rubygems.org/gems/webhook_dump_cli
79
80
  licenses: