rails_api_guard 0.2.1 → 0.2.2
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/README.md +14 -0
- data/lib/rails_api_guard/services/slack_notifier.rb +16 -5
- data/lib/rails_api_guard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 113eca3b940fb42eb59e46207a1389447a14b1c8e664397bcf2e48060bc87c49
|
4
|
+
data.tar.gz: 7ed64fb43fcf0f8225dc0e0a237c35f6b5720e1b0686126d27381766ada440f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5736712e78258a58be184b20bf67628c943c3005649f0a0bc3917c8f416e29b4c4b57cddf5266895bd5073aff91375d2fbbfad25159b58b5fe8cce3f854c97d
|
7
|
+
data.tar.gz: 40e092d2d0ca2471179055399df4fea4e38fddb751ffccb6bd51c0063e77e19b2f065deec319e2e2d45c54f5695465726a6d56de09e4952df0d37c489c100224
|
data/README.md
CHANGED
@@ -34,6 +34,20 @@ config.middleware.use RailsApiGuard::Middleware::RateLimiter
|
|
34
34
|
## Configuration
|
35
35
|
Edit `config/initializers/rails_api_guard.rb` to set request limits, expiry time, Slack alerts, and excluded endpoint patterns.
|
36
36
|
|
37
|
+
## Slack Notifications
|
38
|
+
|
39
|
+
RailsApiGuard can optionally send Slack alerts whenever a request exceeds the defined rate limit threshold.
|
40
|
+
|
41
|
+
### Configuration
|
42
|
+
|
43
|
+
To enable Slack alerts, set your Slack webhook URL in the initializer:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# config/initializers/rails_api_guard.rb
|
47
|
+
RailsApiGuard.configure do |config|
|
48
|
+
config.slack_webhook_url = ENV["SLACK_WEBHOOK_URL"]
|
49
|
+
end
|
50
|
+
|
37
51
|
## Contributing
|
38
52
|
Contribution directions are yet to add.
|
39
53
|
|
@@ -5,11 +5,22 @@ module RailsApiGuard
|
|
5
5
|
class SlackNotifier
|
6
6
|
def self.notify(message)
|
7
7
|
webhook_url = RailsApiGuard.config.slack_webhook_url
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
|
9
|
+
if webhook_url.nil?
|
10
|
+
Rails.logger.warn 'no Slack webhook URl configured'
|
11
|
+
Rails.logger.warn "Message : #{message}"
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
response = HTTParty.post(
|
16
|
+
webhook_url,
|
17
|
+
body: { text: message }.to_json,
|
18
|
+
headers: { 'Content-Type' => 'application/json' }
|
19
|
+
)
|
20
|
+
|
21
|
+
unless rails.success?
|
22
|
+
Rails.logger.error "Failed to send Slack alert: #{response.code} - #{response.body}"
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_api_guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sugat dhole
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|